diff --git a/rector.php b/rector.php index 7e97cb42..b389625a 100644 --- a/rector.php +++ b/rector.php @@ -10,10 +10,12 @@ */ use Rector\Config\RectorConfig; +use Rector\Php84\Rector\Param\ExplicitNullableParamTypeRector; use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector; use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector; use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Set\ValueObject\LevelSetList; +use Rector\ValueObject\PhpVersion; return static function (RectorConfig $rectorConfig): void { $rectorConfig->importNames(); @@ -32,4 +34,8 @@ PHPUnitSetList::PHPUNIT_90, LevelSetList::UP_TO_PHP_74, ]); + $rectorConfig->rules([ + ExplicitNullableParamTypeRector::class, + ]); + $rectorConfig->phpVersion(PhpVersion::PHP_84); }; diff --git a/src/Cli/Symfony/ConsoleApplication.php b/src/Cli/Symfony/ConsoleApplication.php index 412de658..68edfda5 100644 --- a/src/Cli/Symfony/ConsoleApplication.php +++ b/src/Cli/Symfony/ConsoleApplication.php @@ -32,7 +32,7 @@ public function __construct(FactoryInterface $factory, OutputInterface $output, $this->output = $output; } - public function run(InputInterface $input = null, OutputInterface $output = null): int + public function run(?InputInterface $input = null, ?OutputInterface $output = null): int { return parent::run($input, $this->output); } diff --git a/src/Domain/Clock/ClockInterface.php b/src/Domain/Clock/ClockInterface.php index 09cf86e6..013590d5 100644 --- a/src/Domain/Clock/ClockInterface.php +++ b/src/Domain/Clock/ClockInterface.php @@ -15,7 +15,7 @@ interface ClockInterface { public function currentTime(): int; - public function stringToTime(string $string, int $time = null): int; + public function stringToTime(string $string, ?int $time = null): int; public function createTimestampFromFormat(string $format, string $time): int; } diff --git a/src/Domain/Clock/SystemClock.php b/src/Domain/Clock/SystemClock.php index 24b1acc1..6cc5f10e 100644 --- a/src/Domain/Clock/SystemClock.php +++ b/src/Domain/Clock/SystemClock.php @@ -20,7 +20,7 @@ public function currentTime(): int return time(); } - public function stringToTime(string $string, int $time = null): int + public function stringToTime(string $string, ?int $time = null): int { $time ??= $this->currentTime(); $timestamp = strtotime($string, $time); diff --git a/src/Domain/Model/Deployment.php b/src/Domain/Model/Deployment.php index 43d5499b..e1502a06 100644 --- a/src/Domain/Model/Deployment.php +++ b/src/Domain/Model/Deployment.php @@ -101,7 +101,7 @@ class Deployment implements LoggerAwareInterface private string $deploymentLockIdentifier; private ContainerInterface $container; - public function __construct(ContainerInterface $container, string $name, string $deploymentLockIdentifier = null) + public function __construct(ContainerInterface $container, string $name, ?string $deploymentLockIdentifier = null) { $this->container = $container; $this->name = $name; diff --git a/src/Domain/Model/Workflow.php b/src/Domain/Model/Workflow.php index 8b48ff7f..bb660658 100644 --- a/src/Domain/Model/Workflow.php +++ b/src/Domain/Model/Workflow.php @@ -51,7 +51,7 @@ abstract public function getName(): string; /** * Remove the given task from all stages and applications */ - public function removeTask(string $removeTask, Application $application = null): self + public function removeTask(string $removeTask, ?Application $application = null): self { $removeApplicationName = $application instanceof Application ? $application->getName() : null; @@ -111,7 +111,7 @@ public function forStage(string $stage, $tasks): self * @param string $stage The name of the stage when this task shall be executed * @param string $step A stage has three steps "before", "tasks" and "after" */ - protected function addTaskToStage($tasks, string $stage, Application $application = null, string $step = 'tasks'): void + protected function addTaskToStage($tasks, string $stage, ?Application $application = null, string $step = 'tasks'): void { if (!is_array($tasks)) { $tasks = [$tasks]; @@ -137,7 +137,7 @@ protected function addTaskToStage($tasks, string $stage, Application $applicatio * * @return Workflow */ - public function addTask($tasks, string $stage, Application $application = null) + public function addTask($tasks, string $stage, ?Application $application = null) { $this->addTaskToStage($tasks, $stage, $application); @@ -151,7 +151,7 @@ public function addTask($tasks, string $stage, Application $application = null) * * @param array|string $tasks */ - public function afterTask(string $task, $tasks, Application $application = null): self + public function afterTask(string $task, $tasks, ?Application $application = null): self { if (!is_array($tasks)) { $tasks = [$tasks]; @@ -174,7 +174,7 @@ public function afterTask(string $task, $tasks, Application $application = null) * * @param array|string $tasks */ - public function beforeTask(string $task, $tasks, Application $application = null): self + public function beforeTask(string $task, $tasks, ?Application $application = null): self { if (!is_array($tasks)) { $tasks = [$tasks]; @@ -209,7 +209,7 @@ public function defineTask(string $taskName, string $baseTask, array $options): * * @param class-string[]|string $tasks */ - public function beforeStage(string $stage, $tasks, Application $application = null): self + public function beforeStage(string $stage, $tasks, ?Application $application = null): self { $this->addTaskToStage($tasks, $stage, $application, 'before'); @@ -221,7 +221,7 @@ public function beforeStage(string $stage, $tasks, Application $application = nu * * @param class-string[]|string $tasks */ - public function afterStage(string $stage, $tasks, Application $application = null): self + public function afterStage(string $stage, $tasks, ?Application $application = null): self { $this->addTaskToStage($tasks, $stage, $application, 'after'); diff --git a/src/Integration/Factory.php b/src/Integration/Factory.php index 58a6fc06..e00d8783 100644 --- a/src/Integration/Factory.php +++ b/src/Integration/Factory.php @@ -40,7 +40,7 @@ public function __construct(ContainerInterface $container, FilesystemInterface $ $this->logger = $logger; } - public function getDeployment(string $deploymentName, string $configurationPath = null, bool $simulateDeployment = true, bool $initialize = true, bool $forceDeployment = false): Deployment + public function getDeployment(string $deploymentName, ?string $configurationPath = null, bool $simulateDeployment = true, bool $initialize = true, bool $forceDeployment = false): Deployment { $deployment = $this->createDeployment($deploymentName, $configurationPath); @@ -65,7 +65,7 @@ public function getDeployment(string $deploymentName, string $configurationPath /** * @inheritDoc */ - public function getDeploymentNames(string $path = null): array + public function getDeploymentNames(?string $path = null): array { $path = $this->getDeploymentsBasePath($path); $files = $this->filesystem->glob(Files::concatenatePaths([$path, '*.php'])); @@ -76,7 +76,7 @@ public function getDeploymentNames(string $path = null): array /** * @inheritDoc */ - public function getDeploymentsBasePath(string $path = null): string + public function getDeploymentsBasePath(?string $path = null): string { $localDeploymentDescription = $this->filesystem->getRealPath('./.surf'); if (! $path && $this->filesystem->isDirectory($localDeploymentDescription)) { @@ -91,7 +91,7 @@ public function getDeploymentsBasePath(string $path = null): string /** * @inheritDoc */ - public function getWorkspacesBasePath(string $path = null): string + public function getWorkspacesBasePath(?string $path = null): string { $workspacesBasePath = getenv('SURF_WORKSPACE'); @@ -124,7 +124,7 @@ public function getWorkspacesBasePath(string $path = null): string * The script has access to a deployment object as "$deployment". This could change * in the future. */ - protected function createDeployment(string $deploymentName, string $path = null): Deployment + protected function createDeployment(string $deploymentName, ?string $path = null): Deployment { $deploymentConfigurationPath = $this->getDeploymentsBasePath($path); $workspacesBasePath = $this->getWorkspacesBasePath(); diff --git a/src/Integration/FactoryInterface.php b/src/Integration/FactoryInterface.php index 33f2a0f2..a6b8d859 100644 --- a/src/Integration/FactoryInterface.php +++ b/src/Integration/FactoryInterface.php @@ -15,7 +15,7 @@ interface FactoryInterface { - public function getDeployment(string $deploymentName, string $configurationPath = null, bool $simulateDeployment = true, bool $initialize = true, bool $forceDeployment = false): Deployment; + public function getDeployment(string $deploymentName, ?string $configurationPath = null, bool $simulateDeployment = true, bool $initialize = true, bool $forceDeployment = false): Deployment; /** * Get available deployment names @@ -24,17 +24,17 @@ public function getDeployment(string $deploymentName, string $configurationPath * * @return string[] */ - public function getDeploymentNames(string $path = null): array; + public function getDeploymentNames(?string $path = null): array; /** * Get the root path of the surf deployment declarations * * This defaults to ./.surf if a NULL path is given. */ - public function getDeploymentsBasePath(string $path = null): string; + public function getDeploymentsBasePath(?string $path = null): string; /** * Get the base path to local workspaces */ - public function getWorkspacesBasePath(string $path = null): string; + public function getWorkspacesBasePath(?string $path = null): string; } diff --git a/tests/Unit/Domain/Service/ShellCommandServiceTest.php b/tests/Unit/Domain/Service/ShellCommandServiceTest.php index 55804447..430806ac 100644 --- a/tests/Unit/Domain/Service/ShellCommandServiceTest.php +++ b/tests/Unit/Domain/Service/ShellCommandServiceTest.php @@ -34,10 +34,10 @@ class ShellCommandServiceTest extends TestCase */ public function executeRemoteCommandRespectsOptionsInSshCommand( string $expectedCommandArguments, - string $username = null, - string $password = null, - int $port = null, - string $privateKey = null + ?string $username = null, + ?string $password = null, + ?int $port = null, + ?string $privateKey = null ): void { /** @var MockObject|ShellCommandService $service */ $service = $this->createPartialMock(ShellCommandService::class, ['executeProcess']);