From d25738b3d4fc8a873fcc42c70aa6e61112db342b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 3 Nov 2024 12:17:59 +0700 Subject: [PATCH 1/2] Update to use PHP 8.1 syntax Signed-off-by: Abdul Malik Ikhsan --- src/App/src/Handler/HomePageHandler.php | 6 +++--- src/MezzioInstaller/OptionalPackages.php | 9 ++++++--- test/MezzioInstallerTest/OptionalPackagesTestCase.php | 8 ++++---- .../PromptForOptionalPackagesTest.php | 3 +-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/App/src/Handler/HomePageHandler.php b/src/App/src/Handler/HomePageHandler.php index dc629a7..0b35cfe 100644 --- a/src/App/src/Handler/HomePageHandler.php +++ b/src/App/src/Handler/HomePageHandler.php @@ -24,9 +24,9 @@ class HomePageHandler implements RequestHandlerInterface { public function __construct( - private string $containerName, - private RouterInterface $router, - private ?TemplateRendererInterface $template = null + private readonly string $containerName, + private readonly RouterInterface $router, + private readonly ?TemplateRendererInterface $template = null ) { } diff --git a/src/MezzioInstaller/OptionalPackages.php b/src/MezzioInstaller/OptionalPackages.php index a39588a..5270dca 100644 --- a/src/MezzioInstaller/OptionalPackages.php +++ b/src/MezzioInstaller/OptionalPackages.php @@ -175,7 +175,7 @@ class OptionalPackages ]; /** @var string Path to this file. */ - private string $installerSource; + private readonly string $installerSource; /** @var self::INSTALL_* Installation type selected. */ private string $installType = self::INSTALL_FLAT; @@ -214,8 +214,11 @@ public static function install(Event $event): void $installer->finalizePackage(); } - public function __construct(private IOInterface $io, private Composer $composer, ?string $projectRoot = null) - { + public function __construct( + private readonly IOInterface $io, + private readonly Composer $composer, + ?string $projectRoot = null + ) { // Get composer.json location $composerFile = Factory::getComposerFile(); diff --git a/test/MezzioInstallerTest/OptionalPackagesTestCase.php b/test/MezzioInstallerTest/OptionalPackagesTestCase.php index 2216347..fe93bda 100644 --- a/test/MezzioInstallerTest/OptionalPackagesTestCase.php +++ b/test/MezzioInstallerTest/OptionalPackagesTestCase.php @@ -54,7 +54,7 @@ public static function assertPackage( OptionalPackages $installer, ?string $message = null ): void { - $message = $message ?? sprintf('Failed asserting that package "%s" is present in the installer', $package); + $message ??= sprintf('Failed asserting that package "%s" is present in the installer', $package); $found = false; foreach (['composerRequires', 'composerDevRequires'] as $property) { @@ -78,7 +78,7 @@ public static function assertNotPackage( OptionalPackages $installer, ?string $message = null ): void { - $message = $message ?? sprintf('Failed asserting that package "%s" is absent from the installer', $package); + $message ??= sprintf('Failed asserting that package "%s" is absent from the installer', $package); $found = false; foreach (['composerRequires', 'composerDevRequires'] as $property) { @@ -134,7 +134,7 @@ public static function assertWhitelisted( OptionalPackages $installer, ?string $message = null ): void { - $message = $message ?? sprintf('Failed asserting that package "%s" is whitelisted in composer.json', $package); + $message ??= sprintf('Failed asserting that package "%s" is whitelisted in composer.json', $package); $found = false; $r = new ReflectionProperty($installer, 'composerDefinition'); @@ -167,7 +167,7 @@ protected function tearDown(): void */ protected function createOptionalPackages(?string $projectRoot = null): OptionalPackages { - $projectRoot = $projectRoot ?? $this->packageRoot; + $projectRoot ??= $this->packageRoot; $this->io = $this->createMock(IOInterface::class); return new OptionalPackages( $this->io, diff --git a/test/MezzioInstallerTest/PromptForOptionalPackagesTest.php b/test/MezzioInstallerTest/PromptForOptionalPackagesTest.php index 5785e90..875cf09 100644 --- a/test/MezzioInstallerTest/PromptForOptionalPackagesTest.php +++ b/test/MezzioInstallerTest/PromptForOptionalPackagesTest.php @@ -110,8 +110,7 @@ public function testPromptForOptionalPackage( continue; } - if ( - str_contains($message, 'Adding package') + if (str_contains($message, 'Adding package') || str_contains($message, '- Copying ') ) { $written[] = $package; From 3a628054a1437afb29643fe3b91d135c5af7b7b3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 3 Nov 2024 12:25:08 +0700 Subject: [PATCH 2/2] Fix cs Signed-off-by: Abdul Malik Ikhsan --- test/MezzioInstallerTest/OptionalPackagesTestCase.php | 8 ++++---- .../MezzioInstallerTest/PromptForOptionalPackagesTest.php | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/MezzioInstallerTest/OptionalPackagesTestCase.php b/test/MezzioInstallerTest/OptionalPackagesTestCase.php index fe93bda..306bc95 100644 --- a/test/MezzioInstallerTest/OptionalPackagesTestCase.php +++ b/test/MezzioInstallerTest/OptionalPackagesTestCase.php @@ -55,7 +55,7 @@ public static function assertPackage( ?string $message = null ): void { $message ??= sprintf('Failed asserting that package "%s" is present in the installer', $package); - $found = false; + $found = false; foreach (['composerRequires', 'composerDevRequires'] as $property) { $r = new ReflectionProperty($installer, $property); @@ -79,7 +79,7 @@ public static function assertNotPackage( ?string $message = null ): void { $message ??= sprintf('Failed asserting that package "%s" is absent from the installer', $package); - $found = false; + $found = false; foreach (['composerRequires', 'composerDevRequires'] as $property) { $r = new ReflectionProperty($installer, $property); @@ -135,7 +135,7 @@ public static function assertWhitelisted( ?string $message = null ): void { $message ??= sprintf('Failed asserting that package "%s" is whitelisted in composer.json', $package); - $found = false; + $found = false; $r = new ReflectionProperty($installer, 'composerDefinition'); @@ -168,7 +168,7 @@ protected function tearDown(): void protected function createOptionalPackages(?string $projectRoot = null): OptionalPackages { $projectRoot ??= $this->packageRoot; - $this->io = $this->createMock(IOInterface::class); + $this->io = $this->createMock(IOInterface::class); return new OptionalPackages( $this->io, $this->createComposer(), diff --git a/test/MezzioInstallerTest/PromptForOptionalPackagesTest.php b/test/MezzioInstallerTest/PromptForOptionalPackagesTest.php index 875cf09..5785e90 100644 --- a/test/MezzioInstallerTest/PromptForOptionalPackagesTest.php +++ b/test/MezzioInstallerTest/PromptForOptionalPackagesTest.php @@ -110,7 +110,8 @@ public function testPromptForOptionalPackage( continue; } - if (str_contains($message, 'Adding package') + if ( + str_contains($message, 'Adding package') || str_contains($message, '- Copying ') ) { $written[] = $package;