PHPStan is not recognizing my type specification in my docblock preceeding a method.
Here’s the code:
/**
* Process (resize and save) all versions of an uploaded file
*
* @param UploadedFileInterface $file The uploaded file.
* @param-out TypedArray<int, VersionData> $versionsData
* A reference to a typed array of VersionData objects
* Paths are relative to the base photo path.
* @param-out string $error An error message if one was encountered.
*
* @return bool
*/
public function processAllVersions(UploadedFileInterface $file, TypedArray &$versionsData, string &$error): bool
I’m getting an error on the public...
line that “Method ApiHelpersImageProcessor::processAllVersions() has parameter $versionsData with generic class ApiHelpersTypedArray but does not specify its types: TKey, TValue”
TypedArray
is defined & commented like:
/**
* Implements, as much as possible, a typed array.
*
* @template TKey
* @template TValue
* @implements ArrayAccess<TKey, TValue>
* @implements Iterator<TKey, TValue>
*/
class TypedArray implements ArrayAccess, Countable, Iterator, JsonSerializable
I’ve used it elsewhere in my project, defining the key and value just fine.
I think I’m very much defining the type (int, VersionData
– VersionData
is a class in the same namespace). If I change the value type to “string”, I get downstream errors – so obviously at least part of PHPStan is reading that declaration.
What am I missing?