Skip to content

Commit

Permalink
Upgrade to PHP8.1 (#96)
Browse files Browse the repository at this point in the history
* Upgrade to 8.1

* Fix phpstan errors

* Migrate phpunit config to newer version

* Fix code style

* Up the code to higher standard

* Resolve rebase conflicts

* Update phpunit

* Resolve deprecations

* Pass optional identifier to factory registration

* Fix phpunit version

* Add readonly

* Remove unused docblocks

* Fix archive issue on windows
  • Loading branch information
dbrekelmans committed Feb 22, 2024
1 parent 36bacb9 commit 9cae643
Show file tree
Hide file tree
Showing 71 changed files with 598 additions and 1,087 deletions.
22 changes: 8 additions & 14 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,41 @@ jobs:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.1
extensions: zip
coverage: none
- uses: ramsey/composer-install@v1
- uses: ramsey/composer-install@v2
- run: vendor/bin/phpunit
phpstan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.1
extensions: zip
coverage: none
- uses: ramsey/composer-install@v1
- uses: ramsey/composer-install@v2
- run: vendor/bin/phpstan analyse --error-format=github
phpcs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.1
extensions: zip
coverage: none
- uses: ramsey/composer-install@v1
- uses: ramsey/composer-install@v2
- run: vendor/bin/phpcs --warning-severity=0
e2e:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
php: [7.4, 8.0, 8.1, 8.2, 8.3]
php: [8.1, 8.2, 8.3]
dependencies: [locked]
include:
- os: ubuntu-latest
php: 7.4
dependencies: lowest
- os: ubuntu-latest
php: 8.0
dependencies: lowest
- os: ubuntu-latest
php: 8.1
dependencies: lowest
Expand All @@ -67,7 +61,7 @@ jobs:
php-version: ${{ matrix.php }}
extensions: zip
coverage: none
- uses: ramsey/composer-install@v1
- uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.dependencies }}
composer-options: "--no-dev --optimize-autoloader --prefer-dist"
Expand Down
31 changes: 15 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,26 @@
"bdi"
],
"require": {
"php": "^7.4|^8.0",
"php": "^8.1",
"ext-json": "*",
"ext-zip": "*",
"ext-zlib": "*",
"myclabs/php-enum": "^1.7",
"symfony/console": "^5.1",
"symfony/filesystem": "^5.1",
"symfony/http-client": "^5.1",
"symfony/polyfill-php80": "^1.18",
"symfony/process": "^5.1",
"thecodingmachine/safe": "^1.1"
"symfony/console": "^6.0",
"symfony/filesystem": "^6.0",
"symfony/http-client": "^6.0",
"symfony/polyfill-php80": "^1.28",
"symfony/process": "^6.0",
"thecodingmachine/safe": "^2.0"
},
"require-dev": {
"doctrine/coding-standard": "^8.0",
"phpstan/phpstan": "^0.12.36",
"phpstan/phpstan-phpunit": "^0.12.16",
"phpstan/phpstan-strict-rules": "^0.12.5",
"phpunit/phpunit": "^8.5",
"roave/security-advisories": "dev-master",
"thecodingmachine/phpstan-safe-rule": "^1.0",
"thecodingmachine/phpstan-strict-rules": "^0.12.0"
"doctrine/coding-standard": "^12.0",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
"phpunit/phpunit": "^10.0",
"roave/security-advisories": "dev-latest",
"thecodingmachine/phpstan-safe-rule": "^1.2",
"thecodingmachine/phpstan-strict-rules": "^1.0"
},
"autoload": {
"psr-4": {
Expand Down
13 changes: 6 additions & 7 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
colors="true"
failOnRisky="true"
failOnWarning="true"
Expand All @@ -13,9 +12,9 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<source>
<include>
<directory>./src</directory>
</include>
</source>
</phpunit>
4 changes: 1 addition & 3 deletions src/Archive/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ interface Extractor
*/
public function extract(string $archive, string $destination): array;

/**
* @return string[]
*/
/** @return string[] */
public function getSupportedExtensions(): array;
}
10 changes: 3 additions & 7 deletions src/Archive/MultiExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use function array_unique;
use function in_array;
use function pathinfo;
use function Safe\sprintf;
use function sprintf;

final class MultiExtractor implements Extractor
{
Expand All @@ -20,9 +20,7 @@ final class MultiExtractor implements Extractor
/** @var string[] */
private array $supportedExtensions = [];

/**
* @inheritDoc
*/
/** @inheritDoc */
public function extract(string $archive, string $destination): array
{
$pathParts = pathinfo($archive);
Expand All @@ -40,9 +38,7 @@ public function extract(string $archive, string $destination): array
throw new Unsupported(sprintf('No archive extractor found supporting %s archive', $pathParts['extension']));
}

/**
* @inheritDoc
*/
/** @inheritDoc */
public function getSupportedExtensions(): array
{
return $this->supportedExtensions;
Expand Down
8 changes: 2 additions & 6 deletions src/Archive/TarGzExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

final class TarGzExtractor implements Extractor
{
/**
* @inheritDoc
*/
/** @inheritDoc */
public function extract(string $archive, string $destination): array
{
$tarGzData = new PharData($archive);
Expand All @@ -33,9 +31,7 @@ public function extract(string $archive, string $destination): array
return $extractedFilenames;
}

/**
* @inheritDoc
*/
/** @inheritDoc */
public function getSupportedExtensions(): array
{
return ['gz'];
Expand Down
15 changes: 4 additions & 11 deletions src/Archive/ZipExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@
use RuntimeException;
use ZipArchive;

use function Safe\sprintf;
use function sprintf;

use const DIRECTORY_SEPARATOR;

final class ZipExtractor implements Extractor
{
private ZipArchive $zipArchive;

public function __construct(ZipArchive $zipArchive)
public function __construct(private readonly ZipArchive $zipArchive)
{
$this->zipArchive = $zipArchive;
}

/**
* @inheritDoc
*/
/** @inheritDoc */
public function extract(string $archive, string $destination): array
{
$success = $this->zipArchive->open($archive);
Expand Down Expand Up @@ -51,9 +46,7 @@ public function extract(string $archive, string $destination): array
return $extractedFilenames;
}

/**
* @inheritDoc
*/
/** @inheritDoc */
public function getSupportedExtensions(): array
{
return ['zip'];
Expand Down
31 changes: 5 additions & 26 deletions src/Browser/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,10 @@

final class Browser
{
private BrowserName $name;

private Version $version;

private OperatingSystem $operatingSystem;

public function __construct(BrowserName $name, Version $version, OperatingSystem $operatingSystem)
{
$this->name = $name;
$this->version = $version;
$this->operatingSystem = $operatingSystem;
}

public function name(): BrowserName
{
return $this->name;
}

public function version(): Version
{
return $this->version;
}

public function operatingSystem(): OperatingSystem
{
return $this->operatingSystem;
public function __construct(
public readonly BrowserName $name,
public readonly Version $version,
public readonly OperatingSystem $operatingSystem,
) {
}
}
12 changes: 3 additions & 9 deletions src/Browser/BrowserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@

final class BrowserFactory
{
private PathResolverFactory $pathResolverFactory;

private VersionResolverFactory $versionResolverFactory;

public function __construct(
PathResolverFactory $pathResolverFactory,
VersionResolverFactory $versionResolverFactory
private readonly PathResolverFactory $pathResolverFactory,
private readonly VersionResolverFactory $versionResolverFactory,
) {
$this->pathResolverFactory = $pathResolverFactory;
$this->versionResolverFactory = $versionResolverFactory;
}

public function createFromNameAndOperatingSystem(BrowserName $name, OperatingSystem $operatingSystem): Browser
Expand All @@ -31,7 +25,7 @@ public function createFromNameAndOperatingSystem(BrowserName $name, OperatingSys
public function createFromNameOperatingSystemAndPath(
BrowserName $name,
OperatingSystem $operatingSystem,
string $path
string $path,
): Browser {
$versionResolver = $this->versionResolverFactory->createFromName($name);
$version = $versionResolver->from($operatingSystem, $path);
Expand Down
16 changes: 4 additions & 12 deletions src/Browser/BrowserName.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@

namespace DBrekelmans\BrowserDriverInstaller\Browser;

use MyCLabs\Enum\Enum;

/**
* @method static self GOOGLE_CHROME()
* @method static self CHROMIUM()
* @method static self FIREFOX()
* @extends Enum<string>
*/
final class BrowserName extends Enum
enum BrowserName: string
{
public const GOOGLE_CHROME = 'google-chrome';
public const CHROMIUM = 'chromium';
public const FIREFOX = 'firefox';
case GOOGLE_CHROME = 'google-chrome';
case CHROMIUM = 'chromium';
case FIREFOX = 'firefox';
}
2 changes: 1 addition & 1 deletion src/Browser/Chromium/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ final class Command extends BrowserCommand
{
protected static function browserName(): BrowserName
{
return BrowserName::CHROMIUM();
return BrowserName::CHROMIUM;
}
}
23 changes: 6 additions & 17 deletions src/Browser/Chromium/PathResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,21 @@

use DBrekelmans\BrowserDriverInstaller\Browser\BrowserName;
use DBrekelmans\BrowserDriverInstaller\Browser\PathResolver as PathResolverInterface;
use DBrekelmans\BrowserDriverInstaller\Exception\NotImplemented;
use DBrekelmans\BrowserDriverInstaller\OperatingSystem\OperatingSystem;

use function Safe\sprintf;

class PathResolver implements PathResolverInterface
{
public function from(OperatingSystem $operatingSystem): string
{
if ($operatingSystem->equals(OperatingSystem::LINUX())) {
return 'chromium';
}

if ($operatingSystem->equals(OperatingSystem::MACOS())) {
return '/Applications/Chromium.app';
}

if ($operatingSystem->equals(OperatingSystem::WINDOWS())) {
return 'C:\\Program Files (x86)\\Chromium\\Application\\chrome.exe';
}

throw NotImplemented::feature(sprintf('Resolving path on %s', $operatingSystem->getValue()));
return match ($operatingSystem) {
OperatingSystem::LINUX => 'chromium',
OperatingSystem::MACOS => '/Applications/Chromium.app',
OperatingSystem::WINDOWS => 'C:\\Program Files (x86)\\Chromium\\Application\\chrome.exe',
};
}

public function supports(BrowserName $browserName): bool
{
return $browserName->equals(BrowserName::CHROMIUM());
return $browserName === BrowserName::CHROMIUM;
}
}
Loading

0 comments on commit 9cae643

Please sign in to comment.