I am using swagger to create an OpenApi documentation.
I am switching now to php attributes and phpstan in level 6 complain about missing specific array declaration, which worked totally fine as long as I was using annotations.
I give you an example:
<?php
declare(strict_types=1);
namespace AppApiDto;
use OpenApiAttributes as OA;
#[OASchema()]
class UserDto implements DtoInterface
{
#[OAProperty(description: 'Personalnummer ', type: 'string')]
public ?string $uid = null;
#[OAProperty(description: 'Name,Vorname', type: 'string')]
public ?string $username = null;
#[OAProperty(description: 'Stammhaus', type: 'string')]
public ?string $mainhouse = null;
#[OAProperty(description: 'Name, Vorname', type: 'integer')]
public ?int $companyId = null;
#[OAProperty(description: 'Symfony Rollen in der Applikation', type: 'array')]
/** @var array<string> */
public array $roles = [];
#[OAProperty(description: 'Rechte', type: 'array', items: new OAItems(type: 'string'))]
/** @var array<string> */
public array $grants = [];
#[OAProperty(description: 'Ressourcen', type: 'array')]
/** @var array<string, array<string>> */
public array $resources = [];
}
This results on phpstan analyse level 6 in the following errors:
------ ---------------------------------------------------------------------------------------------------
Line Api/Dto/UserDto.php
------ ---------------------------------------------------------------------------------------------------
26 Property AppApiDtoUserDto::$roles type has no value type specified in iterable type array.
???? See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
29 Property AppApiDtoUserDto::$grants type has no value type specified in iterable type array.
???? See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
33 Property AppApiDtoUserDto::$resources type has no value type specified in iterable type array.
???? See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
------ ---------------------------------------------------------------------------------------------------
The lines mentioned being the array definitions.
Of course I can always switch down to level 5, but this feels like giving up.
What would be the proper array annotation to make phpstan pass?
php8.2
nelmio/api-doc-bundle:4.28
phpstan:1.11
phpstan/phpdoc-parser:1.29