From 497356ed4c6ab600f99b0f8476e7d848d56e4d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 28 Dec 2021 12:11:35 +0100 Subject: [PATCH 1/3] Enhancement: Use Php74 rule set --- .php-cs-fixer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index acac9edc..e94357d9 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -26,7 +26,7 @@ $license->save(); -$config = PhpCsFixer\Config\Factory::fromRuleSet(new PhpCsFixer\Config\RuleSet\Php73($license->header())); +$config = PhpCsFixer\Config\Factory::fromRuleSet(new PhpCsFixer\Config\RuleSet\Php74($license->header())); $config->getFinder() ->exclude([ From f7170ad739cfd9ba910896b0bf2d9030fa6eb61b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 28 Dec 2021 12:12:30 +0100 Subject: [PATCH 2/3] Fix: Run 'make coding-standards' --- src/Version.php | 4 +--- .../NormalizeCommand/AbstractTestCase.php | 6 +---- .../Normalizer/Throws/Test.php | 5 +--- test/Util/CommandInvocation.php | 5 +--- test/Util/Directory.php | 11 ++------- test/Util/File.php | 17 +++----------- test/Util/Scenario.php | 11 ++------- test/Util/State.php | 23 ++++--------------- 8 files changed, 15 insertions(+), 67 deletions(-) diff --git a/src/Version.php b/src/Version.php index 3eaf832d..33d89fc9 100644 --- a/src/Version.php +++ b/src/Version.php @@ -20,10 +20,8 @@ final class Version { /** * @see https://github.com/box-project/box/blob/master/doc/configuration.md#pretty-git-tag-placeholder-git - * - * @var string */ - private static $version = '@git@'; + private static string $version = '@git@'; public static function long(): string { diff --git a/test/Integration/Command/NormalizeCommand/AbstractTestCase.php b/test/Integration/Command/NormalizeCommand/AbstractTestCase.php index 3de20954..3d2626c0 100644 --- a/test/Integration/Command/NormalizeCommand/AbstractTestCase.php +++ b/test/Integration/Command/NormalizeCommand/AbstractTestCase.php @@ -29,11 +29,7 @@ abstract class AbstractTestCase extends Framework\TestCase { use Test\Util\Helper; - - /** - * @var string - */ - private $currentWorkingDirectory; + private string $currentWorkingDirectory; final protected function setUp(): void { diff --git a/test/Integration/Command/NormalizeCommand/Normalizer/Throws/Test.php b/test/Integration/Command/NormalizeCommand/Normalizer/Throws/Test.php index 8d40952a..67dc1744 100644 --- a/test/Integration/Command/NormalizeCommand/Normalizer/Throws/Test.php +++ b/test/Integration/Command/NormalizeCommand/Normalizer/Throws/Test.php @@ -52,10 +52,7 @@ public function testFailsWhenNormalizerThrowsRuntimeExceptionDuringNormalization $application = self::createApplication(new NormalizeCommand( new Factory(), new class($exceptionMessage) implements Normalizer\NormalizerInterface { - /** - * @var string - */ - private $exceptionMessage; + private string $exceptionMessage; public function __construct(string $exceptionMessage) { diff --git a/test/Util/CommandInvocation.php b/test/Util/CommandInvocation.php index 2e073fe6..589a1109 100644 --- a/test/Util/CommandInvocation.php +++ b/test/Util/CommandInvocation.php @@ -15,10 +15,7 @@ final class CommandInvocation { - /** - * @var string - */ - private $style; + private string $style; private function __construct(string $variation) { diff --git a/test/Util/Directory.php b/test/Util/Directory.php index b134bc1d..500b8f8f 100644 --- a/test/Util/Directory.php +++ b/test/Util/Directory.php @@ -15,15 +15,8 @@ final class Directory { - /** - * @var string - */ - private $path; - - /** - * @var bool - */ - private $exists; + private string $path; + private bool $exists; private function __construct(string $path) { diff --git a/test/Util/File.php b/test/Util/File.php index 39fa5304..708ce263 100644 --- a/test/Util/File.php +++ b/test/Util/File.php @@ -15,20 +15,9 @@ final class File { - /** - * @var string - */ - private $path; - - /** - * @var bool - */ - private $exists = false; - - /** - * @var null|string - */ - private $contents; + private string $path; + private bool $exists = false; + private ?string $contents; private function __construct() { diff --git a/test/Util/Scenario.php b/test/Util/Scenario.php index 667ca91b..0eaeb224 100644 --- a/test/Util/Scenario.php +++ b/test/Util/Scenario.php @@ -15,15 +15,8 @@ final class Scenario { - /** - * @var CommandInvocation - */ - private $commandInvocation; - - /** - * @var State - */ - private $initialState; + private CommandInvocation $commandInvocation; + private State $initialState; private function __construct(CommandInvocation $commandInvocation, State $initialState) { diff --git a/test/Util/State.php b/test/Util/State.php index 6adf69e1..a999fc38 100644 --- a/test/Util/State.php +++ b/test/Util/State.php @@ -15,25 +15,10 @@ final class State { - /** - * @var Directory - */ - private $directory; - - /** - * @var File - */ - private $composerJsonFile; - - /** - * @var File - */ - private $composerLockFile; - - /** - * @var Directory - */ - private $vendorDirectory; + private Directory $directory; + private File $composerJsonFile; + private File $composerLockFile; + private Directory $vendorDirectory; private function __construct(Directory $directory) { From 735e05981419b89256c86428f649ff7babd0269e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 28 Dec 2021 12:15:38 +0100 Subject: [PATCH 3/3] Fix: Initialize properties in constructor --- test/Util/File.php | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/test/Util/File.php b/test/Util/File.php index 708ce263..28f4b395 100644 --- a/test/Util/File.php +++ b/test/Util/File.php @@ -16,30 +16,44 @@ final class File { private string $path; - private bool $exists = false; + private bool $exists; private ?string $contents; - private function __construct() - { + private function __construct( + string $path, + bool $exists, + ?string $contents + ) { + $this->path = $path; + $this->exists = $exists; + $this->contents = $contents; } public static function fromPath(string $path): self { - $file = new self(); - - $file->path = $path; - - if (\file_exists($path)) { - $file->exists = true; + if (!\file_exists($path)) { + return new self( + $path, + false, + null, + ); + } - $contents = \file_get_contents($path); + $contents = \file_get_contents($path); - if (\is_string($contents)) { - $file->contents = $contents; - } + if (!\is_string($contents)) { + return new self( + $path, + true, + null, + ); } - return $file; + return new self( + $path, + true, + $contents, + ); } public function path(): string