Skip to content

Commit

Permalink
Fix some phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed Feb 17, 2022
1 parent d5d0ec1 commit 9e21451
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 32 deletions.
17 changes: 1 addition & 16 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
parameters:
ignoreErrors:
-
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 \\#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
count: 1
path: src/Task/TYPO3/CMS/AbstractCliTask.php

-
Expand Down
14 changes: 8 additions & 6 deletions src/Task/CleanupReleasesTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ public function execute(Node $node, Application $application, Deployment $deploy
$previousReleaseIdentifier = findPreviousReleaseIdentifier($deployment, $node, $application, $this->shell);
$allReleases = findAllReleases($deployment, $node, $application, $this->shell);

$removableReleases = array_map('trim', array_filter($allReleases, static function ($release) use ($currentReleaseIdentifier, $previousReleaseIdentifier): bool {
return $release !== '.' && $release !== $currentReleaseIdentifier && $release !== $previousReleaseIdentifier && $release !== 'current' && $release !== 'previous';
}));
$removableReleases = $this->extractRemovableReleases($allReleases, $currentReleaseIdentifier, $previousReleaseIdentifier);

if (isset($options['onlyRemoveReleasesOlderThan'])) {
$removeReleases = $this->removeReleasesByAge($options, $removableReleases);
Expand Down Expand Up @@ -106,13 +104,17 @@ private function removeReleasesByAge(array $options, array $removableReleases)
});
}

/**
* @return array
*/
private function removeReleasesByNumber(array $options, array $removableReleases): array
{
sort($removableReleases);
$keepReleases = $options['keepReleases'];
return array_slice($removableReleases, 0, count($removableReleases) - $keepReleases);
}

private function extractRemovableReleases(array $allReleases, ?string $currentReleaseIdentifier, string $previousReleaseIdentifier): array
{
return array_map('trim', array_filter($allReleases, static function ($release) use ($currentReleaseIdentifier, $previousReleaseIdentifier): bool {
return $release !== '.' && $release !== $currentReleaseIdentifier && $release !== $previousReleaseIdentifier && $release !== 'current' && $release !== 'previous';
}));
}
}
14 changes: 7 additions & 7 deletions src/Task/TYPO3/CMS/AbstractCliTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,13 @@ abstract class AbstractCliTask extends Task implements ShellCommandServiceAwareI

/**
* The working directory. Either local or remote, and probably in a special application root directory
*
* @var string|null
*/
protected $workingDirectory;
protected ?string $workingDirectory = null;

/**
* Localhost or deployment target node
*
* @var Node|null
*/
protected $targetNode;
protected ?Node $targetNode = null;

/**
* @return bool|mixed
Expand All @@ -53,8 +49,12 @@ protected function executeCliCommand(array $cliArguments, Node $node, CMS $appli
}
$commandPrefix .= $phpBinaryPathAndFilename . ' ';

if (!$this->targetNode instanceof Node) {
return false;
}

return $this->shell->executeOrSimulate([
'cd ' . escapeshellarg($this->workingDirectory),
'cd ' . escapeshellarg((string)$this->workingDirectory),
$commandPrefix . implode(' ', array_map('escapeshellarg', $cliArguments))
], $this->targetNode, $deployment);
}
Expand Down
12 changes: 9 additions & 3 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@
/**
* Find all releases for current application
*
* @return array[]|false|string[]
* @return string[]
*/
function findAllReleases(Deployment $deployment, Node $node, Application $application, ShellCommandService $shell)
function findAllReleases(Deployment $deployment, Node $node, Application $application, ShellCommandService $shell): array
{
$releasesPath = $application->getReleasesPath();
$allReleasesList = $shell->execute("if [ -d $releasesPath/. ]; then find $releasesPath/. -maxdepth 1 -type d -exec basename {} \; ; fi", $node, $deployment);

return preg_split('/\s+/', $allReleasesList, -1, PREG_SPLIT_NO_EMPTY);
$allReleases = preg_split('/\s+/', $allReleasesList, -1, PREG_SPLIT_NO_EMPTY);

if ($allReleases === false) {
return[];
}

return $allReleases;
}

/**
Expand Down

0 comments on commit 9e21451

Please sign in to comment.