diff --git a/phpstan.neon.dist b/phpstan.neon.dist index dbfe3153b84..51fdb5c3421 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -105,11 +105,6 @@ parameters: identifier: function.alreadyNarrowedType - identifier: property.unusedType - - - identifier: return.unusedType - - - path: tests/ - identifier: void.pure - identifier: varTag.nativeType - diff --git a/src/Doctrine/Odm/Filter/DateFilter.php b/src/Doctrine/Odm/Filter/DateFilter.php index 749af9bfac3..b2cfe80a0f5 100644 --- a/src/Doctrine/Odm/Filter/DateFilter.php +++ b/src/Doctrine/Odm/Filter/DateFilter.php @@ -251,7 +251,7 @@ public function getSchema(Parameter $parameter): array return ['type' => 'string', 'format' => 'date']; } - public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null + public function getOpenApiParameters(Parameter $parameter): array { $in = $parameter instanceof QueryParameter ? 'query' : 'header'; $key = $parameter->getKey(); diff --git a/src/Doctrine/Odm/Filter/RangeFilter.php b/src/Doctrine/Odm/Filter/RangeFilter.php index 6274ccb4499..7f1574f193f 100644 --- a/src/Doctrine/Odm/Filter/RangeFilter.php +++ b/src/Doctrine/Odm/Filter/RangeFilter.php @@ -209,7 +209,7 @@ protected function addMatch(Builder $aggregationBuilder, string $field, string $ } } - public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null + public function getOpenApiParameters(Parameter $parameter): array { $in = $parameter instanceof QueryParameter ? 'query' : 'header'; $key = $parameter->getKey(); diff --git a/src/Doctrine/Orm/Filter/DateFilter.php b/src/Doctrine/Orm/Filter/DateFilter.php index 6559abade58..df038ea3103 100644 --- a/src/Doctrine/Orm/Filter/DateFilter.php +++ b/src/Doctrine/Orm/Filter/DateFilter.php @@ -283,7 +283,7 @@ public function getSchema(Parameter $parameter): array return ['type' => 'string', 'format' => 'date']; } - public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null + public function getOpenApiParameters(Parameter $parameter): array { $in = $parameter instanceof QueryParameter ? 'query' : 'header'; $key = $parameter->getKey(); diff --git a/src/Doctrine/Orm/Filter/RangeFilter.php b/src/Doctrine/Orm/Filter/RangeFilter.php index ae052fa5769..6a1ec3ae612 100644 --- a/src/Doctrine/Orm/Filter/RangeFilter.php +++ b/src/Doctrine/Orm/Filter/RangeFilter.php @@ -227,7 +227,7 @@ protected function addWhere(QueryBuilder $queryBuilder, QueryNameGeneratorInterf } } - public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null + public function getOpenApiParameters(Parameter $parameter): array { $in = $parameter instanceof QueryParameter ? 'query' : 'header'; $key = $parameter->getKey(); diff --git a/src/GraphQl/Metadata/RuntimeOperationMetadataFactory.php b/src/GraphQl/Metadata/RuntimeOperationMetadataFactory.php index 46fef884fec..6b280da24cf 100644 --- a/src/GraphQl/Metadata/RuntimeOperationMetadataFactory.php +++ b/src/GraphQl/Metadata/RuntimeOperationMetadataFactory.php @@ -30,7 +30,7 @@ public function __construct(private readonly ResourceMetadataCollectionFactoryIn { } - public function create(string $uriTemplate, array $context = []): ?Operation + public function create(string $uriTemplate, array $context = []): Operation { try { $parameters = $this->router->match($uriTemplate); diff --git a/src/GraphQl/Serializer/ObjectNormalizer.php b/src/GraphQl/Serializer/ObjectNormalizer.php index 18f2716eebd..40c93cd2d71 100644 --- a/src/GraphQl/Serializer/ObjectNormalizer.php +++ b/src/GraphQl/Serializer/ObjectNormalizer.php @@ -53,7 +53,7 @@ public function getSupportedTypes($format): array * * @throws UnexpectedValueException */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + public function normalize(mixed $object, ?string $format = null, array $context = []): array { if (isset($context['api_resource'])) { $originalResource = $context['api_resource']; diff --git a/src/GraphQl/Type/TypeConverter.php b/src/GraphQl/Type/TypeConverter.php index 4babbb2e16c..83b82990825 100644 --- a/src/GraphQl/Type/TypeConverter.php +++ b/src/GraphQl/Type/TypeConverter.php @@ -119,7 +119,7 @@ public function convertPhpType(Type $type, bool $input, Operation $rootOperation /** * {@inheritdoc} */ - public function resolveType(string $type): ?GraphQLType + public function resolveType(string $type): GraphQLType { try { $astTypeNode = Parser::parseType($type); diff --git a/src/Hydra/Serializer/DocumentationNormalizer.php b/src/Hydra/Serializer/DocumentationNormalizer.php index 028f7e6ee9e..ad9edeb18c0 100644 --- a/src/Hydra/Serializer/DocumentationNormalizer.php +++ b/src/Hydra/Serializer/DocumentationNormalizer.php @@ -67,7 +67,7 @@ public function __construct( /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + public function normalize(mixed $object, ?string $format = null, array $context = []): array { $classes = []; $entrypointProperties = []; diff --git a/src/JsonApi/Filter/SparseFieldset.php b/src/JsonApi/Filter/SparseFieldset.php index 0c30f9540be..b937ea1ae73 100644 --- a/src/JsonApi/Filter/SparseFieldset.php +++ b/src/JsonApi/Filter/SparseFieldset.php @@ -33,7 +33,7 @@ public function getSchema(MetadataParameter $parameter): array ]; } - public function getOpenApiParameters(MetadataParameter $parameter): Parameter|array|null + public function getOpenApiParameters(MetadataParameter $parameter): Parameter { return new Parameter( name: ($k = $parameter->getKey()).'[]', diff --git a/src/JsonApi/Serializer/EntrypointNormalizer.php b/src/JsonApi/Serializer/EntrypointNormalizer.php index 7d6dd6ab95f..f49411d766a 100644 --- a/src/JsonApi/Serializer/EntrypointNormalizer.php +++ b/src/JsonApi/Serializer/EntrypointNormalizer.php @@ -39,7 +39,7 @@ public function __construct(private readonly ResourceMetadataCollectionFactoryIn /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + public function normalize(mixed $object, ?string $format = null, array $context = []): array { $entrypoint = ['links' => ['self' => $this->urlGenerator->generate('api_entrypoint', [], UrlGeneratorInterface::ABS_URL)]]; diff --git a/src/JsonSchema/Metadata/Property/Factory/SchemaPropertyMetadataFactory.php b/src/JsonSchema/Metadata/Property/Factory/SchemaPropertyMetadataFactory.php index ecd549b56ad..75450254f8f 100644 --- a/src/JsonSchema/Metadata/Property/Factory/SchemaPropertyMetadataFactory.php +++ b/src/JsonSchema/Metadata/Property/Factory/SchemaPropertyMetadataFactory.php @@ -62,7 +62,7 @@ public function create(string $resourceClass, string $property, array $options = } } - $extraProperties = $propertyMetadata->getExtraProperties() ?? []; + $extraProperties = $propertyMetadata->getExtraProperties(); // see AttributePropertyMetadataFactory if (true === ($extraProperties[self::JSON_SCHEMA_USER_DEFINED] ?? false)) { // schema seems to have been declared by the user: do not override nor complete user value diff --git a/src/JsonSchema/SchemaFactory.php b/src/JsonSchema/SchemaFactory.php index a92dbab361f..25425e82ff9 100644 --- a/src/JsonSchema/SchemaFactory.php +++ b/src/JsonSchema/SchemaFactory.php @@ -176,7 +176,7 @@ private function buildLegacyPropertySchema(Schema $schema, string $definitionNam unset($propertySchema['type']); } - $extraProperties = $propertyMetadata->getExtraProperties() ?? []; + $extraProperties = $propertyMetadata->getExtraProperties(); // see AttributePropertyMetadataFactory if (true === ($extraProperties[SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED] ?? false)) { // schema seems to have been declared by the user: do not override nor complete user value @@ -295,7 +295,7 @@ private function buildPropertySchema(Schema $schema, string $definitionName, str $additionalPropertySchema ?? [] ); - $extraProperties = $propertyMetadata->getExtraProperties() ?? []; + $extraProperties = $propertyMetadata->getExtraProperties(); // see AttributePropertyMetadataFactory if (true === ($extraProperties[SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED] ?? false)) { // schema seems to have been declared by the user: do not override nor complete user value diff --git a/src/Laravel/Eloquent/Metadata/Factory/Property/EloquentAttributePropertyMetadataFactory.php b/src/Laravel/Eloquent/Metadata/Factory/Property/EloquentAttributePropertyMetadataFactory.php index 439ef2db49b..51ddb890dd9 100644 --- a/src/Laravel/Eloquent/Metadata/Factory/Property/EloquentAttributePropertyMetadataFactory.php +++ b/src/Laravel/Eloquent/Metadata/Factory/Property/EloquentAttributePropertyMetadataFactory.php @@ -79,7 +79,7 @@ private function handleUserDefinedSchema(ApiProperty $propertyMetadata): ApiProp // can't know later if the schema has been defined by the user or by API Platform // store extra key to make this difference if (null !== $propertyMetadata->getSchema()) { - $extraProperties = $propertyMetadata->getExtraProperties() ?? []; + $extraProperties = $propertyMetadata->getExtraProperties(); $propertyMetadata = $propertyMetadata->withExtraProperties([SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED => true] + $extraProperties); } diff --git a/src/Metadata/ApiProperty.php b/src/Metadata/ApiProperty.php index d9bf25c80f2..632e5c077fe 100644 --- a/src/Metadata/ApiProperty.php +++ b/src/Metadata/ApiProperty.php @@ -572,7 +572,7 @@ public function isInitializable(): ?bool return $this->initializable; } - public function getExtraProperties(): ?array + public function getExtraProperties(): array { return $this->extraProperties; } diff --git a/src/Metadata/Property/Factory/AttributePropertyMetadataFactory.php b/src/Metadata/Property/Factory/AttributePropertyMetadataFactory.php index cb7770df9c6..c1fe1a9942d 100644 --- a/src/Metadata/Property/Factory/AttributePropertyMetadataFactory.php +++ b/src/Metadata/Property/Factory/AttributePropertyMetadataFactory.php @@ -150,7 +150,7 @@ private function handleUserDefinedSchema(ApiProperty $propertyMetadata): ApiProp // can't know later if the schema has been defined by the user or by API Platform // store extra key to make this difference if (null !== $propertyMetadata->getSchema()) { - $extraProperties = $propertyMetadata->getExtraProperties() ?? []; + $extraProperties = $propertyMetadata->getExtraProperties(); $propertyMetadata = $propertyMetadata->withExtraProperties([SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED => true] + $extraProperties); } diff --git a/src/Metadata/Property/Factory/ExtractorPropertyMetadataFactory.php b/src/Metadata/Property/Factory/ExtractorPropertyMetadataFactory.php index 8c81a3c0ba4..e8e13f2256a 100644 --- a/src/Metadata/Property/Factory/ExtractorPropertyMetadataFactory.php +++ b/src/Metadata/Property/Factory/ExtractorPropertyMetadataFactory.php @@ -133,7 +133,7 @@ private function handleUserDefinedSchema(ApiProperty $propertyMetadata): ApiProp // can't know later if the schema has been defined by the user or by API Platform // store extra key to make this difference if (null !== $propertyMetadata->getSchema()) { - $extraProperties = $propertyMetadata->getExtraProperties() ?? []; + $extraProperties = $propertyMetadata->getExtraProperties(); $propertyMetadata = $propertyMetadata->withExtraProperties([SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED => true] + $extraProperties); } diff --git a/src/OpenApi/Serializer/ApiGatewayNormalizer.php b/src/OpenApi/Serializer/ApiGatewayNormalizer.php index aaea891adca..534b05e731b 100644 --- a/src/OpenApi/Serializer/ApiGatewayNormalizer.php +++ b/src/OpenApi/Serializer/ApiGatewayNormalizer.php @@ -42,7 +42,7 @@ public function __construct(private readonly NormalizerInterface $documentationN * * @throws UnexpectedValueException */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + public function normalize(mixed $object, ?string $format = null, array $context = []): array { $data = $this->documentationNormalizer->normalize($object, $format, $context); if (!\is_array($data)) { diff --git a/src/Serializer/AbstractItemNormalizer.php b/src/Serializer/AbstractItemNormalizer.php index 796f7011419..150bbcfdde2 100644 --- a/src/Serializer/AbstractItemNormalizer.php +++ b/src/Serializer/AbstractItemNormalizer.php @@ -275,7 +275,7 @@ public function denormalize(mixed $data, string $class, ?string $format = null, foreach (array_keys($data) as $attribute) { $attribute = $this->nameConverter ? $this->nameConverter->denormalize((string) $attribute) : $attribute; $propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $attribute, $options); - $attributeExtraProperties = $propertyMetadata->getExtraProperties() ?? []; + $attributeExtraProperties = $propertyMetadata->getExtraProperties(); $throwOnPropertyAccessDenied = $attributeExtraProperties['throw_on_access_denied'] ?? $throwOnAccessDenied; if (!\in_array($attribute, $propertyNames, true)) { continue; diff --git a/src/Serializer/Filter/PropertyFilter.php b/src/Serializer/Filter/PropertyFilter.php index 188dba648e2..c0ea9a2461e 100644 --- a/src/Serializer/Filter/PropertyFilter.php +++ b/src/Serializer/Filter/PropertyFilter.php @@ -277,7 +277,7 @@ public function getSchema(MetadataParameter $parameter): array ]; } - public function getOpenApiParameters(MetadataParameter $parameter): Parameter|array|null + public function getOpenApiParameters(MetadataParameter $parameter): Parameter { $example = \sprintf( '%1$s[]={propertyName}&%1$s[]={anotherPropertyName}', diff --git a/src/State/Exception/ParameterNotSupportedException.php b/src/State/Exception/ParameterNotSupportedException.php index 1f0dcd5d58f..f3d149c825e 100644 --- a/src/State/Exception/ParameterNotSupportedException.php +++ b/src/State/Exception/ParameterNotSupportedException.php @@ -33,17 +33,17 @@ public function getTitle(): ?string return $this->message; } - public function getStatus(): ?int + public function getStatus(): int { return 400; } - public function getDetail(): ?string + public function getDetail(): string { return \sprintf('Parameter "%s" not supported', $this->parameter); } - public function getInstance(): ?string + public function getInstance(): string { return $this->parameter; } diff --git a/src/State/Provider/BackedEnumProvider.php b/src/State/Provider/BackedEnumProvider.php index e973be62362..71769ee3bd6 100644 --- a/src/State/Provider/BackedEnumProvider.php +++ b/src/State/Provider/BackedEnumProvider.php @@ -21,7 +21,7 @@ final class BackedEnumProvider implements ProviderInterface { - public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null + public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array { $resourceClass = $operation->getClass(); if (!$resourceClass || !is_a($resourceClass, \BackedEnum::class, true)) { diff --git a/src/State/Tests/ParameterProviderTest.php b/src/State/Tests/ParameterProviderTest.php index 97791d9f670..5f649da2827 100644 --- a/src/State/Tests/ParameterProviderTest.php +++ b/src/State/Tests/ParameterProviderTest.php @@ -34,7 +34,7 @@ public function get(string $id) { if ('test' === $id) { return new class implements ParameterProviderInterface { - public function provide(Parameter $parameter, array $parameters = [], array $context = []): ?Operation + public function provide(Parameter $parameter, array $parameters = [], array $context = []): Operation { return new Get(name: 'ok'); } diff --git a/src/Symfony/Routing/IriConverter.php b/src/Symfony/Routing/IriConverter.php index 936a0fc3135..5570156ea5c 100644 --- a/src/Symfony/Routing/IriConverter.php +++ b/src/Symfony/Routing/IriConverter.php @@ -113,7 +113,7 @@ public function getResourceFromIri(string $iri, array $context = [], ?Operation /** * {@inheritdoc} */ - public function getIriFromResource(object|string $resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, ?Operation $operation = null, array $context = []): ?string + public function getIriFromResource(object|string $resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, ?Operation $operation = null, array $context = []): string { $resourceClass = $context['force_resource_class'] ?? (\is_string($resource) ? $resource : $this->getObjectClass($resource)); diff --git a/src/Symfony/Routing/SkolemIriConverter.php b/src/Symfony/Routing/SkolemIriConverter.php index d8b21061bae..5ed331a5f3f 100644 --- a/src/Symfony/Routing/SkolemIriConverter.php +++ b/src/Symfony/Routing/SkolemIriConverter.php @@ -49,7 +49,7 @@ public function getResourceFromIri(string $iri, array $context = [], ?Operation /** * {@inheritdoc} */ - public function getIriFromResource(object|string $resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, ?Operation $operation = null, array $context = []): ?string + public function getIriFromResource(object|string $resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, ?Operation $operation = null, array $context = []): string { $referenceType = $operation ? ($operation->getUrlGenerationStrategy() ?? $referenceType) : $referenceType; if (($isObject = \is_object($resource)) && $this->objectHashMap->contains($resource)) { diff --git a/src/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaCollectionRestriction.php b/src/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaCollectionRestriction.php index ed81909a382..bfb15d0a084 100644 --- a/src/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaCollectionRestriction.php +++ b/src/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaCollectionRestriction.php @@ -76,7 +76,7 @@ private function mergeConstraintRestrictions(Required|Optional $constraint, ApiP foreach ($nestedConstraints as $nestedConstraint) { foreach ($this->restrictionsMetadata as $restrictionMetadata) { - if ($restrictionMetadata->supports($nestedConstraint, $propertyMetadata->withExtraProperties(($propertyMetadata->getExtraProperties() ?? []) + ['nested_schema' => true])) && !empty($nestedConstraintRestriction = $restrictionMetadata->create($nestedConstraint, $propertyMetadata))) { + if ($restrictionMetadata->supports($nestedConstraint, $propertyMetadata->withExtraProperties($propertyMetadata->getExtraProperties() + ['nested_schema' => true])) && !empty($nestedConstraintRestriction = $restrictionMetadata->create($nestedConstraint, $propertyMetadata))) { $propertyRestrictions[] = $nestedConstraintRestriction; } } diff --git a/src/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactory.php b/src/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactory.php index 5aba1bb66da..077eeddeee2 100644 --- a/src/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactory.php +++ b/src/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactory.php @@ -94,7 +94,7 @@ public function create(string $resourceClass, string $property, array $options = { $propertyMetadata = $this->decorated->create($resourceClass, $property, $options); - $extraProperties = $propertyMetadata->getExtraProperties() ?? []; + $extraProperties = $propertyMetadata->getExtraProperties(); // see AttributePropertyMetadataFactory if (true === ($extraProperties[SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED] ?? false)) { // schema seems to have been declared by the user: do not override nor complete user value diff --git a/tests/Fixtures/TestBundle/HttpCache/TagCollectorCustom.php b/tests/Fixtures/TestBundle/HttpCache/TagCollectorCustom.php index 19d1947e4c9..2ad32344c8e 100644 --- a/tests/Fixtures/TestBundle/HttpCache/TagCollectorCustom.php +++ b/tests/Fixtures/TestBundle/HttpCache/TagCollectorCustom.php @@ -69,7 +69,7 @@ public function collect(array $context = []): void $this->addCacheTagForResource($context, $iri); } - private function addCacheTagForResource(array $context, string $iri): void + private function addCacheTagForResource(array &$context, string $iri): void { $context['resources'][$iri] = $iri; } diff --git a/tests/Fixtures/TestBundle/HttpCache/TagCollectorDefault.php b/tests/Fixtures/TestBundle/HttpCache/TagCollectorDefault.php index 9ffae4956be..2dc472c180f 100644 --- a/tests/Fixtures/TestBundle/HttpCache/TagCollectorDefault.php +++ b/tests/Fixtures/TestBundle/HttpCache/TagCollectorDefault.php @@ -29,7 +29,7 @@ public function collect(array $context = []): void } } - private function addResourceToContext(array $context): void + private function addResourceToContext(array &$context): void { $iri = $context['iri']; diff --git a/tests/Fixtures/TestBundle/Serializer/ErrorNormalizer.php b/tests/Fixtures/TestBundle/Serializer/ErrorNormalizer.php index 54fd697b1dc..cbefe3af649 100644 --- a/tests/Fixtures/TestBundle/Serializer/ErrorNormalizer.php +++ b/tests/Fixtures/TestBundle/Serializer/ErrorNormalizer.php @@ -22,7 +22,7 @@ public function __construct(private readonly NormalizerInterface $decorated) { } - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject + public function normalize(mixed $object, ?string $format = null, array $context = []): array|\ArrayObject { $a = $this->decorated->normalize($object, $format, $context); $a['hello'] = 'world'; diff --git a/tests/Fixtures/TestBundle/Serializer/Normalizer/OverrideDocumentationNormalizer.php b/tests/Fixtures/TestBundle/Serializer/Normalizer/OverrideDocumentationNormalizer.php index 542171905dd..3099c6cb89c 100644 --- a/tests/Fixtures/TestBundle/Serializer/Normalizer/OverrideDocumentationNormalizer.php +++ b/tests/Fixtures/TestBundle/Serializer/Normalizer/OverrideDocumentationNormalizer.php @@ -31,7 +31,7 @@ public function __construct(private readonly NormalizerInterface $documentationN * * @throws ExceptionInterface */ - public function normalize($object, $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null + public function normalize($object, $format = null, array $context = []): array { $data = $this->documentationNormalizer->normalize($object, $format, $context); if (!\is_array($data)) {