Skip to content

Commit

Permalink
Merge b4eb4fc into 37602ff
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed Feb 3, 2022
2 parents 37602ff + b4eb4fc commit 5a06bb9
Show file tree
Hide file tree
Showing 80 changed files with 346 additions and 267 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@
"bin/surf"
],
"scripts": {
"phpstan": "vendor/bin/phpstan analyse --ansi"
"phpstan": "phpstan analyse --ansi"
}
}
97 changes: 97 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$object_or_string of function is_a expects object\\|string, string\\|null given\\.$#"
count: 1
path: src/Cli/Symfony/CompilerPasses/CommandsToApplicationCompilerPass.php

-
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\\:\\:\\$releaseIdentifier \\(string\\|null\\) does not accept string\\|false\\.$#"
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\\.$#"
count: 1
path: src/Domain/Model/Deployment.php

-
message: "#^Parameter \\#1 \\$name of method TYPO3\\\\Surf\\\\Domain\\\\Model\\\\Deployment\\:\\:__construct\\(\\) expects string, string\\|null given\\.$#"
count: 1
path: src/Domain/Model/FailedDeployment.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
path: src/Task/CleanupReleasesTask.php

-
message: "#^Parameter \\#1 \\$input of function array_filter expects array, array\\<array\\|string\\>\\|false given\\.$#"
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
path: src/Task/TYPO3/CMS/AbstractCliTask.php

-
message: "#^Parameter \\#2 \\$node of method TYPO3\\\\Surf\\\\Domain\\\\Service\\\\ShellCommandService\\:\\:executeOrSimulate\\(\\) expects TYPO3\\\\Surf\\\\Domain\\\\Model\\\\Node, TYPO3\\\\Surf\\\\Domain\\\\Model\\\\Node\\|null given\\.$#"
count: 2
path: src/Task/TYPO3/CMS/AbstractCliTask.php

-
message: "#^Offset mixed on array\\{\\} in isset\\(\\) does not exist\\.$#"
count: 2
path: tests/Unit/Task/BaseTaskTest.php

11 changes: 6 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
includes:
- phpstan-baseline.neon
parameters:
level: 2
level: 8
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
paths:
- "src/"
- "tests/"
- src
- tests

inferPrivatePropertyTypeFromConstructor: true
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false

ignoreErrors:
20 changes: 6 additions & 14 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,21 @@

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

return static function (ContainerConfigurator $containerConfigurator): void {
// get parameters
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [
__DIR__ . '/tests'
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// Define what rule sets will be applied
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_70);
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_75);
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_80);
$containerConfigurator->import(PHPUnitSetList::PHPUNIT80_DMS);
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_CODE_QUALITY);
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_EXCEPTION);
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD);
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_YIELD_DATA_PROVIDER);

// get services (needed for register a single rule)
// $services = $containerConfigurator->services();
$services = $containerConfigurator->services();

// register a single rule
// $services->set(TypedPropertyRector::class);
//$services->set(TypedPropertyRector::class);
$services->set(AddVoidReturnTypeWhereNoReturnRector::class);
};
10 changes: 5 additions & 5 deletions src/Command/DescribeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(FactoryInterface $factory)
$this->factory = $factory;
}

protected function configure()
protected function configure(): void
{
$this->setDescription('Describes the flow for the given name')
->addArgument(
Expand Down Expand Up @@ -93,15 +93,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

protected function printNodes(array $nodes)
protected function printNodes(array $nodes): void
{
$this->output->writeln('Nodes:' . PHP_EOL);
foreach ($nodes as $node) {
$this->output->writeln(' <success>' . $node->getName() . '</success> <info>(' . $node->getHostname() . ')</info>');
}
}

protected function printApplications(array $applications, Workflow $workflow)
protected function printApplications(array $applications, Workflow $workflow): void
{
$this->output->writeln(PHP_EOL . 'Applications:' . PHP_EOL);
foreach ($applications as $application) {
Expand Down Expand Up @@ -129,7 +129,7 @@ protected function printApplications(array $applications, Workflow $workflow)
}
}

protected function printStages(Application $application, array $stages, array $tasks)
protected function printStages(Application $application, array $stages, array $tasks): void
{
foreach ($stages as $stage) {
$this->output->writeln(' <comment>' . $stage . ':</comment>');
Expand Down Expand Up @@ -163,7 +163,7 @@ protected function printStages(Application $application, array $stages, array $t
* @param string $step
* @param string $output
*/
private function printBeforeAfterTasks(array $tasks, $applicationName, $task, $step, &$output)
private function printBeforeAfterTasks(array $tasks, $applicationName, $task, $step, &$output): void
{
foreach (['_', $applicationName] as $name) {
$label = $name === '_' ? 'for all applications' : 'for application ' . $name;
Expand Down
10 changes: 2 additions & 8 deletions src/Domain/Clock/ClockException.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ public static function stringCouldNotBeConvertedToTimestamp($string)
return new self(sprintf('The string %s could not be converted to timestamp', $string));
}

/**
* @param string $format
* @param int $time
*
* @return ClockException
*/
public static function formatCouldNotBeConvertedToTimestamp($format, $time)
public static function formatCouldNotBeConvertedToTimestamp(string $format, string $time): self
{
return new self(sprintf('The format %s could not be converted to timestamp for time %d', $format, $time));
return new self(sprintf('The format %s could not be converted to timestamp for time %s', $format, $time));
}
}
2 changes: 1 addition & 1 deletion src/Domain/Clock/SystemClock.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public function createTimestampFromFormat(string $format, string $time): int
if ($datetime === false) {
throw ClockException::formatCouldNotBeConvertedToTimestamp($format, $time);
}
return $datetime->format('U');
return $datetime->getTimestamp();
}
}
49 changes: 29 additions & 20 deletions src/Domain/Model/Deployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ class Deployment implements LoggerAwareInterface, ContainerAwareInterface

/**
* The release identifier will be created on each deployment
* @var string
* @var string|null
*/
protected $releaseIdentifier;

/**
* TRUE if the deployment should be simulated
* @var string
* @var bool
*/
protected $dryRun = false;

Expand Down Expand Up @@ -128,10 +128,17 @@ class Deployment implements LoggerAwareInterface, ContainerAwareInterface
*/
private $deploymentLockIdentifier;

public function __construct($name, $deploymentLockIdentifier = null)
public function __construct(string $name, string $deploymentLockIdentifier = null)
{
$this->name = $name;
$this->releaseIdentifier = strftime('%Y%m%d%H%M%S', time());

$time = strftime('%Y%m%d%H%M%S', time());

if($time === false) {
throw new \UnexpectedValueException('Could not create valid releaseIdentifier');
}

$this->releaseIdentifier = $time;

$this->setDeploymentLockIdentifier($deploymentLockIdentifier);
}
Expand All @@ -146,7 +153,7 @@ public function __construct($name, $deploymentLockIdentifier = null)
*
* @throws SurfException
*/
public function initialize()
public function initialize(): void
{
if ($this->initialized) {
throw new SurfException('Already initialized', 1335976472);
Expand Down Expand Up @@ -184,7 +191,7 @@ public function onInitialize($callback)
*
* @throws SurfException
*/
public function deploy()
public function deploy(): void
{
$this->logger->notice('Deploying ' . $this->name . ' (' . $this->releaseIdentifier . ')');
$this->workflow->run($this);
Expand All @@ -195,7 +202,7 @@ public function deploy()
*
* It will set dryRun = TRUE which can be inspected by any task.
*/
public function simulate()
public function simulate(): void
{
$this->setDryRun(true);
$this->logger->notice('Simulating ' . $this->name . ' (' . $this->releaseIdentifier . ')');
Expand Down Expand Up @@ -274,9 +281,9 @@ public function getNodes()
*
* In the special case "localhost" an ad-hoc Node with hostname "localhost" is returned.
*
* @return Node The Node or NULL if no Node with the given name was found
* @return Node|null The Node or NULL if no Node with the given name was found
*/
public function getNode($name)
public function getNode(string $name): ?Node
{
if ($name === 'localhost') {
$node = new Node('localhost');
Expand Down Expand Up @@ -368,22 +375,22 @@ public function getReleaseIdentifier()
return $this->releaseIdentifier;
}

public function setRelativeProjectRootPath($relativeProjectRootPath)
public function setRelativeProjectRootPath(string $relativeProjectRootPath): self
{
$this->relativeProjectRootPath = $relativeProjectRootPath;

return $this;
}

public function getRelativeProjectRootPath()
public function getRelativeProjectRootPath(): string
{
return $this->relativeProjectRootPath;
}

/**
* @return bool TRUE If the deployment is run in "dry run" mode
*/
public function isDryRun()
public function isDryRun(): bool
{
return $this->dryRun;
}
Expand Down Expand Up @@ -503,7 +510,7 @@ public function setOption($key, $value)
*
* @param string $deploymentConfigurationPath
*/
public function setDeploymentBasePath($deploymentConfigurationPath)
public function setDeploymentBasePath($deploymentConfigurationPath): void
{
$this->deploymentBasePath = $deploymentConfigurationPath;
}
Expand All @@ -521,15 +528,15 @@ public function getDeploymentBasePath()
/**
* @param string $workspacesBasePath
*/
public function setWorkspacesBasePath($workspacesBasePath)
public function setWorkspacesBasePath($workspacesBasePath): void
{
$this->workspacesBasePath = rtrim($workspacesBasePath, '\\/');
}

/**
* @param string $temporaryPath
*/
public function setTemporaryPath($temporaryPath)
public function setTemporaryPath($temporaryPath): void
{
$this->temporaryPath = rtrim($temporaryPath, '\\/');
}
Expand Down Expand Up @@ -582,16 +589,18 @@ public function getWorkspaceWithProjectRootPath(Application $application)
/**
* Get path to a temp folder on the filesystem
*/
public function getTemporaryPath()
public function getTemporaryPath(): string
{
return $this->temporaryPath;
}

public function rollback(bool $dryRun = false)
public function rollback(bool $dryRun = false): void
{
$this->logger->notice('Rollback deployment ' . $this->name . ' (' . $this->releaseIdentifier . ')');

$this->setWorkflow($this->container->get(RollbackWorkflow::class));
/** @var RollbackWorkflow $workflow */
$workflow = $this->container->get(RollbackWorkflow::class);
$this->setWorkflow($workflow);
$this->initialize();
if ($dryRun) {
$this->setDryRun(true);
Expand All @@ -602,7 +611,7 @@ public function rollback(bool $dryRun = false)
/**
* @param bool $force
*/
public function setForceRun($force)
public function setForceRun($force): void
{
$this->forceRun = (bool)$force;
}
Expand All @@ -626,7 +635,7 @@ public function getDeploymentLockIdentifier()
/**
* @param string|null $deploymentLockIdentifier
*/
private function setDeploymentLockIdentifier($deploymentLockIdentifier = null)
private function setDeploymentLockIdentifier($deploymentLockIdentifier = null): void
{
if (! is_string($deploymentLockIdentifier) || $deploymentLockIdentifier === '') {
$deploymentLockIdentifier = getenv('SURF_DEPLOYMENT_LOCK_IDENTIFIER') !== false
Expand Down

0 comments on commit 5a06bb9

Please sign in to comment.