Repository: codeigniter4/CodeIgniter4 (PHP)

Issue:
Bug: unable to add more than one file to FileCollection constructor
### PHP Version

7.3, 7.4, 8.0, 8.1

### CodeIgniter4 Version

4.2.1

### CodeIgniter4 Installation Method

Composer (as dependency to an existing project)

### Which operating systems have you tested for this bug?

macOS, Linux

### Which server did you use?

fpm-fcgi

### Database

MariaDB 10.8

### What happened?

When I'm trying to create `FileCollection` object from 2 or more files paths (not directories), passed in the `__constructor`, only first file is added. Because in `FileCollection->add()` method uses `return $this->addFile($path);` instead of `$this->addFile($path);` that ends the execution of the `foreach` loop

### Steps to Reproduce

`$object = new FileCollection(['/path/to/file', '/path/to/other-file']);`

### Expected Output

An object containing all passed files

### Anything else?

_No response_


Discussion:
Hi @AnakinA1 ,
Do you get what you need with the following code?

```php 
use CodeIgniter\Files\FileCollection;

$files = new FileCollection();

$file= APPPATH . 'Config/Auth.php';
$otherFile = APPPATH . 'Config/AuthGroups.php';

dd($files->addFiles([$file,$otherFile]));

```


Hi, yes, but question is that inside docs mentioned that `FileCollection` allows to work with groups of files and by logic `__constructor` should provide an opportunity to add as many files/dirs as you want. And the current behavior is blocking the ability to add more than 1 file via the constructor, for no real reason
I've confirmed this bug.
I sent a PR to fix it. See #6291
Great, thank you!
This bug has only been sent a PR and has not yet been fixed.



Patch:
diff --git a/system/Files/FileCollection.php b/system/Files/FileCollection.php
index 853c15c07ae1..20b208fded43 100644
--- a/system/Files/FileCollection.php
+++ b/system/Files/FileCollection.php
@@ -178,7 +178,9 @@ public function add($paths, bool $recursive = true)
                 // Test for a directory
                 self::resolveDirectory($path);
             } catch (FileException $e) {
-                return $this->addFile($path);
+                $this->addFile($path);
+
+                continue;
             }
 
             $this->addDirectory($path, $recursive);


Test patch:
diff --git a/tests/system/Files/FileCollectionTest.php b/tests/system/Files/FileCollectionTest.php
index ced5b38873d2..7936cc2e62da 100644
--- a/tests/system/Files/FileCollectionTest.php
+++ b/tests/system/Files/FileCollectionTest.php
@@ -178,7 +178,24 @@ public function testAddStringDirectoryRecursive()
         $this->assertSame($expected, $files->get());
     }
 
-    public function testAddArray()
+    public function testAddArrayFiles()
+    {
+        $files = new FileCollection();
+
+        $expected = [
+            $this->directory . 'apple.php',
+            SUPPORTPATH . 'Files/baker/banana.php',
+        ];
+
+        $files->add([
+            $this->directory . 'apple.php',
+            SUPPORTPATH . 'Files/baker/banana.php',
+        ]);
+
+        $this->assertSame($expected, $files->get());
+    }
+
+    public function testAddArrayDirectoryAndFile()
     {
         $files = new FileCollection();
 
@@ -190,7 +207,7 @@ public function testAddArray()
         ];
 
         $files->add([
-            SUPPORTPATH . 'Files/able',
+            SUPPORTPATH . 'Files/able', // directory
             SUPPORTPATH . 'Files/baker/banana.php',
         ]);