diff --git a/composer.json b/composer.json index 890e459..7a0be98 100644 --- a/composer.json +++ b/composer.json @@ -23,9 +23,7 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.89", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "^1.4", - "phpstan/phpstan-symfony": "^1.1", + "phpstan/phpstan": "^2.1", "sbsedv/form-bundle": "^1.7", "symfony/validator": "^7.0" }, @@ -35,9 +33,6 @@ } }, "config": { - "sort-packages": true, - "allow-plugins": { - "phpstan/extension-installer": true - } + "sort-packages": true } } diff --git a/config/definitions/event_listener.php b/config/definitions/event_listener.php index 7e4db5a..6e3b423 100644 --- a/config/definitions/event_listener.php +++ b/config/definitions/event_listener.php @@ -3,7 +3,7 @@ namespace Symfony\Component\Config\Definition\Configurator; return function (DefinitionConfigurator $definition): void { - $definition + $definition // @phpstan-ignore method.notFound ->rootNode() ->children() ->arrayNode('event_listeners') diff --git a/config/definitions/other.php b/config/definitions/other.php index 9546e48..4de380b 100644 --- a/config/definitions/other.php +++ b/config/definitions/other.php @@ -3,7 +3,7 @@ namespace Symfony\Component\Config\Definition\Configurator; return function (DefinitionConfigurator $definition): void { - $definition + $definition // @phpstan-ignore method.notFound ->rootNode() ->children() ->booleanNode('exception_normalizer')->defaultTrue()->end() diff --git a/phpstan.dist.neon b/phpstan.dist.neon new file mode 100644 index 0000000..dbb01d3 --- /dev/null +++ b/phpstan.dist.neon @@ -0,0 +1,6 @@ +parameters: + level: 9 + + paths: + - src/ + - config/ diff --git a/phpstan.neon b/phpstan.neon deleted file mode 100644 index 0eeffd0..0000000 --- a/phpstan.neon +++ /dev/null @@ -1,10 +0,0 @@ -parameters: - level: 9 - - reportUnmatchedIgnoredErrors: false - - ignoreErrors: - - identifier: missingType.iterableValue - - paths: - - src diff --git a/src/EventListener/InvalidFormExceptionEventListener.php b/src/EventListener/InvalidFormExceptionEventListener.php index 518b025..311a971 100644 --- a/src/EventListener/InvalidFormExceptionEventListener.php +++ b/src/EventListener/InvalidFormExceptionEventListener.php @@ -11,6 +11,7 @@ use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Translation\TranslatableMessage; +use Symfony\Contracts\Translation\TranslatableInterface; class InvalidFormExceptionEventListener implements EventSubscriberInterface { @@ -43,7 +44,7 @@ public function __invoke(ExceptionEvent $event): void $errors = []; - /** @var array $formError */ + /** @var array{'message': string|TranslatableInterface, 'cause'?: string, 'type'?: string, 'cause'?: string} $formError */ foreach ($formErrors as $formError) { $dto = new ApiResponseErrorDto($formError['message'], 'invalid_request_error', $formError['cause'] ?? null); diff --git a/src/Exception/AccessDeniedException.php b/src/Exception/AccessDeniedException.php index ad34767..766ef3c 100644 --- a/src/Exception/AccessDeniedException.php +++ b/src/Exception/AccessDeniedException.php @@ -7,6 +7,10 @@ class AccessDeniedException extends HttpException { + /** + * @param array $headers + * @param array $other + */ public function __construct( TranslatableInterface|string $message = 'Access denied.', ?\Throwable $previous = null, diff --git a/src/Exception/BundledHttpException.php b/src/Exception/BundledHttpException.php index fa0ccff..735e82e 100644 --- a/src/Exception/BundledHttpException.php +++ b/src/Exception/BundledHttpException.php @@ -7,7 +7,9 @@ class BundledHttpException extends HttpException { /** - * @param HttpException[] $exceptions The exceptions to bundle. + * @param HttpException[] $exceptions The exceptions to bundle. + * @param array $headers + * @param array $other */ public function __construct( private array $exceptions, diff --git a/src/Exception/DuplicateResourceException.php b/src/Exception/DuplicateResourceException.php index 31b6da6..3bf93a0 100644 --- a/src/Exception/DuplicateResourceException.php +++ b/src/Exception/DuplicateResourceException.php @@ -8,7 +8,9 @@ class DuplicateResourceException extends HttpException { /** - * @param mixed $resourceIdentifier The duplicate resource identifier. + * @param scalar|\Stringable|null $resourceIdentifier The duplicate resource identifier. + * @param array $headers + * @param array $other */ public function __construct( TranslatableInterface|string $message, @@ -24,6 +26,7 @@ public function __construct( $resourceIdentifier = (string) $resourceIdentifier; } + // @phpstan-ignore-next-line function.alreadyNarrowedType if (null !== $resourceIdentifier && !\is_scalar($resourceIdentifier)) { throw new \InvalidArgumentException('The $resourceIdentifier must have a scalar value.'); } diff --git a/src/Exception/HttpException.php b/src/Exception/HttpException.php index 1586cdb..34fba7e 100644 --- a/src/Exception/HttpException.php +++ b/src/Exception/HttpException.php @@ -14,14 +14,14 @@ class HttpException extends \Exception implements HttpExceptionInterface protected ?TranslatableInterface $translatable = null; /** - * @param TranslatableInterface|string $message The Exception message to throw. - * @param int $code [optional] The Exception code. - * @param \Throwable|null $previous [optional] The previous throwable used for the exception chaining. - * @param string|null $cause [optional] The error cause. - * @param array $headers [optional] Additional http response headers. - * @param array $other [optional] Additional error parameters. - * @param bool $isLoggable [optional] Whether the exception should be logged. - * @param string $logLevel [optional] The desired log level. + * @param TranslatableInterface|string $message The Exception message to throw. + * @param int $code [optional] The Exception code. + * @param \Throwable|null $previous [optional] The previous throwable used for the exception chaining. + * @param string|null $cause [optional] The error cause. + * @param array $headers [optional] Additional http response headers. + * @param array $other [optional] Additional error parameters. + * @param bool $isLoggable [optional] Whether the exception should be logged. + * @param string $logLevel [optional] The desired log level. */ public function __construct( TranslatableInterface|string $message, @@ -80,7 +80,9 @@ public function getType(): string } /** - * Get the extra data. + * The extra data. + * + * @return array */ public function getOther(): array { @@ -92,6 +94,9 @@ public function getStatusCode(): int return $this->code; } + /** + * @return array + */ public function getHeaders(): array { return $this->headers; diff --git a/src/Response/ApiResponseFactory.php b/src/Response/ApiResponseFactory.php index 8bd688a..b193d3a 100644 --- a/src/Response/ApiResponseFactory.php +++ b/src/Response/ApiResponseFactory.php @@ -21,9 +21,9 @@ public function __construct( /** * Create an API response. * - * @param ApiResponseDto $apiResponseDto The ApiResponse DTO object. - * @param array $headers [optional] An array of headers that will be added to the response. - * @param array $context [optional] The serialization context. + * @param ApiResponseDto $apiResponseDto The ApiResponse DTO object. + * @param array $headers [optional] An array of headers that will be added to the response. + * @param array $context [optional] The serialization context. */ public function createApiResponse(ApiResponseDto $apiResponseDto, array $headers = [], array $context = []): Response { diff --git a/src/SBSEDVResponseBundle.php b/src/SBSEDVResponseBundle.php index c728dcd..e55e140 100644 --- a/src/SBSEDVResponseBundle.php +++ b/src/SBSEDVResponseBundle.php @@ -17,6 +17,7 @@ public function configure(DefinitionConfigurator $definition): void $definition->import('../config/definitions/*.php'); } + // @phpstan-ignore-next-line missingType.iterableValue public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void { if ($config['exception_normalizer'] === true) { diff --git a/src/Serializer/Normalizer/ApiResponseErrorNormalizer.php b/src/Serializer/Normalizer/ApiResponseErrorNormalizer.php index e265542..a23936a 100644 --- a/src/Serializer/Normalizer/ApiResponseErrorNormalizer.php +++ b/src/Serializer/Normalizer/ApiResponseErrorNormalizer.php @@ -17,7 +17,10 @@ public function __construct( } /** - * @param ApiResponseErrorDto $object + * @param ApiResponseErrorDto $object + * @param array $context + * + * @return array */ public function normalize(mixed $object, ?string $format = null, array $context = []): array { @@ -43,6 +46,9 @@ public function normalize(mixed $object, ?string $format = null, array $context return $error; } + /** + * @param array $context + */ public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof ApiResponseErrorDto; diff --git a/src/Serializer/Normalizer/ApiResponseNormalizer.php b/src/Serializer/Normalizer/ApiResponseNormalizer.php index fc6086e..11aeae5 100644 --- a/src/Serializer/Normalizer/ApiResponseNormalizer.php +++ b/src/Serializer/Normalizer/ApiResponseNormalizer.php @@ -20,7 +20,10 @@ public function __construct( } /** - * @param ApiResponseDto $object + * @param ApiResponseDto $object + * @param array $context + * + * @return array */ public function normalize(mixed $object, ?string $format = null, array $context = []): array { @@ -38,6 +41,9 @@ public function normalize(mixed $object, ?string $format = null, array $context ]; } + /** + * @param array $context + */ public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof ApiResponseDto; diff --git a/src/Serializer/Normalizer/HttpExceptionNormalizer.php b/src/Serializer/Normalizer/HttpExceptionNormalizer.php index 611422f..6d44488 100644 --- a/src/Serializer/Normalizer/HttpExceptionNormalizer.php +++ b/src/Serializer/Normalizer/HttpExceptionNormalizer.php @@ -17,7 +17,10 @@ class HttpExceptionNormalizer implements NormalizerInterface, NormalizerAwareInt use NormalizerAwareTrait; /** - * @param FlattenException $object + * @param FlattenException $object + * @param array $context + * + * @return array */ public function normalize(mixed $object, ?string $format = null, array $context = []): array { @@ -44,10 +47,13 @@ public function normalize(mixed $object, ?string $format = null, array $context $response = new ApiResponseDto($message, null, $errors, $object->getStatusCode()); - // @phpstan-ignore-next-line + // @phpstan-ignore-next-line return.type return $this->normalizer->normalize($response, $format, $context); } + /** + * @param array $context + */ public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof FlattenException && isset($context['exception']) && $context['exception'] instanceof HttpException; diff --git a/src/Serializer/Normalizer/LinkCollectionNormalizer.php b/src/Serializer/Normalizer/LinkCollectionNormalizer.php index 5e04e8f..def2359 100644 --- a/src/Serializer/Normalizer/LinkCollectionNormalizer.php +++ b/src/Serializer/Normalizer/LinkCollectionNormalizer.php @@ -12,7 +12,10 @@ class LinkCollectionNormalizer implements NormalizerInterface, NormalizerAwareIn use NormalizerAwareTrait; /** - * @param LinkCollection $object + * @param LinkCollection $object + * @param array $context + * + * @return array */ public function normalize(mixed $object, ?string $format = null, array $context = []): array { @@ -25,6 +28,9 @@ public function normalize(mixed $object, ?string $format = null, array $context return $data; } + /** + * @param array $context + */ public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof LinkCollection; diff --git a/src/Serializer/Normalizer/LinkNormalizer.php b/src/Serializer/Normalizer/LinkNormalizer.php index 00505ab..1d22359 100644 --- a/src/Serializer/Normalizer/LinkNormalizer.php +++ b/src/Serializer/Normalizer/LinkNormalizer.php @@ -14,7 +14,10 @@ public function __construct( } /** - * @param Link $object + * @param Link $object + * @param array $context + * + * @return array */ public function normalize(mixed $object, ?string $format = null, array $context = []): array { @@ -27,6 +30,9 @@ public function normalize(mixed $object, ?string $format = null, array $context return [...$object->other, 'href' => $href]; } + /** + * @param array $context + */ public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof Link; diff --git a/src/Serializer/Normalizer/ProblemNormalizer.php b/src/Serializer/Normalizer/ProblemNormalizer.php index e07a015..2eb8e5a 100644 --- a/src/Serializer/Normalizer/ProblemNormalizer.php +++ b/src/Serializer/Normalizer/ProblemNormalizer.php @@ -24,7 +24,10 @@ public function __construct( } /** - * @param FlattenException $object + * @param FlattenException $object + * @param array $context + * + * @return array */ public function normalize(mixed $object, ?string $format = null, array $context = []): array { @@ -61,10 +64,13 @@ public function normalize(mixed $object, ?string $format = null, array $context $response = new ApiResponseDto($msg, null, [$error], $object->getStatusCode()); - // @phpstan-ignore-next-line + // @phpstan-ignore-next-line return.type return $this->normalizer->normalize($response, $format, $context); } + /** + * @param array $context + */ public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof FlattenException && (!($context['exception'] ?? null) instanceof HttpException);