From a6093ed7a8febc1c81de0a7618d82fe3165f6b7d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 10 Jan 2023 00:19:31 +0700 Subject: [PATCH] Apply PHP 8.0 Syntax and constructor promotion Signed-off-by: Abdul Malik Ikhsan --- src/AssetInstaller.php | 10 +--------- src/AssetUninstaller.php | 12 ++---------- src/Plugin.php | 8 +++----- test/AssetInstallerTest.php | 3 +-- test/AssetUninstallerTest.php | 3 +-- test/PluginTest.php | 7 +++---- 6 files changed, 11 insertions(+), 32 deletions(-) diff --git a/src/AssetInstaller.php b/src/AssetInstaller.php index 27d11cd..f754202 100644 --- a/src/AssetInstaller.php +++ b/src/AssetInstaller.php @@ -36,19 +36,11 @@ class AssetInstaller { use UnparseableTokensTrait; - /** @var Composer */ - private $composer; - - /** @var IOInterface */ - private $io; - /** @var string Base path for project; default is current working dir. */ private $projectPath; - public function __construct(Composer $composer, IOInterface $io) + public function __construct(private Composer $composer, private IOInterface $io) { - $this->composer = $composer; - $this->io = $io; $this->projectPath = getcwd(); } diff --git a/src/AssetUninstaller.php b/src/AssetUninstaller.php index 55da181..b4672a3 100644 --- a/src/AssetUninstaller.php +++ b/src/AssetUninstaller.php @@ -32,22 +32,14 @@ class AssetUninstaller { use UnparseableTokensTrait; - /** @var Composer */ - private $composer; - /** @var string[] .gitignore rules */ - private $gitignore = []; - - /** @var IOInterface */ - private $io; + private array $gitignore = []; /** @var string Base path for project; default is current working dir. */ private $projectPath; - public function __construct(Composer $composer, IOInterface $io) + public function __construct(private Composer $composer, private IOInterface $io) { - $this->composer = $composer; - $this->io = $io; $this->projectPath = getcwd(); } diff --git a/src/Plugin.php b/src/Plugin.php index 002b4f2..34dda26 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -18,18 +18,16 @@ class Plugin implements PluginInterface, EventSubscriberInterface { - /** @var Composer */ - private $composer; + private Composer $composer; /** * Array of installers to run following a dump-autoload operation. * * @var callable[] */ - private $installers = []; + private array $installers = []; - /** @var IOInterface */ - private $io; + private IOInterface $io; /** * Provide composer event listeners. diff --git a/test/AssetInstallerTest.php b/test/AssetInstallerTest.php index e356699..775eb28 100644 --- a/test/AssetInstallerTest.php +++ b/test/AssetInstallerTest.php @@ -51,8 +51,7 @@ class AssetInstallerTest extends TestCase /** @var IOInterface|ObjectProphecy */ private $io; - /** @var vfsStreamDirectory */ - private $filesystem; + private vfsStreamDirectory $filesystem; public function setUp(): void { diff --git a/test/AssetUninstallerTest.php b/test/AssetUninstallerTest.php index 31ec99a..3a82497 100644 --- a/test/AssetUninstallerTest.php +++ b/test/AssetUninstallerTest.php @@ -83,8 +83,7 @@ class AssetUninstallerTest extends TestCase ], ]; - /** @var vfsStreamDirectory */ - private $filesystem; + private vfsStreamDirectory $filesystem; /** @var PackageInterface|ObjectProphecy */ private $package; diff --git a/test/PluginTest.php b/test/PluginTest.php index 3b73e4a..83c2fe4 100644 --- a/test/PluginTest.php +++ b/test/PluginTest.php @@ -24,8 +24,7 @@ class PluginTest extends TestCase use DeprecatedAssertionsTrait; use ProphecyTrait; - /** @var vfsStreamDirectory */ - private $filesystem; + private vfsStreamDirectory $filesystem; /** @var Composer|ObjectProphecy */ private $composer; @@ -102,10 +101,10 @@ public function testOnPostAutoloadDumpTriggersInstallers(): void /** @psalm-var object{operations: array} $obj */ $spy = (object) ['operations' => []]; - $installer1 = function () use ($spy): void { + $installer1 = static function () use ($spy): void { $spy->operations[] = 'installer1'; }; - $installer2 = function () use ($spy): void { + $installer2 = static function () use ($spy): void { $spy->operations[] = 'installer2'; };