Skip to content

Commit fa731b1

Browse files
committed
Mark columnName as always set
This is enforced before writing to the property that holds FieldMapping arrays. As shown by the static analysis baselines reduction, this existence is relied on throughout the codebase.
1 parent 760397c commit fa731b1

File tree

4 files changed

+4
-50
lines changed

4 files changed

+4
-50
lines changed

lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
* @psalm-type FieldMapping = array{
7474
* type: string,
7575
* fieldName: string,
76-
* columnName?: string,
76+
* columnName: string,
7777
* length?: int,
7878
* id?: bool,
7979
* nullable?: bool,

lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata)
178178
$fieldXml = $root->addChild('field');
179179
$fieldXml->addAttribute('name', $field['fieldName']);
180180
$fieldXml->addAttribute('type', $field['type']);
181-
182-
if (isset($field['columnName'])) {
183-
$fieldXml->addAttribute('column', $field['columnName']);
184-
}
181+
$fieldXml->addAttribute('column', $field['columnName']);
185182

186183
if (isset($field['length'])) {
187184
$fieldXml->addAttribute('length', (string) $field['length']);

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ parameters:
21912191
path: lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php
21922192

21932193
-
2194-
message: "#^Offset 'version' on array\\{type\\: string, fieldName\\: string, columnName\\?\\: string, length\\?\\: int, id\\?\\: bool, nullable\\?\\: bool, columnDefinition\\?\\: string, precision\\?\\: int, \\.\\.\\.\\} in isset\\(\\) does not exist\\.$#"
2194+
message: "#^Offset 'version' on array\\{type\\: string, fieldName\\: string, columnName\\: string, length\\?\\: int, id\\?\\: bool, nullable\\?\\: bool, columnDefinition\\?\\: string, precision\\?\\: int, \\.\\.\\.\\} in isset\\(\\) does not exist\\.$#"
21952195
count: 1
21962196
path: lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php
21972197

psalm-baseline.xml

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@
102102
<MissingReturnType occurrences="1">
103103
<code>loadCacheEntry</code>
104104
</MissingReturnType>
105-
<PossiblyUndefinedArrayOffset occurrences="1">
106-
<code>$fieldMapping['columnName']</code>
107-
</PossiblyUndefinedArrayOffset>
108105
<UndefinedInterfaceMethod occurrences="1">
109106
<code>getCacheRegion</code>
110107
</UndefinedInterfaceMethod>
@@ -712,11 +709,6 @@
712709
<code>matching</code>
713710
</UndefinedInterfaceMethod>
714711
</file>
715-
<file src="lib/Doctrine/ORM/Mapping/AnsiQuoteStrategy.php">
716-
<PossiblyUndefinedArrayOffset occurrences="1">
717-
<code>$class-&gt;fieldMappings[$fieldName]['columnName']</code>
718-
</PossiblyUndefinedArrayOffset>
719-
</file>
720712
<file src="lib/Doctrine/ORM/Mapping/AssociationOverride.php">
721713
<MissingConstructor occurrences="5">
722714
<code>$fetch</code>
@@ -1009,18 +1001,10 @@
10091001
<code>setValue</code>
10101002
<code>setValue</code>
10111003
</PossiblyNullReference>
1012-
<PossiblyUndefinedArrayOffset occurrences="11">
1013-
<code>$fieldMapping['columnName']</code>
1014-
<code>$fieldMapping['columnName']</code>
1015-
<code>$mapping['columnName']</code>
1004+
<PossiblyUndefinedArrayOffset occurrences="3">
10161005
<code>$mapping['originalClass']</code>
10171006
<code>$mapping['originalField']</code>
10181007
<code>$mapping['targetEntity']</code>
1019-
<code>$this-&gt;fieldMappings[$field]['columnName']</code>
1020-
<code>$this-&gt;fieldMappings[$field]['columnName']</code>
1021-
<code>$this-&gt;fieldMappings[$idProperty]['columnName']</code>
1022-
<code>$this-&gt;fieldMappings[$idProperty]['columnName']</code>
1023-
<code>$this-&gt;fieldMappings[$idProperty]['columnName']</code>
10241008
</PossiblyUndefinedArrayOffset>
10251009
<PropertyNotSetInConstructor occurrences="6">
10261010
<code>$idGenerator</code>
@@ -1091,10 +1075,6 @@
10911075
<MissingClosureParamType occurrences="1">
10921076
<code>$joinColumn</code>
10931077
</MissingClosureParamType>
1094-
<PossiblyUndefinedArrayOffset occurrences="2">
1095-
<code>$class-&gt;fieldMappings[$fieldName]['columnName']</code>
1096-
<code>$class-&gt;fieldMappings[$fieldName]['columnName']</code>
1097-
</PossiblyUndefinedArrayOffset>
10981078
</file>
10991079
<file src="lib/Doctrine/ORM/Mapping/DiscriminatorColumn.php">
11001080
<PossiblyNullPropertyAssignmentValue occurrences="4">
@@ -1779,11 +1759,6 @@
17791759
<code>$targetClass-&gt;associationMappings</code>
17801760
</PossiblyNullArrayOffset>
17811761
</file>
1782-
<file src="lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php">
1783-
<PossiblyUndefinedArrayOffset occurrences="1">
1784-
<code>$fieldMapping['columnName']</code>
1785-
</PossiblyUndefinedArrayOffset>
1786-
</file>
17871762
<file src="lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php">
17881763
<ArgumentTypeCoercion occurrences="1">
17891764
<code>$this-&gt;em</code>
@@ -1839,10 +1814,6 @@
18391814
<code>getValue</code>
18401815
<code>setValue</code>
18411816
</PossiblyNullReference>
1842-
<PossiblyUndefinedArrayOffset occurrences="2">
1843-
<code>$fieldMapping['columnName']</code>
1844-
<code>$fieldMapping['columnName']</code>
1845-
</PossiblyUndefinedArrayOffset>
18461817
<PropertyNotSetInConstructor occurrences="1">
18471818
<code>$insertSql</code>
18481819
</PropertyNotSetInConstructor>
@@ -2151,9 +2122,6 @@
21512122
<PossiblyNullArrayOffset occurrences="1">
21522123
<code>$class-&gt;associationMappings</code>
21532124
</PossiblyNullArrayOffset>
2154-
<PossiblyUndefinedArrayOffset occurrences="1">
2155-
<code>$field['columnName']</code>
2156-
</PossiblyUndefinedArrayOffset>
21572125
<PropertyNotSetInConstructor occurrences="2">
21582126
<code>$fieldMapping</code>
21592127
<code>$pathExpression</code>
@@ -2841,9 +2809,6 @@
28412809
<code>getShortName</code>
28422810
<code>getShortName</code>
28432811
</PossiblyNullReference>
2844-
<PossiblyUndefinedArrayOffset occurrences="1">
2845-
<code>$class-&gt;fieldMappings[$this-&gt;fieldMappings[$columnName]]['columnName']</code>
2846-
</PossiblyUndefinedArrayOffset>
28472812
</file>
28482813
<file src="lib/Doctrine/ORM/Query/SqlWalker.php">
28492814
<DocblockTypeContradiction occurrences="8">
@@ -2923,11 +2888,6 @@
29232888
<PossiblyNullReference occurrences="1">
29242889
<code>dispatch</code>
29252890
</PossiblyNullReference>
2926-
<PossiblyUndefinedArrayOffset occurrences="3">
2927-
<code>$fieldMapping['columnName']</code>
2928-
<code>$mapping['columnName']</code>
2929-
<code>$mapping['columnName']</code>
2930-
</PossiblyUndefinedArrayOffset>
29312891
<PropertyTypeCoercion occurrences="3">
29322892
<code>$query</code>
29332893
<code>$this-&gt;queryComponents</code>
@@ -3640,9 +3600,6 @@
36403600
<NonInvariantDocblockPropertyType occurrences="1">
36413601
<code>$_extension</code>
36423602
</NonInvariantDocblockPropertyType>
3643-
<PossiblyUndefinedArrayOffset occurrences="1">
3644-
<code>$fieldMapping['columnName']</code>
3645-
</PossiblyUndefinedArrayOffset>
36463603
<RedundantConditionGivenDocblockType occurrences="2">
36473604
<code>$metadata-&gt;table</code>
36483605
<code>isset($metadata-&gt;lifecycleCallbacks)</code>

0 commit comments

Comments
 (0)