Skip to content

Commit bc4a5dc

Browse files
chore: solve some phpstan issues
1 parent b48501a commit bc4a5dc

33 files changed

+35
-42
lines changed

phpstan.neon.dist

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@ parameters:
105105
identifier: function.alreadyNarrowedType
106106
-
107107
identifier: property.unusedType
108-
-
109-
identifier: return.unusedType
110-
-
111-
path: tests/
112-
identifier: void.pure
113108
-
114109
identifier: varTag.nativeType
115110
-

src/Doctrine/Odm/Filter/DateFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public function getSchema(Parameter $parameter): array
251251
return ['type' => 'string', 'format' => 'date'];
252252
}
253253

254-
public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null
254+
public function getOpenApiParameters(Parameter $parameter): array
255255
{
256256
$in = $parameter instanceof QueryParameter ? 'query' : 'header';
257257
$key = $parameter->getKey();

src/Doctrine/Odm/Filter/RangeFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ protected function addMatch(Builder $aggregationBuilder, string $field, string $
209209
}
210210
}
211211

212-
public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null
212+
public function getOpenApiParameters(Parameter $parameter): array
213213
{
214214
$in = $parameter instanceof QueryParameter ? 'query' : 'header';
215215
$key = $parameter->getKey();

src/Doctrine/Orm/Filter/DateFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public function getSchema(Parameter $parameter): array
283283
return ['type' => 'string', 'format' => 'date'];
284284
}
285285

286-
public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null
286+
public function getOpenApiParameters(Parameter $parameter): array
287287
{
288288
$in = $parameter instanceof QueryParameter ? 'query' : 'header';
289289
$key = $parameter->getKey();

src/Doctrine/Orm/Filter/RangeFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ protected function addWhere(QueryBuilder $queryBuilder, QueryNameGeneratorInterf
227227
}
228228
}
229229

230-
public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null
230+
public function getOpenApiParameters(Parameter $parameter): array
231231
{
232232
$in = $parameter instanceof QueryParameter ? 'query' : 'header';
233233
$key = $parameter->getKey();

src/GraphQl/Metadata/RuntimeOperationMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(private readonly ResourceMetadataCollectionFactoryIn
3030
{
3131
}
3232

33-
public function create(string $uriTemplate, array $context = []): ?Operation
33+
public function create(string $uriTemplate, array $context = []): Operation
3434
{
3535
try {
3636
$parameters = $this->router->match($uriTemplate);

src/GraphQl/Serializer/ObjectNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getSupportedTypes($format): array
5353
*
5454
* @throws UnexpectedValueException
5555
*/
56-
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
56+
public function normalize(mixed $object, ?string $format = null, array $context = []): array
5757
{
5858
if (isset($context['api_resource'])) {
5959
$originalResource = $context['api_resource'];

src/GraphQl/Type/TypeConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function convertPhpType(Type $type, bool $input, Operation $rootOperation
119119
/**
120120
* {@inheritdoc}
121121
*/
122-
public function resolveType(string $type): ?GraphQLType
122+
public function resolveType(string $type): GraphQLType
123123
{
124124
try {
125125
$astTypeNode = Parser::parseType($type);

src/Hydra/Serializer/DocumentationNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function __construct(
6767
/**
6868
* {@inheritdoc}
6969
*/
70-
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
70+
public function normalize(mixed $object, ?string $format = null, array $context = []): array
7171
{
7272
$classes = [];
7373
$entrypointProperties = [];

src/JsonApi/Filter/SparseFieldset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getSchema(MetadataParameter $parameter): array
3333
];
3434
}
3535

36-
public function getOpenApiParameters(MetadataParameter $parameter): Parameter|array|null
36+
public function getOpenApiParameters(MetadataParameter $parameter): Parameter
3737
{
3838
return new Parameter(
3939
name: ($k = $parameter->getKey()).'[]',

src/JsonApi/Serializer/EntrypointNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(private readonly ResourceMetadataCollectionFactoryIn
3939
/**
4040
* {@inheritdoc}
4141
*/
42-
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
42+
public function normalize(mixed $object, ?string $format = null, array $context = []): array
4343
{
4444
$entrypoint = ['links' => ['self' => $this->urlGenerator->generate('api_entrypoint', [], UrlGeneratorInterface::ABS_URL)]];
4545

src/JsonSchema/Metadata/Property/Factory/SchemaPropertyMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function create(string $resourceClass, string $property, array $options =
6262
}
6363
}
6464

65-
$extraProperties = $propertyMetadata->getExtraProperties() ?? [];
65+
$extraProperties = $propertyMetadata->getExtraProperties();
6666
// see AttributePropertyMetadataFactory
6767
if (true === ($extraProperties[self::JSON_SCHEMA_USER_DEFINED] ?? false)) {
6868
// schema seems to have been declared by the user: do not override nor complete user value

src/JsonSchema/SchemaFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private function buildLegacyPropertySchema(Schema $schema, string $definitionNam
176176
unset($propertySchema['type']);
177177
}
178178

179-
$extraProperties = $propertyMetadata->getExtraProperties() ?? [];
179+
$extraProperties = $propertyMetadata->getExtraProperties();
180180
// see AttributePropertyMetadataFactory
181181
if (true === ($extraProperties[SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED] ?? false)) {
182182
// schema seems to have been declared by the user: do not override nor complete user value
@@ -291,7 +291,7 @@ private function buildPropertySchema(Schema $schema, string $definitionName, str
291291
$additionalPropertySchema ?? []
292292
);
293293

294-
$extraProperties = $propertyMetadata->getExtraProperties() ?? [];
294+
$extraProperties = $propertyMetadata->getExtraProperties();
295295
// see AttributePropertyMetadataFactory
296296
if (true === ($extraProperties[SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED] ?? false)) {
297297
// schema seems to have been declared by the user: do not override nor complete user value

src/Laravel/Eloquent/Metadata/Factory/Property/EloquentAttributePropertyMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private function handleUserDefinedSchema(ApiProperty $propertyMetadata): ApiProp
7979
// can't know later if the schema has been defined by the user or by API Platform
8080
// store extra key to make this difference
8181
if (null !== $propertyMetadata->getSchema()) {
82-
$extraProperties = $propertyMetadata->getExtraProperties() ?? [];
82+
$extraProperties = $propertyMetadata->getExtraProperties();
8383
$propertyMetadata = $propertyMetadata->withExtraProperties([SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED => true] + $extraProperties);
8484
}
8585

src/Metadata/ApiProperty.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ public function isInitializable(): ?bool
572572
return $this->initializable;
573573
}
574574

575-
public function getExtraProperties(): ?array
575+
public function getExtraProperties(): array
576576
{
577577
return $this->extraProperties;
578578
}

src/Metadata/CascadeToOperationsTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function cascadeToGraphQlOperations(): static
5656
/**
5757
* @param Operations<HttpOperation>|list<GraphQlOperation> $operations
5858
*
59-
* @return array[string, HttpOperation]|list<GraphQlOperation>
59+
* @return array<string, HttpOperation>|list<GraphQlOperation>
6060
*/
6161
private function getMutatedOperations(iterable $operations, ApiResource $apiResource): iterable
6262
{

src/Metadata/Property/Factory/AttributePropertyMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private function handleUserDefinedSchema(ApiProperty $propertyMetadata): ApiProp
150150
// can't know later if the schema has been defined by the user or by API Platform
151151
// store extra key to make this difference
152152
if (null !== $propertyMetadata->getSchema()) {
153-
$extraProperties = $propertyMetadata->getExtraProperties() ?? [];
153+
$extraProperties = $propertyMetadata->getExtraProperties();
154154
$propertyMetadata = $propertyMetadata->withExtraProperties([SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED => true] + $extraProperties);
155155
}
156156

src/Metadata/Property/Factory/ExtractorPropertyMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private function handleUserDefinedSchema(ApiProperty $propertyMetadata): ApiProp
133133
// can't know later if the schema has been defined by the user or by API Platform
134134
// store extra key to make this difference
135135
if (null !== $propertyMetadata->getSchema()) {
136-
$extraProperties = $propertyMetadata->getExtraProperties() ?? [];
136+
$extraProperties = $propertyMetadata->getExtraProperties();
137137
$propertyMetadata = $propertyMetadata->withExtraProperties([SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED => true] + $extraProperties);
138138
}
139139

src/OpenApi/Serializer/ApiGatewayNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(private readonly NormalizerInterface $documentationN
4242
*
4343
* @throws UnexpectedValueException
4444
*/
45-
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
45+
public function normalize(mixed $object, ?string $format = null, array $context = []): array
4646
{
4747
$data = $this->documentationNormalizer->normalize($object, $format, $context);
4848
if (!\is_array($data)) {

src/Serializer/AbstractItemNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public function denormalize(mixed $data, string $class, ?string $format = null,
275275
foreach (array_keys($data) as $attribute) {
276276
$attribute = $this->nameConverter ? $this->nameConverter->denormalize((string) $attribute) : $attribute;
277277
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $attribute, $options);
278-
$attributeExtraProperties = $propertyMetadata->getExtraProperties() ?? [];
278+
$attributeExtraProperties = $propertyMetadata->getExtraProperties();
279279
$throwOnPropertyAccessDenied = $attributeExtraProperties['throw_on_access_denied'] ?? $throwOnAccessDenied;
280280
if (!\in_array($attribute, $propertyNames, true)) {
281281
continue;

src/Serializer/Filter/PropertyFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public function getSchema(MetadataParameter $parameter): array
277277
];
278278
}
279279

280-
public function getOpenApiParameters(MetadataParameter $parameter): Parameter|array|null
280+
public function getOpenApiParameters(MetadataParameter $parameter): Parameter
281281
{
282282
$example = \sprintf(
283283
'%1$s[]={propertyName}&%1$s[]={anotherPropertyName}',

src/State/Exception/ParameterNotSupportedException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ public function getTitle(): ?string
3333
return $this->message;
3434
}
3535

36-
public function getStatus(): ?int
36+
public function getStatus(): int
3737
{
3838
return 400;
3939
}
4040

41-
public function getDetail(): ?string
41+
public function getDetail(): string
4242
{
4343
return \sprintf('Parameter "%s" not supported', $this->parameter);
4444
}
4545

46-
public function getInstance(): ?string
46+
public function getInstance(): string
4747
{
4848
return $this->parameter;
4949
}

src/State/Provider/BackedEnumProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
final class BackedEnumProvider implements ProviderInterface
2323
{
24-
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
24+
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array
2525
{
2626
$resourceClass = $operation->getClass();
2727
if (!$resourceClass || !is_a($resourceClass, \BackedEnum::class, true)) {

src/State/Tests/ParameterProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function get(string $id)
3434
{
3535
if ('test' === $id) {
3636
return new class implements ParameterProviderInterface {
37-
public function provide(Parameter $parameter, array $parameters = [], array $context = []): ?Operation
37+
public function provide(Parameter $parameter, array $parameters = [], array $context = []): Operation
3838
{
3939
return new Get(name: 'ok');
4040
}

src/Symfony/Bundle/Test/Client.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,8 @@ public function getKernelBrowser(): KernelBrowser
149149

150150
/**
151151
* Returns the container.
152-
*
153-
* @return ContainerInterface|null Returns null when the Kernel has been shutdown or not started yet
154152
*/
155-
public function getContainer(): ?ContainerInterface
153+
public function getContainer(): ContainerInterface
156154
{
157155
return $this->kernelBrowser->getContainer();
158156
}

src/Symfony/Routing/IriConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function getResourceFromIri(string $iri, array $context = [], ?Operation
113113
/**
114114
* {@inheritdoc}
115115
*/
116-
public function getIriFromResource(object|string $resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, ?Operation $operation = null, array $context = []): ?string
116+
public function getIriFromResource(object|string $resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, ?Operation $operation = null, array $context = []): string
117117
{
118118
$resourceClass = $context['force_resource_class'] ?? (\is_string($resource) ? $resource : $this->getObjectClass($resource));
119119

src/Symfony/Routing/SkolemIriConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function getResourceFromIri(string $iri, array $context = [], ?Operation
4949
/**
5050
* {@inheritdoc}
5151
*/
52-
public function getIriFromResource(object|string $resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, ?Operation $operation = null, array $context = []): ?string
52+
public function getIriFromResource(object|string $resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, ?Operation $operation = null, array $context = []): string
5353
{
5454
$referenceType = $operation ? ($operation->getUrlGenerationStrategy() ?? $referenceType) : $referenceType;
5555
if (($isObject = \is_object($resource)) && $this->objectHashMap->contains($resource)) {

src/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaCollectionRestriction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private function mergeConstraintRestrictions(Required|Optional $constraint, ApiP
7676

7777
foreach ($nestedConstraints as $nestedConstraint) {
7878
foreach ($this->restrictionsMetadata as $restrictionMetadata) {
79-
if ($restrictionMetadata->supports($nestedConstraint, $propertyMetadata->withExtraProperties(($propertyMetadata->getExtraProperties() ?? []) + ['nested_schema' => true])) && !empty($nestedConstraintRestriction = $restrictionMetadata->create($nestedConstraint, $propertyMetadata))) {
79+
if ($restrictionMetadata->supports($nestedConstraint, $propertyMetadata->withExtraProperties($propertyMetadata->getExtraProperties() + ['nested_schema' => true])) && !empty($nestedConstraintRestriction = $restrictionMetadata->create($nestedConstraint, $propertyMetadata))) {
8080
$propertyRestrictions[] = $nestedConstraintRestriction;
8181
}
8282
}

src/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function create(string $resourceClass, string $property, array $options =
9494
{
9595
$propertyMetadata = $this->decorated->create($resourceClass, $property, $options);
9696

97-
$extraProperties = $propertyMetadata->getExtraProperties() ?? [];
97+
$extraProperties = $propertyMetadata->getExtraProperties();
9898
// see AttributePropertyMetadataFactory
9999
if (true === ($extraProperties[SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED] ?? false)) {
100100
// schema seems to have been declared by the user: do not override nor complete user value

tests/Fixtures/TestBundle/HttpCache/TagCollectorCustom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function collect(array $context = []): void
6969
$this->addCacheTagForResource($context, $iri);
7070
}
7171

72-
private function addCacheTagForResource(array $context, string $iri): void
72+
private function addCacheTagForResource(array &$context, string $iri): void
7373
{
7474
$context['resources'][$iri] = $iri;
7575
}

tests/Fixtures/TestBundle/HttpCache/TagCollectorDefault.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function collect(array $context = []): void
2929
}
3030
}
3131

32-
private function addResourceToContext(array $context): void
32+
private function addResourceToContext(array &$context): void
3333
{
3434
$iri = $context['iri'];
3535

tests/Fixtures/TestBundle/Serializer/ErrorNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(private readonly NormalizerInterface $decorated)
2222
{
2323
}
2424

25-
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject
25+
public function normalize(mixed $object, ?string $format = null, array $context = []): array|\ArrayObject
2626
{
2727
$a = $this->decorated->normalize($object, $format, $context);
2828
$a['hello'] = 'world';

tests/Fixtures/TestBundle/Serializer/Normalizer/OverrideDocumentationNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(private readonly NormalizerInterface $documentationN
3131
*
3232
* @throws ExceptionInterface
3333
*/
34-
public function normalize($object, $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null
34+
public function normalize($object, $format = null, array $context = []): array
3535
{
3636
$data = $this->documentationNormalizer->normalize($object, $format, $context);
3737
if (!\is_array($data)) {

0 commit comments

Comments
 (0)