From 2341a977540482dc84c98bfe5c34b29790746f21 Mon Sep 17 00:00:00 2001
From: Nicolas Joubert <njoubert@clever-age.com>
Date: Fri, 13 Dec 2024 11:52:34 +0100
Subject: [PATCH 1/2] #12 Remove all phpstan ignoreErrors. Fix code.

---
 phpstan.neon                 | 13 -------------
 src/Task/FileFetchTask.php   |  4 +++-
 src/Task/ListContentTask.php |  5 +++++
 3 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/phpstan.neon b/phpstan.neon
index 30e9572..63aadba 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -3,16 +3,3 @@ parameters:
     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
diff --git a/src/Task/FileFetchTask.php b/src/Task/FileFetchTask.php
index 0ea81a2..9652580 100644
--- a/src/Task/FileFetchTask.php
+++ b/src/Task/FileFetchTask.php
@@ -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;
@@ -32,6 +31,9 @@ class FileFetchTask extends AbstractConfigurableTask implements IterableTaskInte
 
     protected FilesystemOperator $destinationFS;
 
+    /**
+     * @var array<int, string>
+     */
     protected array $matchingFiles = [];
 
     /**
diff --git a/src/Task/ListContentTask.php b/src/Task/ListContentTask.php
index 8c394cd..758512b 100644
--- a/src/Task/ListContentTask.php
+++ b/src/Task/ListContentTask.php
@@ -26,6 +26,9 @@
  */
 class ListContentTask extends AbstractConfigurableTask implements IterableTaskInterface
 {
+    /**
+     * @var list<\League\Flysystem\StorageAttributes>|null
+     */
     protected ?array $fsContent = null;
 
     /**
@@ -76,6 +79,8 @@ public function next(ProcessState $state): bool
     }
 
     /**
+     * @return list<\League\Flysystem\StorageAttributes>
+     *
      * @throws FilesystemException
      */
     protected function getFilteredFilesystemContents(FilesystemOperator $filesystem, ?string $pattern = null): array

From 63640606b349dcaa1a83eabbd036313200a002c3 Mon Sep 17 00:00:00 2001
From: Nicolas Joubert <njoubert@clever-age.com>
Date: Fri, 13 Dec 2024 14:18:46 +0100
Subject: [PATCH 2/2] #12 Apply phpstan level 10

---
 phpstan.neon                 |  2 +-
 src/Task/FileFetchTask.php   | 23 ++++++++++++++++-------
 src/Task/ListContentTask.php | 11 +++++++----
 src/Task/RemoveFileTask.php  |  5 ++++-
 4 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/phpstan.neon b/phpstan.neon
index 63aadba..e9a9e7e 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -1,5 +1,5 @@
 parameters:
-    level: 6
+    level: 10
     paths:
         - src
         - tests
diff --git a/src/Task/FileFetchTask.php b/src/Task/FileFetchTask.php
index 9652580..b915e67 100644
--- a/src/Task/FileFetchTask.php
+++ b/src/Task/FileFetchTask.php
@@ -51,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);
     }
 
     /**
@@ -71,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);
     }
 
@@ -94,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');
diff --git a/src/Task/ListContentTask.php b/src/Task/ListContentTask.php
index 758512b..c804135 100644
--- a/src/Task/ListContentTask.php
+++ b/src/Task/ListContentTask.php
@@ -53,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)) {
@@ -87,7 +90,7 @@ protected function getFilteredFilesystemContents(FilesystemOperator $filesystem,
     {
         $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;
             }
         }
diff --git a/src/Task/RemoveFileTask.php b/src/Task/RemoveFileTask.php
index 5bb0af9..2f195f4 100644
--- a/src/Task/RemoveFileTask.php
+++ b/src/Task/RemoveFileTask.php
@@ -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 {