diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 1ba751d7c11d..e8e1ea1faead 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -5977,42 +5977,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/HTTP/Exceptions/RedirectException.php', ]; -$ignoreErrors[] = [ - // identifier: function.alreadyNarrowedType - 'message' => '#^Call to function is_array\\(\\) with array will always evaluate to true\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/HTTP/Files/FileCollection.php', -]; -$ignoreErrors[] = [ - // identifier: missingType.iterableValue - 'message' => '#^Method CodeIgniter\\\\HTTP\\\\Files\\\\FileCollection\\:\\:all\\(\\) return type has no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/HTTP/Files/FileCollection.php', -]; -$ignoreErrors[] = [ - // identifier: missingType.iterableValue - 'message' => '#^Method CodeIgniter\\\\HTTP\\\\Files\\\\FileCollection\\:\\:createFileObject\\(\\) has parameter \\$array with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/HTTP/Files/FileCollection.php', -]; -$ignoreErrors[] = [ - // identifier: missingType.iterableValue - 'message' => '#^Method CodeIgniter\\\\HTTP\\\\Files\\\\FileCollection\\:\\:fixFilesArray\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/HTTP/Files/FileCollection.php', -]; -$ignoreErrors[] = [ - // identifier: missingType.iterableValue - 'message' => '#^Method CodeIgniter\\\\HTTP\\\\Files\\\\FileCollection\\:\\:fixFilesArray\\(\\) return type has no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/HTTP/Files/FileCollection.php', -]; -$ignoreErrors[] = [ - // identifier: missingType.iterableValue - 'message' => '#^Method CodeIgniter\\\\HTTP\\\\Files\\\\FileCollection\\:\\:getValueDotNotationSyntax\\(\\) has parameter \\$index with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/HTTP/Files/FileCollection.php', -]; $ignoreErrors[] = [ // identifier: missingType.iterableValue 'message' => '#^Method CodeIgniter\\\\HTTP\\\\Files\\\\FileCollection\\:\\:getValueDotNotationSyntax\\(\\) has parameter \\$value with no value type specified in iterable type array\\.$#', @@ -6020,14 +5984,8 @@ 'path' => __DIR__ . '/system/HTTP/Files/FileCollection.php', ]; $ignoreErrors[] = [ - // identifier: booleanAnd.rightNotBoolean - 'message' => '#^Only booleans are allowed in &&, array given on the right side\\.$#', - 'count' => 2, - 'path' => __DIR__ . '/system/HTTP/Files/FileCollection.php', -]; -$ignoreErrors[] = [ - // identifier: missingType.iterableValue - 'message' => '#^Property CodeIgniter\\\\HTTP\\\\Files\\\\FileCollection\\:\\:\\$files type has no value type specified in iterable type array\\.$#', + // identifier: parameter.phpDocType + 'message' => '#^PHPDoc tag @param for parameter \\$value with type array\\\\|CodeIgniter\\\\HTTP\\\\Files\\\\UploadedFile\\>\\|null is not subtype of native type array\\.$#', 'count' => 1, 'path' => __DIR__ . '/system/HTTP/Files/FileCollection.php', ]; @@ -13957,12 +13915,6 @@ 'count' => 1, 'path' => __DIR__ . '/tests/system/HTTP/DownloadResponseTest.php', ]; -$ignoreErrors[] = [ - // identifier: method.nameCase - 'message' => '#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNull\\(\\) with incorrect case\\: AssertNull$#', - 'count' => 1, - 'path' => __DIR__ . '/tests/system/HTTP/Files/FileCollectionTest.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Function CodeIgniter\\\\HTTP\\\\Files\\\\is_uploaded_file\\(\\) has no return type specified\\.$#', diff --git a/system/HTTP/Files/FileCollection.php b/system/HTTP/Files/FileCollection.php index 079d5e73114f..cc9e3af90730 100644 --- a/system/HTTP/Files/FileCollection.php +++ b/system/HTTP/Files/FileCollection.php @@ -31,7 +31,7 @@ class FileCollection * Populated the first time either files(), file(), or hasFile() * is called. * - * @var array|null + * @var array|UploadedFile>|null */ protected $files; @@ -40,7 +40,7 @@ class FileCollection * Each element in the array will be an instance of UploadedFile. * The key of each element will be the client filename. * - * @return array|null + * @return array|UploadedFile>|null */ public function all() { @@ -79,7 +79,7 @@ public function getFile(string $name) /** * Verify if a file exist in the collection of uploaded files and is have been uploaded with multiple option. * - * @return list|null + * @return array|null */ public function getFileMultiple(string $name) { @@ -165,7 +165,9 @@ protected function populateFiles() * Given a file array, will create UploadedFile instances. Will * loop over an array and create objects for each. * - * @return list|UploadedFile + * @param array $array + * + * @return array|UploadedFile */ protected function createFileObject(array $array) { @@ -200,6 +202,10 @@ protected function createFileObject(array $array) * Thanks to Jack Sleight on the PHP Manual page for the basis * of this method. * + * @param array|string>> $data + * + * @return array + * * @see http://php.net/manual/en/reserved.variables.files.php#118294 */ protected function fixFilesArray(array $data): array @@ -244,16 +250,16 @@ protected function fixFilesArray(array $data): array /** * Navigate through an array looking for a particular index * - * @param array $index The index sequence we are navigating down - * @param array $value The portion of the array to process + * @param list $index The index sequence we are navigating down + * @param array|UploadedFile>|null $value The portion of the array to process * - * @return list|UploadedFile|null + * @return array|UploadedFile|null */ protected function getValueDotNotationSyntax(array $index, array $value) { $currentIndex = array_shift($index); - if (isset($currentIndex) && is_array($index) && $index && is_array($value[$currentIndex]) && $value[$currentIndex]) { + if (isset($currentIndex) && $index !== [] && is_array($value[$currentIndex]) && isset($value[$currentIndex])) { return $this->getValueDotNotationSyntax($index, $value[$currentIndex]); } diff --git a/tests/system/HTTP/Files/FileCollectionTest.php b/tests/system/HTTP/Files/FileCollectionTest.php index a0d7bb1de771..3e502f7afec4 100644 --- a/tests/system/HTTP/Files/FileCollectionTest.php +++ b/tests/system/HTTP/Files/FileCollectionTest.php @@ -524,7 +524,7 @@ public function testFileNoExistSingleFile(): void $collection = new FileCollection(); $file = $collection->getFile('fileuser'); - $this->AssertNull($file); + $this->assertNull($file); } public function testFileReturnValidMultipleFiles(): void