Skip to content
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

refactor: PHPDocs FileCollection #9126

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
52 changes: 2 additions & 50 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -5977,57 +5977,15 @@
'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\\.$#',
'count' => 1,
'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\\<string, array\\<int\\|string, CodeIgniter\\\\HTTP\\\\Files\\\\UploadedFile\\>\\|CodeIgniter\\\\HTTP\\\\Files\\\\UploadedFile\\>\\|null is not subtype of native type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/HTTP/Files/FileCollection.php',
];
Expand Down Expand Up @@ -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\\.$#',
Expand Down
22 changes: 14 additions & 8 deletions system/HTTP/Files/FileCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FileCollection
* Populated the first time either files(), file(), or hasFile()
* is called.
*
* @var array|null
* @var array<string, array<int|string,UploadedFile>|UploadedFile>|null
*/
protected $files;

Expand All @@ -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<string, array<int|string,UploadedFile>|UploadedFile>|null
*/
public function all()
{
Expand Down Expand Up @@ -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<UploadedFile>|null
* @return array<int|string,UploadedFile>|null
*/
public function getFileMultiple(string $name)
{
Expand Down Expand Up @@ -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>|UploadedFile
* @param array<string, mixed> $array
*
* @return array<int|string,UploadedFile>|UploadedFile
*/
protected function createFileObject(array $array)
{
Expand Down Expand Up @@ -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, array<string, int|list<string>|string>> $data
*
* @return array<string, mixed>
*
* @see http://php.net/manual/en/reserved.variables.files.php#118294
*/
protected function fixFilesArray(array $data): array
Expand Down Expand Up @@ -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<string> $index The index sequence we are navigating down
* @param array<string, array<int|string, UploadedFile>|UploadedFile>|null $value The portion of the array to process
*
* @return list<UploadedFile>|UploadedFile|null
* @return array<int|string,UploadedFile>|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]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/system/HTTP/Files/FileCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading