Skip to content

Commit 4eefaf3

Browse files
Merge pull request #13 from cleverage/12_phpstan
Improve phpstan quality level
2 parents 5adb4df + 6364060 commit 4eefaf3

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

phpstan.neon

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
parameters:
2-
level: 6
2+
level: 10
33
paths:
44
- src
55
- tests
6-
ignoreErrors:
7-
- '#type has no value type specified in iterable type#'
8-
- '#has parameter .* with no value type specified in iterable type#'
9-
- '#has no value type specified in iterable type array#'
10-
- '#configureOptions\(\) has no return type specified.#'
11-
- '#configure\(\) has no return type specified#'
12-
- '#process\(\) has no return type specified#'
13-
- '#should return Iterator but returns Traversable#'
14-
- '#Negated boolean expression is always false#'
15-
checkGenericClassInNonGenericObjectType: false
16-
reportUnmatchedIgnoredErrors: false
17-
inferPrivatePropertyTypeFromConstructor: true
18-
treatPhpDocTypesAsCertain: false

src/Task/FileFetchTask.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use CleverAge\ProcessBundle\Model\AbstractConfigurableTask;
1717
use CleverAge\ProcessBundle\Model\IterableTaskInterface;
1818
use CleverAge\ProcessBundle\Model\ProcessState;
19-
use League\Flysystem\Filesystem;
2019
use League\Flysystem\FilesystemException;
2120
use League\Flysystem\FilesystemOperator;
2221
use Symfony\Component\DependencyInjection\ServiceLocator;
@@ -32,6 +31,9 @@ class FileFetchTask extends AbstractConfigurableTask implements IterableTaskInte
3231

3332
protected FilesystemOperator $destinationFS;
3433

34+
/**
35+
* @var array<int, string>
36+
*/
3537
protected array $matchingFiles = [];
3638

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

52-
$this->sourceFS = $this->storages->get($this->getOption($state, 'source_filesystem'));
53-
$this->destinationFS = $this->storages->get($this->getOption($state, 'destination_filesystem'));
54+
/** @var string $sourceFilesystemOption */
55+
$sourceFilesystemOption = $this->getOption($state, 'source_filesystem');
56+
$this->sourceFS = $this->storages->get($sourceFilesystemOption);
57+
/** @var string $destinationFilesystemOption */
58+
$destinationFilesystemOption = $this->getOption($state, 'destination_filesystem');
59+
$this->destinationFS = $this->storages->get($destinationFilesystemOption);
5460
}
5561

5662
/**
@@ -69,7 +75,9 @@ public function execute(ProcessState $state): void
6975
return;
7076
}
7177

72-
$this->doFileCopy($state, $file, $this->getOption($state, 'remove_source'));
78+
/** @var bool $removeSourceOption */
79+
$removeSourceOption = $this->getOption($state, 'remove_source');
80+
$this->doFileCopy($state, $file, $removeSourceOption);
7381
$state->setOutput($file);
7482
}
7583

@@ -92,16 +100,19 @@ public function next(ProcessState $state): bool
92100
*/
93101
protected function findMatchingFiles(ProcessState $state): void
94102
{
103+
/** @var ?string $filePattern */
95104
$filePattern = $this->getOption($state, 'file_pattern');
96105
if ($filePattern) {
97106
foreach ($this->sourceFS->listContents('/') as $file) {
98-
if ('file' === $file['type']
99-
&& preg_match($filePattern, (string) $file['path'])
100-
&& !\in_array($file['path'], $this->matchingFiles, true)) {
101-
$this->matchingFiles[] = $file['path'];
107+
if ('file' === $file->type()
108+
&& preg_match($filePattern, $file->path())
109+
&& !\in_array($file->path(), $this->matchingFiles, true)
110+
) {
111+
$this->matchingFiles[] = $file->path();
102112
}
103113
}
104114
} else {
115+
/** @var array<string>|string|null $input */
105116
$input = $state->getInput();
106117
if (!$input) {
107118
throw new \UnexpectedValueException('No pattern neither input provided for the Task');

src/Task/ListContentTask.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
*/
2727
class ListContentTask extends AbstractConfigurableTask implements IterableTaskInterface
2828
{
29+
/**
30+
* @var list<\League\Flysystem\StorageAttributes>|null
31+
*/
2932
protected ?array $fsContent = null;
3033

3134
/**
@@ -50,10 +53,13 @@ protected function configureOptions(OptionsResolver $resolver): void
5053
public function execute(ProcessState $state): void
5154
{
5255
if (null === $this->fsContent || null === key($this->fsContent)) {
53-
$filesystem = $this->storages->get($this->getOption($state, 'filesystem'));
54-
$pattern = $this->getOption($state, 'file_pattern');
56+
/** @var string $filesystemOption */
57+
$filesystemOption = $this->getOption($state, 'filesystem');
58+
$filesystem = $this->storages->get($filesystemOption);
59+
/** @var ?string $patternOption */
60+
$patternOption = $this->getOption($state, 'file_pattern');
5561

56-
$this->fsContent = $this->getFilteredFilesystemContents($filesystem, $pattern);
62+
$this->fsContent = $this->getFilteredFilesystemContents($filesystem, $patternOption);
5763
}
5864

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

7884
/**
85+
* @return list<\League\Flysystem\StorageAttributes>
86+
*
7987
* @throws FilesystemException
8088
*/
8189
protected function getFilteredFilesystemContents(FilesystemOperator $filesystem, ?string $pattern = null): array
8290
{
8391
$results = [];
8492
foreach ($filesystem->listContents('') as $item) {
85-
if (null === $pattern || preg_match($pattern, (string) $item['path'])) {
93+
if (null === $pattern || preg_match($pattern, $item->path())) {
8694
$results[] = $item;
8795
}
8896
}

src/Task/RemoveFileTask.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ protected function configureOptions(OptionsResolver $resolver): void
4141

4242
public function execute(ProcessState $state): void
4343
{
44-
$filesystem = $this->storages->get($this->getOption($state, 'filesystem'));
44+
/** @var string $filesystemOption */
45+
$filesystemOption = $this->getOption($state, 'filesystem');
46+
$filesystem = $this->storages->get($filesystemOption);
47+
/** @var string $filePath */
4548
$filePath = $state->getInput();
4649

4750
try {

0 commit comments

Comments
 (0)