Skip to content

Commit

Permalink
Add type declarations (#463)
Browse files Browse the repository at this point in the history
* Add type declarations

* Apply php-cs-fixer changes

Co-authored-by: sabbelasichon <sabbelasichon@users.noreply.github.com>
  • Loading branch information
sabbelasichon and sabbelasichon committed Feb 7, 2022
1 parent 4e8adff commit e8ac94b
Show file tree
Hide file tree
Showing 107 changed files with 315 additions and 545 deletions.
47 changes: 1 addition & 46 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,50 +1,15 @@
parameters:
ignoreErrors:
-
message: "#^Cannot call method getVersion\\(\\) on Symfony\\\\Component\\\\Console\\\\Application\\|null\\.$#"
count: 1
path: src/Command/SelfUpdateCommand.php

-
message: "#^Method TYPO3\\\\Surf\\\\Domain\\\\Filesystem\\\\Filesystem\\:\\:glob\\(\\) should return array but returns array\\<int, string\\>\\|false\\.$#"
count: 1
path: src/Domain/Filesystem/Filesystem.php

-
message: "#^Parameter \\#1 \\$length of function random_bytes expects int\\<1, max\\>, int given\\.$#"
count: 1
path: src/Domain/Generator/RandomBytesGenerator.php

-
message: "#^Method TYPO3\\\\Surf\\\\Domain\\\\Model\\\\Deployment\\:\\:getReleaseIdentifier\\(\\) should return string but returns string\\|null\\.$#"
count: 1
path: src/Domain/Model/Deployment.php

-
message: "#^Property TYPO3\\\\Surf\\\\Domain\\\\Model\\\\Deployment\\:\\:\\$deploymentLockIdentifier \\(string\\) does not accept string\\|null\\.$#"
count: 1
path: src/Domain/Model/Deployment.php

-
message: "#^Property TYPO3\\\\Surf\\\\Domain\\\\Model\\\\Deployment\\:\\:\\$workflow \\(TYPO3\\\\Surf\\\\Domain\\\\Model\\\\Workflow\\) does not accept object\\|null\\.$#"
message: "#^Parameter \\#1 \\$workflow of method TYPO3\\\\Surf\\\\Domain\\\\Model\\\\Application\\:\\:registerTasks\\(\\) expects TYPO3\\\\Surf\\\\Domain\\\\Model\\\\Workflow, TYPO3\\\\Surf\\\\Domain\\\\Model\\\\Workflow\\|null given\\.$#"
count: 1
path: src/Domain/Model/Deployment.php

-
message: "#^Cannot call method createTimestampFromFormat\\(\\) on TYPO3\\\\Surf\\\\Domain\\\\Clock\\\\ClockInterface\\|null\\.$#"
count: 1
path: src/Task/CleanupReleasesTask.php

-
message: "#^Cannot call method currentTime\\(\\) on TYPO3\\\\Surf\\\\Domain\\\\Clock\\\\ClockInterface\\|null\\.$#"
count: 1
path: src/Task/CleanupReleasesTask.php

-
message: "#^Cannot call method stringToTime\\(\\) on TYPO3\\\\Surf\\\\Domain\\\\Clock\\\\ClockInterface\\|null\\.$#"
count: 1
path: src/Task/CleanupReleasesTask.php

-
message: "#^Parameter \\#1 \\$input of function array_filter expects array, array\\<array\\|string\\>\\|false given\\.$#"
count: 1
Expand All @@ -55,16 +20,6 @@ parameters:
count: 1
path: src/Task/Generic/RollbackTask.php

-
message: "#^Parameter \\#2 \\$node of method TYPO3\\\\Surf\\\\Task\\\\Git\\\\AbstractCheckoutTask\\:\\:executeOrSimulateGitCloneOrUpdate\\(\\) expects TYPO3\\\\Surf\\\\Domain\\\\Model\\\\Node, TYPO3\\\\Surf\\\\Domain\\\\Model\\\\Node\\|null given\\.$#"
count: 1
path: src/Task/Package/GitTask.php

-
message: "#^Parameter \\#3 \\$node of method TYPO3\\\\Surf\\\\Task\\\\Git\\\\AbstractCheckoutTask\\:\\:executeOrSimulatePostGitCheckoutCommands\\(\\) expects TYPO3\\\\Surf\\\\Domain\\\\Model\\\\Node, TYPO3\\\\Surf\\\\Domain\\\\Model\\\\Node\\|null given\\.$#"
count: 1
path: src/Task/Package/GitTask.php

-
message: "#^Parameter \\#1 \\$arg of function escapeshellarg expects string, string\\|null given\\.$#"
count: 1
Expand Down
4 changes: 3 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

Expand All @@ -14,12 +15,13 @@
__DIR__ . '/src',
__DIR__ . '/tests',
]);
$containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT);

$parameters->set(Option::AUTO_IMPORT_NAMES, true);
// get services (needed for register a single rule)
$services = $containerConfigurator->services();

// register a single rule
$services->set(TypedPropertyRector::class);
//$services->set(TypedPropertyRector::class);
//$services->set(AddVoidReturnTypeWhereNoReturnRector::class);
};
11 changes: 3 additions & 8 deletions src/Application/BaseApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@ class BaseApplication extends Application
* Symlinks, which should be created for each release.
*
* @see \TYPO3\Surf\Task\Generic\CreateSymlinksTask
* @var array
*/
protected $symlinks = [];
protected array $symlinks = [];

/**
* Directories which should be created on deployment. E.g. shared folders.
*
* @var array
*/
protected $directories = [];
protected array $directories = [];

/**
* Basic application specific options
Expand All @@ -62,10 +59,8 @@ class BaseApplication extends Application
* updateMethod: How to prepare and update the application assets on the node after transfer
*
* lockDeployment: Locked deployments can only run once at a time
*
* @var array
*/
protected $options = [
protected array $options = [
'packageMethod' => 'git',
'transferMethod' => 'rsync',
'updateMethod' => null,
Expand Down
6 changes: 2 additions & 4 deletions src/Application/Neos/Flow.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ class Flow extends BaseApplication
{
/**
* The production context
* @var string
*/
protected $context = 'Production';
protected string $context = 'Production';

/**
* The Neos Flow major and minor version of this application
* @var string
*/
protected $version = '4.0';
protected string $version = '4.0';

public const DEFAULT_WEB_DIRECTORY = 'Web';

Expand Down
10 changes: 5 additions & 5 deletions src/Cli/Symfony/ConsoleKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class ConsoleKernel extends Kernel
/**
* @inheritDoc
*/
public function registerBundles()
public function registerBundles(): array
{
return [];
}
Expand All @@ -42,16 +42,16 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
/**
* @inheritDoc
*/
protected function build(ContainerBuilder $containerBuilder): void
protected function build(ContainerBuilder $container): void
{
$containerBuilder->addCompilerPass(new CommandsToApplicationCompilerPass());
$containerBuilder->registerForAutoconfiguration(
$container->addCompilerPass(new CommandsToApplicationCompilerPass());
$container->registerForAutoconfiguration(
ContainerAwareInterface::class
)->addMethodCall(
'setContainer',
[new Reference(ContainerInterface::class)]
);
$containerBuilder->registerForAutoconfiguration(
$container->registerForAutoconfiguration(
ShellCommandServiceAwareInterface::class
)->addMethodCall(
'setShellCommandService',
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Symfony/Logger/ConsoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function write(array $record): void
/**
* {@inheritdoc}
*/
protected function getDefaultFormatter()
protected function getDefaultFormatter(): ConsoleFormatter
{
return new ConsoleFormatter();
}
Expand Down
22 changes: 6 additions & 16 deletions src/Command/DescribeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@

class DescribeCommand extends Command
{
/**
* @var InputInterface
*/
protected $input;
protected InputInterface $input;

/**
* @var OutputInterface
*/
protected $output;
protected OutputInterface $output;

private FactoryInterface $factory;

Expand Down Expand Up @@ -70,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$deployment = $this->factory->getDeployment((string)$deploymentName, $configurationPath);
$workflow = $deployment->getWorkflow();

if (! $deployment instanceof FailedDeployment) {
if (! $deployment instanceof FailedDeployment && $workflow instanceof Workflow) {
$output->writeln('<success>Deployment ' . $deployment->getName() . '</success>');
$output->writeln('');
$output->writeln('Workflow: <success>' . $workflow->getName() . '</success>');
Expand All @@ -84,10 +78,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->printNodes($deployment->getNodes());

$this->printApplications($deployment->getApplications(), $deployment->getWorkflow());
$this->printApplications($deployment->getApplications(), $workflow);
}

return 0;
return Command::SUCCESS;
}

protected function printNodes(array $nodes): void
Expand Down Expand Up @@ -154,13 +148,9 @@ protected function printStages(Application $application, array $stages, array $t
/**
* Print all tasks before or after a task
*
* @param array $tasks
* @param string $applicationName
* @param string $task
* @param string $step
* @param string $output
*/
private function printBeforeAfterTasks(array $tasks, $applicationName, $task, $step, &$output): void
private function printBeforeAfterTasks(array $tasks, string $applicationName, string $task, string $step, &$output): void
{
foreach (['_', $applicationName] as $name) {
$label = $name === '_' ? 'for all applications' : 'for application ' . $name;
Expand Down
12 changes: 8 additions & 4 deletions src/Command/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$stability = $input->getOption('stability');

/** @var GithubStrategy $strategy */
$strategy = $updater->getStrategy();
$strategy->setCurrentLocalVersion($this->getApplication()->getVersion());
$application = $this->getApplication();

if (! $application instanceof \Symfony\Component\Console\Application) {
throw new \UnexpectedValueException('No application defined');
}

$strategy->setCurrentLocalVersion($application->getVersion());
$strategy->setStability($stability);

if ($input->getOption('check')) {
Expand Down Expand Up @@ -104,7 +108,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

return 0;
return Command::SUCCESS;
}

private function getLocalPharName(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
$output->writeln('');

return 0;
return Command::SUCCESS;
}
}
4 changes: 1 addition & 3 deletions src/Domain/Clock/ClockException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
final class ClockException extends Exception
{
/**
* @param string $string
*
* @return ClockException
*/
public static function stringCouldNotBeConvertedToTimestamp($string)
public static function stringCouldNotBeConvertedToTimestamp(string $string): self
{
return new self(sprintf('The string %s could not be converted to timestamp', $string));
}
Expand Down
8 changes: 7 additions & 1 deletion src/Domain/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public function createDirectory(string $directory): bool

public function glob(string $pattern): array
{
return glob($pattern);
$matches = glob($pattern);

if ($matches === false) {
throw new \UnexpectedValueException(sprintf('Glob pattern "%s" could be applied', $pattern));
}

return $matches;
}
}
15 changes: 4 additions & 11 deletions src/Domain/Model/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ class Application

/**
* The name
* @var string
*/
protected $name;
protected string $name;

/**
* The nodes for this application
Expand All @@ -39,21 +38,15 @@ class Application

/**
* The deployment path for this application on a node
* @var string
*/
protected $deploymentPath = '';
protected string $deploymentPath = '';

/**
* The relative releases directory for this application on a node
* @var string
*/
protected $releasesDirectory = 'releases';
protected string $releasesDirectory = 'releases';

/**
* The options
* @var array
*/
protected $options = [];
protected array $options = [];

public function __construct(string $name)
{
Expand Down

0 comments on commit e8ac94b

Please sign in to comment.