Skip to content

Commit 271d399

Browse files
committed
Hunt down invalid docblocks
It is OK to ignore some of the errors we get, but not this one.
1 parent c78f933 commit 271d399

File tree

4 files changed

+87
-47
lines changed

4 files changed

+87
-47
lines changed

lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php

+2-22
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ public function enableAssociationCache($fieldName, array $cache)
13531353
/**
13541354
* @param string $fieldName
13551355
* @param array $cache
1356-
* @psalm-param array{usage?: int, region?: string|null} $cache
1356+
* @psalm-param array{usage?: int|null, region?: string|null} $cache
13571357
*
13581358
* @return int[]|string[]
13591359
* @psalm-return array{usage: int, region: string|null}
@@ -1793,25 +1793,7 @@ protected function validateAndCompleteFieldMapping(array $mapping): array
17931793
* @psalm-param array<string, mixed> $mapping The mapping.
17941794
*
17951795
* @return mixed[] The updated mapping.
1796-
* @psalm-return array{
1797-
* mappedBy: mixed|null,
1798-
* inversedBy: mixed|null,
1799-
* isOwningSide: bool,
1800-
* sourceEntity: class-string,
1801-
* targetEntity: string,
1802-
* fieldName: mixed,
1803-
* fetch: mixed,
1804-
* cascade: array<array-key,string>,
1805-
* isCascadeRemove: bool,
1806-
* isCascadePersist: bool,
1807-
* isCascadeRefresh: bool,
1808-
* isCascadeMerge: bool,
1809-
* isCascadeDetach: bool,
1810-
* type: int,
1811-
* originalField: string,
1812-
* originalClass: class-string,
1813-
* ?orphanRemoval: bool
1814-
* }
1796+
* @psalm-return AssociationMapping
18151797
*
18161798
* @throws MappingException If something is wrong with the mapping.
18171799
*/
@@ -1941,7 +1923,6 @@ protected function _validateAndCompleteAssociationMapping(array $mapping)
19411923
* @psalm-param array<string, mixed> $mapping The mapping to validate & complete.
19421924
*
19431925
* @return mixed[] The validated & completed mapping.
1944-
* @psalm-return array{isOwningSide: mixed, orphanRemoval: bool, isCascadeRemove: bool}
19451926
* @psalm-return array{
19461927
* mappedBy: mixed|null,
19471928
* inversedBy: mixed|null,
@@ -2096,7 +2077,6 @@ protected function _validateAndCompleteOneToManyMapping(array $mapping)
20962077
* Validates & completes a many-to-many association mapping.
20972078
*
20982079
* @psalm-param array<string, mixed> $mapping The mapping to validate & complete.
2099-
* @psalm-param array<string, mixed> $mapping The mapping to validate & complete.
21002080
*
21012081
* @return mixed[] The validated & completed mapping.
21022082
* @psalm-return array{

lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -903,11 +903,10 @@ private function columnToArray(string $fieldName, ?array $column): array
903903
* Parse / Normalize the cache configuration
904904
*
905905
* @param mixed[] $cacheMapping
906-
* @psalm-param array{usage: mixed, region: (string|null)} $cacheMapping
907-
* @psalm-param array{usage: string, region?: string} $cacheMapping
906+
* @psalm-param array{usage: string|null, region?: mixed} $cacheMapping
908907
*
909908
* @return mixed[]
910-
* @psalm-return array{usage: int, region: string|null}
909+
* @psalm-return array{usage: int|null, region: string|null}
911910
*/
912911
private function cacheToArray(array $cacheMapping): array
913912
{

phpstan-baseline.neon

+5-5
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ parameters:
170170
count: 2
171171
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
172172

173+
-
174+
message: "#^Method Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\:\\:_validateAndCompleteManyToManyMapping\\(\\) should return array\\{mappedBy\\: mixed, inversedBy\\: mixed, isOwningSide\\: bool, sourceEntity\\: class\\-string, targetEntity\\: string, fieldName\\: mixed, fetch\\: mixed, cascade\\: array\\<string\\>, \\.\\.\\.\\} but returns array\\{cache\\?\\: array, cascade\\: array\\<string\\>, declared\\?\\: class\\-string, fetch\\: mixed, fieldName\\: string, id\\?\\: bool, inherited\\?\\: class\\-string, indexBy\\?\\: string, \\.\\.\\.\\}\\.$#"
175+
count: 1
176+
path: lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
177+
173178
-
174179
message: "#^Method Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\:\\:fullyQualifiedClassName\\(\\) should return class\\-string\\|null but returns string\\|null\\.$#"
175180
count: 1
@@ -230,11 +235,6 @@ parameters:
230235
count: 1
231236
path: lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
232237

233-
-
234-
message: "#^Offset 'usage' on array\\{usage\\: string, region\\?\\: string\\} in isset\\(\\) always exists and is not nullable\\.$#"
235-
count: 1
236-
path: lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php
237-
238238
-
239239
message: "#^Call to function is_int\\(\\) with string will always evaluate to false\\.$#"
240240
count: 1

psalm-baseline.xml

+78-17
Original file line numberDiff line numberDiff line change
@@ -603,11 +603,6 @@
603603
<code>$mapping</code>
604604
<code>$overrideMapping</code>
605605
</InvalidArgument>
606-
<InvalidDocblock>
607-
<code>protected function _validateAndCompleteAssociationMapping(array $mapping)</code>
608-
<code>protected function _validateAndCompleteManyToManyMapping(array $mapping)</code>
609-
<code>protected function _validateAndCompleteOneToOneMapping(array $mapping)</code>
610-
</InvalidDocblock>
611606
<InvalidNullableReturnType>
612607
<code>ReflectionProperty</code>
613608
<code>ReflectionProperty</code>
@@ -620,28 +615,92 @@
620615
<code>$this-&gt;subClasses</code>
621616
</InvalidPropertyAssignmentValue>
622617
<InvalidReturnStatement>
618+
<code>$mapping</code>
619+
<code>$mapping</code>
620+
<code>$mapping</code>
623621
<code>$this-&gt;reflClass</code>
624622
</InvalidReturnStatement>
625623
<InvalidReturnType>
624+
<code>AssociationMapping</code>
625+
<code>array{
626+
* mappedBy: mixed,
627+
* inversedBy: mixed,
628+
* isOwningSide: bool,
629+
* sourceEntity: string,
630+
* targetEntity: string,
631+
* fieldName: mixed,
632+
* fetch: int|mixed,
633+
* cascade: array&lt;array-key,string&gt;,
634+
* isCascadeRemove: bool,
635+
* isCascadePersist: bool,
636+
* isCascadeRefresh: bool,
637+
* isCascadeMerge: bool,
638+
* isCascadeDetach: bool,
639+
* orphanRemoval: bool
640+
* }</code>
641+
<code>array{
642+
* mappedBy: mixed|null,
643+
* inversedBy: mixed|null,
644+
* isOwningSide: bool,
645+
* sourceEntity: class-string,
646+
* targetEntity: string,
647+
* fieldName: mixed,
648+
* fetch: mixed,
649+
* cascade: array&lt;string&gt;,
650+
* isCascadeRemove: bool,
651+
* isCascadePersist: bool,
652+
* isCascadeRefresh: bool,
653+
* isCascadeMerge: bool,
654+
* isCascadeDetach: bool,
655+
* type: int,
656+
* originalField: string,
657+
* originalClass: class-string,
658+
* joinColumns?: array{0: array{name: string, referencedColumnName: string}}|mixed,
659+
* id?: mixed,
660+
* sourceToTargetKeyColumns?: array&lt;string, string&gt;,
661+
* joinColumnFieldNames?: array&lt;string, string&gt;,
662+
* targetToSourceKeyColumns?: array&lt;string, string&gt;,
663+
* orphanRemoval: bool
664+
* }</code>
626665
<code>getReflectionClass</code>
627666
</InvalidReturnType>
628667
<LessSpecificReturnStatement>
629668
<code>$cache</code>
630669
<code>$className</code>
631670
<code>$className</code>
632671
<code>$columnNames</code>
672+
<code>$mapping</code>
633673
<code>$quotedColumnNames</code>
634674
<code>$this-&gt;namespace . '\\' . $className</code>
635675
</LessSpecificReturnStatement>
636676
<MethodSignatureMustProvideReturnType>
637677
<code>__toString</code>
638678
</MethodSignatureMustProvideReturnType>
639-
<MissingReturnType>
640-
<code>_validateAndCompleteAssociationMapping</code>
641-
<code>_validateAndCompleteManyToManyMapping</code>
642-
<code>_validateAndCompleteOneToOneMapping</code>
643-
</MissingReturnType>
644679
<MoreSpecificReturnType>
680+
<code>array{
681+
* mappedBy: mixed,
682+
* inversedBy: mixed,
683+
* isOwningSide: bool,
684+
* sourceEntity: class-string,
685+
* targetEntity: string,
686+
* fieldName: mixed,
687+
* fetch: mixed,
688+
* cascade: array&lt;string&gt;,
689+
* isCascadeRemove: bool,
690+
* isCascadePersist: bool,
691+
* isCascadeRefresh: bool,
692+
* isCascadeMerge: bool,
693+
* isCascadeDetach: bool,
694+
* type: int,
695+
* originalField: string,
696+
* originalClass: class-string,
697+
* joinTable?: array{inverseJoinColumns: mixed}|mixed,
698+
* joinTableColumns?: list&lt;mixed&gt;,
699+
* isOnDeleteCascade?: true,
700+
* relationToSourceKeyColumns?: array,
701+
* relationToTargetKeyColumns?: array,
702+
* orphanRemoval: bool
703+
* }</code>
645704
<code>array{usage: int, region: string|null}</code>
646705
<code>class-string|null</code>
647706
<code>list&lt;string&gt;</code>
@@ -928,10 +987,6 @@
928987
<code>addNamedQuery</code>
929988
</DeprecatedMethod>
930989
<InvalidArgument>
931-
<code>$this-&gt;cacheToArray($manyToManyElement-&gt;cache)</code>
932-
<code>$this-&gt;cacheToArray($manyToOneElement-&gt;cache)</code>
933-
<code>$this-&gt;cacheToArray($oneToManyElement-&gt;cache)</code>
934-
<code>$this-&gt;cacheToArray($oneToOneElement-&gt;cache)</code>
935990
<code>[
936991
'name' =&gt; isset($discrColumn['name']) ? (string) $discrColumn['name'] : null,
937992
'type' =&gt; isset($discrColumn['type']) ? (string) $discrColumn['type'] : 'string',
@@ -1031,16 +1086,22 @@
10311086
'enumType' =&gt; isset($discrColumn['enumType']) ? (string) $discrColumn['enumType'] : null,
10321087
]</code>
10331088
</InvalidArgument>
1034-
<InvalidDocblock>
1035-
<code>private function cacheToArray(array $cacheMapping): array</code>
1036-
</InvalidDocblock>
1089+
<LessSpecificReturnStatement>
1090+
<code>[
1091+
'usage' =&gt; $usage,
1092+
'region' =&gt; $region,
1093+
]</code>
1094+
</LessSpecificReturnStatement>
10371095
<MissingParamType>
10381096
<code>$fileExtension</code>
10391097
<code>$locator</code>
10401098
</MissingParamType>
10411099
<MoreSpecificImplementedParamType>
10421100
<code>$metadata</code>
10431101
</MoreSpecificImplementedParamType>
1102+
<MoreSpecificReturnType>
1103+
<code>array{usage: int|null, region: string|null}</code>
1104+
</MoreSpecificReturnType>
10441105
<PossiblyUndefinedMethod>
10451106
<code>$element</code>
10461107
<code>$element</code>

0 commit comments

Comments
 (0)