Skip to content

Commit

Permalink
refactoring: min php version is 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Gemorroj committed Jul 1, 2023
1 parent 6af48ad commit 7418e55
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 40 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ jobs:
fail-fast: false
matrix:
include:
- operating-system: 'ubuntu-latest'
php-version: '7.4'
job-description: 'Ubuntu; PHP 7.4; latest-deps'

- operating-system: 'ubuntu-latest'
php-version: '7.4'
composer-flags: '--prefer-lowest'
job-description: 'Ubuntu; PHP 7.4; lowest-deps'

- operating-system: 'ubuntu-latest'
php-version: '8.0'
job-description: 'Ubuntu; PHP 8.0; latest-deps'
Expand Down
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP74Migration' => true,
'@PHP80Migration' => true,

'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ $info = $ginfo->getInfo();


### System requirements:
- PHP >= 7.4
- PHP >= 8.0
- pcre extension
- proc_open

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
}
],
"require": {
"php": ">=7.4",
"php": ">=8.0",
"ext-pcre": "*",
"ext-mbstring": "*",
"ext-json": "*",
"symfony/process": "^4.4||^5.0||^6.0"
"symfony/process": "^5.4||^6.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5.16",
"phpstan/phpstan": "^1.0",
"friendsofphp/php-cs-fixer": "^3.0"
"phpunit/phpunit": "^9.6",
"phpstan/phpstan": "^1.10",
"friendsofphp/php-cs-fixer": "^3.20"
},
"suggest": {
"ext-apcu": "APCU info"
Expand Down
4 changes: 0 additions & 4 deletions src/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public static function locateActualPath(array $paths): ?string
/**
* Get a file's contents, or default to second param.
*
* @param mixed $default
*
* @return string|mixed|null
*/
public static function getContents(string $file, $default = null)
Expand All @@ -49,8 +47,6 @@ public static function getContents(string $file, $default = null)
/**
* Like above, but in lines instead of a big string.
*
* @param mixed $default
*
* @return string[]|mixed|null
*/
public static function getLines(string $file, $default = null)
Expand Down
18 changes: 12 additions & 6 deletions src/OS/Linux.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,14 @@ public function getNetwork(): ?array
$typeContents = \mb_strtoupper(Common::getContents($path.'/device/modalias', ''));
[$typeMatch] = \explode(':', $typeContents, 2);

$ueventContents = @\parse_ini_file($path.'/uevent');
$deviceUeventContents = @\parse_ini_file($path.'/device/uevent');
$ueventContents = Common::getContents($path.'/uevent');
if ($ueventContents) {
$ueventContents = @\parse_ini_string($ueventContents);
}
$deviceUeventContents = Common::getContents($path.'/device/uevent');
if ($deviceUeventContents) {
$deviceUeventContents = @\parse_ini_string($deviceUeventContents);
}

if ($ueventContents && isset($ueventContents['DEVTYPE'])) {
$type = \ucfirst($ueventContents['DEVTYPE']);
Expand Down Expand Up @@ -661,15 +667,15 @@ public function getVirtualization(): ?string
if ('Veertu' === $biosVendor) {
return 'Veertu';
}
if (0 === \strpos($biosVendor, 'Parallels')) {
if (\str_starts_with($biosVendor, 'Parallels')) {
return 'Parallels';
}

if (false !== \strpos(Common::getContents('/proc/mounts', ''), 'lxcfs /proc/')) {
if (\str_contains(Common::getContents('/proc/mounts', ''), 'lxcfs /proc/')) {
return 'LXC';
}

if (\is_file('/.dockerenv') || \is_file('/.dockerinit') || false !== \strpos(Common::getContents('/proc/1/cgroup', ''), 'docker')) {
if (\is_file('/.dockerenv') || \is_file('/.dockerinit') || \str_contains(Common::getContents('/proc/1/cgroup', ''), 'docker')) {
return 'Docker';
}

Expand Down Expand Up @@ -741,7 +747,7 @@ public function getModel(): ?string

// product name is usually bullshit, but *occasionally* it's a useful name of the computer, such as
// dell latitude e6500 or hp z260
if ($product && false === \mb_strpos($name, $product) && false === \strpos($product, 'Filled')) {
if ($product && false === \mb_strpos($name, $product) && !\str_contains($product, 'Filled')) {
return $product.' ('.$infoStr.')';
}

Expand Down
6 changes: 3 additions & 3 deletions src/OS/Windows.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function getDrives(): ?array
})($driveInfo['Index']))
->setName($driveInfo['Caption'])
->setReads(null)
->setVendor(false !== \strpos($driveInfo['Caption'], ' ') ? \explode(' ', $driveInfo['Caption'], 2)[0] : null)
->setVendor(\str_contains($driveInfo['Caption'], ' ') ? \explode(' ', $driveInfo['Caption'], 2)[0] : null)
->setWrites(null);
}

Expand Down Expand Up @@ -285,7 +285,7 @@ public function getPci(): ?array
$devs = [];
foreach ($info as $pnpDev) {
$type = \explode('\\', $pnpDev['DeviceID'], 2)[0];
if (('PCI' !== $type) || (empty($pnpDev['Caption']) || 0 === \strpos($pnpDev['Manufacturer'], '('))) {
if (('PCI' !== $type) || (empty($pnpDev['Caption']) || \str_starts_with($pnpDev['Manufacturer'], '('))) {
continue;
}

Expand All @@ -307,7 +307,7 @@ public function getUsb(): ?array
$devs = [];
foreach ($info as $pnpDev) {
$type = \explode('\\', $pnpDev['DeviceID'], 2)[0];
if (('USB' !== $type) || (empty($pnpDev['Caption']) || 0 === \strpos($pnpDev['Manufacturer'], '('))) {
if (('USB' !== $type) || (empty($pnpDev['Caption']) || \str_starts_with($pnpDev['Manufacturer'], '('))) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Parsers/Apcaccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function work(): ?array
}

$result = \trim($process->getOutput());
if (0 === \strpos($result, 'Error')) {
if (\str_starts_with($result, 'Error')) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Parsers/Free.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function work(): ?array
$free = $process->getOutput();

$arr = \explode("\n", \trim($free));
$isWideOutput = false === \strpos($arr[0], 'buff/cache'); // alpine doesnt support wide output for example
$isWideOutput = !\str_contains($arr[0], 'buff/cache'); // alpine doesnt support wide output for example
\array_shift($arr); // remove header

$memStr = \trim(\explode(':', $arr[0], 2)[1]);
Expand Down
10 changes: 5 additions & 5 deletions src/Parsers/Hwpci.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ private function fetchUsbIdsLinux(): void

foreach ($paths as $path) {
// Avoid the same device artificially appearing more than once
if (false !== \strpos($path, ':')) {
if (\str_contains($path, ':')) {
continue;
}

// First try uevent
if (\is_readable($path.'/uevent') &&
\preg_match('/^product=([^\/]+)\/([^\/]+)\/[^$]+$/m', \mb_strtolower(Common::getContents($path.'/uevent')), $match)) {
if (\is_readable($path.'/uevent')
&& \preg_match('/^product=([^\/]+)\/([^\/]+)\/[^$]+$/m', \mb_strtolower(Common::getContents($path.'/uevent')), $match)) {
$vId = \str_pad($match[1], 4, '0', \STR_PAD_LEFT);
$dId = \str_pad($match[2], 4, '0', \STR_PAD_LEFT);
$this->entries[$vId][$dId] = 1;
} // And next modalias
elseif (\is_readable($path.'/modalias') &&
\preg_match('/^usb:v([0-9A-Z]{4})p([0-9A-Z]{4})/', Common::getContents($path.'/modalias'), $match)) {
elseif (\is_readable($path.'/modalias')
&& \preg_match('/^usb:v([0-9A-Z]{4})p([0-9A-Z]{4})/', Common::getContents($path.'/modalias'), $match)) {
$vId = \mb_strtolower($match[1]);
$dId = \mb_strtolower($match[2]);
$this->entries[$vId][$dId] = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/Parsers/Sensors/Hddtemp.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private function parseSockData(string $data): array
[$path, $name, $temp, $unit] = \explode('|', \trim($drive));

// Ignore garbled output from SSDs that hddtemp cant parse
if (false !== \strpos($temp, 'UNK')) {
if (\str_contains($temp, 'UNK')) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Parsers/Sensors/Hwmon.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function work(): ?array
$driverName = Common::getContents(\dirname($path).'/name');

// Temperatures
if (0 === \strpos($base, 'temp') && \is_file($labelPath)) {
if (\str_starts_with($base, 'temp') && \is_file($labelPath)) {
$label = Common::getContents($labelPath);
$value /= $value > 10000 ? 1000 : 1;
$unit = 'C'; // I don't think this is ever going to be in F
Expand Down
2 changes: 1 addition & 1 deletion src/Parsers/Sensors/Sensors.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function work(): ?array

private static function isSensorLine(string $line): bool
{
return false !== \strpos($line, ':') && 'Adapter:' !== \substr($line, 0, 8);
return \str_contains($line, ':') && 'Adapter:' !== \substr($line, 0, 8);
}

private static function parseSensor(string $sensor): array
Expand Down
2 changes: 1 addition & 1 deletion src/Parsers/Smbstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static function parseService(string $service): array
// tested date: Wed Dec 9 01:40:20 PM 2015 CET or Fri Mar 30 15:48:34 2018
if (isset($out['connectedAt']) && !($out['connectedAt'] instanceof \DateTime)) {
if ($connectedAtYear) { // perhaps timezone
if (false === \strpos($token, '-')) { // yes, timezone
if (!\str_contains($token, '-')) { // yes, timezone
$out['connectedAt'] .= ' '.$token;
$out['connectedAt'] = new \DateTime($out['connectedAt']);
continue;
Expand Down

0 comments on commit 7418e55

Please sign in to comment.