Skip to content

Improve phpstan quality level #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
parameters:
level: 6
level: 10
paths:
- src
- tests
ignoreErrors:
- '#type has no value type specified in iterable type#'
- '#has parameter .* with no value type specified in iterable type#'
- '#has no value type specified in iterable type array#'
- '#configureOptions\(\) has no return type specified.#'
- '#configure\(\) has no return type specified#'
- '#process\(\) has no return type specified#'
- '#should return Iterator but returns Traversable#'
- '#Negated boolean expression is always false#'
checkGenericClassInNonGenericObjectType: false
reportUnmatchedIgnoredErrors: false
inferPrivatePropertyTypeFromConstructor: true
treatPhpDocTypesAsCertain: false
27 changes: 19 additions & 8 deletions src/Task/FileFetchTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use CleverAge\ProcessBundle\Model\AbstractConfigurableTask;
use CleverAge\ProcessBundle\Model\IterableTaskInterface;
use CleverAge\ProcessBundle\Model\ProcessState;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
use League\Flysystem\FilesystemOperator;
use Symfony\Component\DependencyInjection\ServiceLocator;
Expand All @@ -32,6 +31,9 @@ class FileFetchTask extends AbstractConfigurableTask implements IterableTaskInte

protected FilesystemOperator $destinationFS;

/**
* @var array<int, string>
*/
protected array $matchingFiles = [];

/**
Expand All @@ -49,8 +51,12 @@ public function initialize(ProcessState $state): void
// Configure options
parent::initialize($state);

$this->sourceFS = $this->storages->get($this->getOption($state, 'source_filesystem'));
$this->destinationFS = $this->storages->get($this->getOption($state, 'destination_filesystem'));
/** @var string $sourceFilesystemOption */
$sourceFilesystemOption = $this->getOption($state, 'source_filesystem');
$this->sourceFS = $this->storages->get($sourceFilesystemOption);
/** @var string $destinationFilesystemOption */
$destinationFilesystemOption = $this->getOption($state, 'destination_filesystem');
$this->destinationFS = $this->storages->get($destinationFilesystemOption);
}

/**
Expand All @@ -69,7 +75,9 @@ public function execute(ProcessState $state): void
return;
}

$this->doFileCopy($state, $file, $this->getOption($state, 'remove_source'));
/** @var bool $removeSourceOption */
$removeSourceOption = $this->getOption($state, 'remove_source');
$this->doFileCopy($state, $file, $removeSourceOption);
$state->setOutput($file);
}

Expand All @@ -92,16 +100,19 @@ public function next(ProcessState $state): bool
*/
protected function findMatchingFiles(ProcessState $state): void
{
/** @var ?string $filePattern */
$filePattern = $this->getOption($state, 'file_pattern');
if ($filePattern) {
foreach ($this->sourceFS->listContents('/') as $file) {
if ('file' === $file['type']
&& preg_match($filePattern, (string) $file['path'])
&& !\in_array($file['path'], $this->matchingFiles, true)) {
$this->matchingFiles[] = $file['path'];
if ('file' === $file->type()
&& preg_match($filePattern, $file->path())
&& !\in_array($file->path(), $this->matchingFiles, true)
) {
$this->matchingFiles[] = $file->path();
}
}
} else {
/** @var array<string>|string|null $input */
$input = $state->getInput();
if (!$input) {
throw new \UnexpectedValueException('No pattern neither input provided for the Task');
Expand Down
16 changes: 12 additions & 4 deletions src/Task/ListContentTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
*/
class ListContentTask extends AbstractConfigurableTask implements IterableTaskInterface
{
/**
* @var list<\League\Flysystem\StorageAttributes>|null
*/
protected ?array $fsContent = null;

/**
Expand All @@ -50,10 +53,13 @@ protected function configureOptions(OptionsResolver $resolver): void
public function execute(ProcessState $state): void
{
if (null === $this->fsContent || null === key($this->fsContent)) {
$filesystem = $this->storages->get($this->getOption($state, 'filesystem'));
$pattern = $this->getOption($state, 'file_pattern');
/** @var string $filesystemOption */
$filesystemOption = $this->getOption($state, 'filesystem');
$filesystem = $this->storages->get($filesystemOption);
/** @var ?string $patternOption */
$patternOption = $this->getOption($state, 'file_pattern');

$this->fsContent = $this->getFilteredFilesystemContents($filesystem, $pattern);
$this->fsContent = $this->getFilteredFilesystemContents($filesystem, $patternOption);
}

if (null === key($this->fsContent)) {
Expand All @@ -76,13 +82,15 @@ public function next(ProcessState $state): bool
}

/**
* @return list<\League\Flysystem\StorageAttributes>
*
* @throws FilesystemException
*/
protected function getFilteredFilesystemContents(FilesystemOperator $filesystem, ?string $pattern = null): array
{
$results = [];
foreach ($filesystem->listContents('') as $item) {
if (null === $pattern || preg_match($pattern, (string) $item['path'])) {
if (null === $pattern || preg_match($pattern, $item->path())) {
$results[] = $item;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Task/RemoveFileTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ protected function configureOptions(OptionsResolver $resolver): void

public function execute(ProcessState $state): void
{
$filesystem = $this->storages->get($this->getOption($state, 'filesystem'));
/** @var string $filesystemOption */
$filesystemOption = $this->getOption($state, 'filesystem');
$filesystem = $this->storages->get($filesystemOption);
/** @var string $filePath */
$filePath = $state->getInput();

try {
Expand Down
Loading