Skip to content

Commit bfd1fa9

Browse files
chore: introduce phpstan level 6
1 parent 82ab5ef commit bfd1fa9

20 files changed

+137
-47
lines changed

phpstan.neon.dist

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 5
2+
level: 6
33
paths:
44
- src
55
- tests
@@ -112,3 +112,63 @@ parameters:
112112

113113
# Allow extra assertions in tests: https://github.com/phpstan/phpstan-strict-rules/issues/130
114114
- '#^Call to (static )?method PHPUnit\\Framework\\Assert::.* will always evaluate to true\.$#'
115+
116+
# Level 6
117+
-
118+
identifier: missingType.iterableValue
119+
-
120+
identifier: missingType.generics
121+
-
122+
identifier: missingType.property
123+
paths:
124+
- src/Doctrine/Common/Tests
125+
- src/Doctrine/Odm/Tests
126+
- src/Doctrine/Orm/Tests
127+
- src/Elasticsearch/Tests
128+
- src/Hydra/Tests
129+
- src/JsonApi/Tests
130+
- src/JsonSchema/Tests
131+
- src/Metadata/Tests
132+
- src/Serializer/Tests
133+
- src/Symfony/Tests
134+
- tests
135+
-
136+
identifier: missingType.parameter
137+
paths:
138+
- src/Doctrine/Common/Tests
139+
- src/Doctrine/Odm/Tests
140+
- src/Doctrine/Orm/Tests
141+
- src/Elasticsearch/Tests
142+
- src/GraphQl/Tests
143+
- src/Hydra/Tests
144+
- src/JsonApi/Tests
145+
- src/JsonSchema/Tests
146+
- src/Metadata/Tests
147+
- src/OpenApi/Tests
148+
- src/Serializer/Tests
149+
- src/Symfony/Bundle/Test
150+
- src/Symfony/Tests
151+
- tests
152+
- src # TODO
153+
-
154+
identifier: missingType.return
155+
paths:
156+
- src/Doctrine/Common/Tests
157+
- src/Doctrine/Odm/Tests
158+
- src/Doctrine/Orm/Tests
159+
- src/Elasticsearch/Tests
160+
- src/GraphQl/Tests
161+
- src/Hydra/Tests
162+
- src/JsonApi/Tests
163+
- src/JsonSchema/Tests
164+
- src/Metadata/Tests
165+
- src/OpenApi/Tests
166+
- src/Serializer/Tests
167+
- src/Symfony/Tests
168+
- tests
169+
-
170+
identifier: argument.templateType
171+
paths:
172+
- src/Symfony/Bundle/Test
173+
- tests
174+
- src # TODO

src/GraphQl/Resolver/Factory/ResolverFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function __invoke(?string $resourceClass = null, ?string $rootClass = nul
8787
};
8888
}
8989

90-
private function resolve(?array $source, array $args, ResolveInfo $info, ?string $rootClass = null, ?Operation $operation = null, mixed $body = null)
90+
private function resolve(?array $source, array $args, ResolveInfo $info, ?string $rootClass = null, ?Operation $operation = null, mixed $body = null): mixed
9191
{
9292
// Handles relay nodes
9393
if (!$operation) {

src/Metadata/ApiProperty.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,12 @@ public function withIdentifier(bool $identifier): static
345345
return $self;
346346
}
347347

348-
public function getDefault()
348+
public function getDefault(): mixed
349349
{
350350
return $this->default;
351351
}
352352

353-
public function withDefault($default): static
353+
public function withDefault(mixed $default): static
354354
{
355355
$self = clone $this;
356356
$self->default = $default;
@@ -587,6 +587,8 @@ public function withExtraProperties(array $extraProperties = []): static
587587

588588
/**
589589
* Gets IRI of this property.
590+
*
591+
* @return string[]
590592
*/
591593
public function getIris()
592594
{
@@ -608,6 +610,8 @@ public function withIris(string|array $iris): static
608610

609611
/**
610612
* Whether to generate a skolem iri on anonymous resources.
613+
*
614+
* @return bool
611615
*/
612616
public function getGenId()
613617
{

src/Metadata/Extractor/XmlPropertyExtractor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ private function buildValues(\SimpleXMLElement $resource): array
110110
return $data;
111111
}
112112

113-
private function buildArrayValue(?\SimpleXMLElement $resource, string $key, mixed $default = null)
113+
private function buildArrayValue(?\SimpleXMLElement $resource, string $key): ?array
114114
{
115115
if (!isset($resource->{$key.'s'}->{$key})) {
116-
return $default;
116+
return null;
117117
}
118118

119119
return (array) $resource->{$key.'s'}->{$key};

src/Metadata/Extractor/YamlPropertyExtractor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ private function buildProperties(array $resourcesYaml): void
101101
}
102102
}
103103

104-
private function buildAttribute(array $resource, string $key, mixed $default = null)
104+
private function buildAttribute(array $resource, string $key): ?array
105105
{
106106
if (empty($resource[$key])) {
107-
return $default;
107+
return null;
108108
}
109109

110110
if (!\is_array($resource[$key])) {

src/Metadata/HttpOperation.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public function getUriTemplate(): ?string
287287
return $this->uriTemplate;
288288
}
289289

290-
public function withUriTemplate(?string $uriTemplate = null)
290+
public function withUriTemplate(?string $uriTemplate = null): static
291291
{
292292
$self = clone $this;
293293
$self->uriTemplate = $uriTemplate;
@@ -311,11 +311,17 @@ public function withTypes($types): static
311311
return $self;
312312
}
313313

314+
/**
315+
* @return array<int|string, string|string[]>|string|null
316+
*/
314317
public function getFormats()
315318
{
316319
return $this->formats;
317320
}
318321

322+
/**
323+
* @param array<int|string, string|string[]>|string|null $formats
324+
*/
319325
public function withFormats($formats = null): static
320326
{
321327
$self = clone $this;
@@ -324,11 +330,17 @@ public function withFormats($formats = null): static
324330
return $self;
325331
}
326332

333+
/**
334+
* @return array<int|string, string|string[]>|string|null
335+
*/
327336
public function getInputFormats()
328337
{
329338
return $this->inputFormats;
330339
}
331340

341+
/**
342+
* @param array<int|string, string|string[]>|string|null $inputFormats
343+
*/
332344
public function withInputFormats($inputFormats = null): static
333345
{
334346
$self = clone $this;
@@ -337,11 +349,17 @@ public function withInputFormats($inputFormats = null): static
337349
return $self;
338350
}
339351

352+
/**
353+
* @return array<int|string, string|string[]>|string|null
354+
*/
340355
public function getOutputFormats()
341356
{
342357
return $this->outputFormats;
343358
}
344359

360+
/**
361+
* @param array<int|string, string|string[]>|string|null $outputFormats
362+
*/
345363
public function withOutputFormats($outputFormats = null): static
346364
{
347365
$self = clone $this;
@@ -350,6 +368,9 @@ public function withOutputFormats($outputFormats = null): static
350368
return $self;
351369
}
352370

371+
/**
372+
* @return array<string, mixed>|array<int, Link>|list<string>|null
373+
*/
353374
public function getUriVariables()
354375
{
355376
return $this->uriVariables;

src/Metadata/Metadata.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,54 +224,51 @@ public function withFilters(array $filters): static
224224
return $self;
225225
}
226226

227-
/**
228-
* @return array|bool|mixed|null
229-
*/
230-
public function getMercure()
227+
public function getMercure(): mixed
231228
{
232229
return $this->mercure;
233230
}
234231

235-
public function withMercure($mercure): static
232+
public function withMercure(mixed $mercure): static
236233
{
237234
$self = clone $this;
238235
$self->mercure = $mercure;
239236

240237
return $self;
241238
}
242239

243-
public function getMessenger()
240+
public function getMessenger(): mixed
244241
{
245242
return $this->messenger;
246243
}
247244

248-
public function withMessenger($messenger): static
245+
public function withMessenger(mixed $messenger): static
249246
{
250247
$self = clone $this;
251248
$self->messenger = $messenger;
252249

253250
return $self;
254251
}
255252

256-
public function getInput()
253+
public function getInput(): mixed
257254
{
258255
return $this->input;
259256
}
260257

261-
public function withInput($input): static
258+
public function withInput(mixed $input): static
262259
{
263260
$self = clone $this;
264261
$self->input = $input;
265262

266263
return $self;
267264
}
268265

269-
public function getOutput()
266+
public function getOutput(): mixed
270267
{
271268
return $this->output;
272269
}
273270

274-
public function withOutput($output): static
271+
public function withOutput(mixed $output): static
275272
{
276273
$self = clone $this;
277274
$self->output = $output;

src/Metadata/Resource/Factory/NotExposedOperationResourceMetadataCollectionFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ final class NotExposedOperationResourceMetadataCollectionFactory implements Reso
2929
{
3030
use OperationDefaultsTrait;
3131

32-
public static $skolemUriTemplate = '/.well-known/genid/{id}';
32+
public static string $skolemUriTemplate = '/.well-known/genid/{id}';
3333

34-
private $linkFactory;
35-
private $decorated;
34+
private LinkFactoryInterface $linkFactory;
35+
private ResourceMetadataCollectionFactoryInterface|null $decorated;
3636

3737
public function __construct(LinkFactoryInterface $linkFactory, ?ResourceMetadataCollectionFactoryInterface $decorated = null)
3838
{

src/Metadata/UriVariableTransformerInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ interface UriVariableTransformerInterface
2525
* @param array $context Options available to the transformer
2626
*
2727
* @throws InvalidUriVariableException Occurs when the URI variable could not be transformed
28+
*
29+
* @return mixed
2830
*/
2931
public function transform(mixed $value, array $types, array $context = []);
3032

src/OpenApi/Model/Header.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class Header
1717
{
1818
use ExtensionTrait;
1919

20-
public function __construct(private readonly string $in = 'header', private string $description = '', private bool $required = false, private bool $deprecated = false, private bool $allowEmptyValue = false, private array $schema = [], private ?string $style = null, private bool $explode = false, private bool $allowReserved = false, private $example = null, private ?\ArrayObject $examples = null, private ?\ArrayObject $content = null)
20+
public function __construct(private readonly string $in = 'header', private string $description = '', private bool $required = false, private bool $deprecated = false, private bool $allowEmptyValue = false, private array $schema = [], private ?string $style = null, private bool $explode = false, private bool $allowReserved = false, private mixed $example = null, private ?\ArrayObject $examples = null, private ?\ArrayObject $content = null)
2121
{
2222
if (null === $style) {
2323
$this->style = 'simple';
@@ -84,7 +84,7 @@ public function getAllowReserved(): bool
8484
return $this->allowReserved;
8585
}
8686

87-
public function getExample()
87+
public function getExample(): mixed
8888
{
8989
return $this->example;
9090
}

0 commit comments

Comments
 (0)