Skip to content

Commit

Permalink
Mark columnName as always set
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
greg0ire committed Jan 8, 2022
1 parent 760397c commit fa731b1
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 50 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
* @psalm-type FieldMapping = array{
* type: string,
* fieldName: string,
* columnName?: string,
* columnName: string,
* length?: int,
* id?: bool,
* nullable?: bool,
Expand Down
5 changes: 1 addition & 4 deletions lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata)
$fieldXml = $root->addChild('field');
$fieldXml->addAttribute('name', $field['fieldName']);
$fieldXml->addAttribute('type', $field['type']);

if (isset($field['columnName'])) {
$fieldXml->addAttribute('column', $field['columnName']);
}
$fieldXml->addAttribute('column', $field['columnName']);

if (isset($field['length'])) {
$fieldXml->addAttribute('length', (string) $field['length']);
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,7 @@ parameters:
path: lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php

-
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\\.$#"
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\\.$#"
count: 1
path: lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php

Expand Down
45 changes: 1 addition & 44 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@
<MissingReturnType occurrences="1">
<code>loadCacheEntry</code>
</MissingReturnType>
<PossiblyUndefinedArrayOffset occurrences="1">
<code>$fieldMapping['columnName']</code>
</PossiblyUndefinedArrayOffset>
<UndefinedInterfaceMethod occurrences="1">
<code>getCacheRegion</code>
</UndefinedInterfaceMethod>
Expand Down Expand Up @@ -712,11 +709,6 @@
<code>matching</code>
</UndefinedInterfaceMethod>
</file>
<file src="lib/Doctrine/ORM/Mapping/AnsiQuoteStrategy.php">
<PossiblyUndefinedArrayOffset occurrences="1">
<code>$class-&gt;fieldMappings[$fieldName]['columnName']</code>
</PossiblyUndefinedArrayOffset>
</file>
<file src="lib/Doctrine/ORM/Mapping/AssociationOverride.php">
<MissingConstructor occurrences="5">
<code>$fetch</code>
Expand Down Expand Up @@ -1009,18 +1001,10 @@
<code>setValue</code>
<code>setValue</code>
</PossiblyNullReference>
<PossiblyUndefinedArrayOffset occurrences="11">
<code>$fieldMapping['columnName']</code>
<code>$fieldMapping['columnName']</code>
<code>$mapping['columnName']</code>
<PossiblyUndefinedArrayOffset occurrences="3">
<code>$mapping['originalClass']</code>
<code>$mapping['originalField']</code>
<code>$mapping['targetEntity']</code>
<code>$this-&gt;fieldMappings[$field]['columnName']</code>
<code>$this-&gt;fieldMappings[$field]['columnName']</code>
<code>$this-&gt;fieldMappings[$idProperty]['columnName']</code>
<code>$this-&gt;fieldMappings[$idProperty]['columnName']</code>
<code>$this-&gt;fieldMappings[$idProperty]['columnName']</code>
</PossiblyUndefinedArrayOffset>
<PropertyNotSetInConstructor occurrences="6">
<code>$idGenerator</code>
Expand Down Expand Up @@ -1091,10 +1075,6 @@
<MissingClosureParamType occurrences="1">
<code>$joinColumn</code>
</MissingClosureParamType>
<PossiblyUndefinedArrayOffset occurrences="2">
<code>$class-&gt;fieldMappings[$fieldName]['columnName']</code>
<code>$class-&gt;fieldMappings[$fieldName]['columnName']</code>
</PossiblyUndefinedArrayOffset>
</file>
<file src="lib/Doctrine/ORM/Mapping/DiscriminatorColumn.php">
<PossiblyNullPropertyAssignmentValue occurrences="4">
Expand Down Expand Up @@ -1779,11 +1759,6 @@
<code>$targetClass-&gt;associationMappings</code>
</PossiblyNullArrayOffset>
</file>
<file src="lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php">
<PossiblyUndefinedArrayOffset occurrences="1">
<code>$fieldMapping['columnName']</code>
</PossiblyUndefinedArrayOffset>
</file>
<file src="lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php">
<ArgumentTypeCoercion occurrences="1">
<code>$this-&gt;em</code>
Expand Down Expand Up @@ -1839,10 +1814,6 @@
<code>getValue</code>
<code>setValue</code>
</PossiblyNullReference>
<PossiblyUndefinedArrayOffset occurrences="2">
<code>$fieldMapping['columnName']</code>
<code>$fieldMapping['columnName']</code>
</PossiblyUndefinedArrayOffset>
<PropertyNotSetInConstructor occurrences="1">
<code>$insertSql</code>
</PropertyNotSetInConstructor>
Expand Down Expand Up @@ -2151,9 +2122,6 @@
<PossiblyNullArrayOffset occurrences="1">
<code>$class-&gt;associationMappings</code>
</PossiblyNullArrayOffset>
<PossiblyUndefinedArrayOffset occurrences="1">
<code>$field['columnName']</code>
</PossiblyUndefinedArrayOffset>
<PropertyNotSetInConstructor occurrences="2">
<code>$fieldMapping</code>
<code>$pathExpression</code>
Expand Down Expand Up @@ -2841,9 +2809,6 @@
<code>getShortName</code>
<code>getShortName</code>
</PossiblyNullReference>
<PossiblyUndefinedArrayOffset occurrences="1">
<code>$class-&gt;fieldMappings[$this-&gt;fieldMappings[$columnName]]['columnName']</code>
</PossiblyUndefinedArrayOffset>
</file>
<file src="lib/Doctrine/ORM/Query/SqlWalker.php">
<DocblockTypeContradiction occurrences="8">
Expand Down Expand Up @@ -2923,11 +2888,6 @@
<PossiblyNullReference occurrences="1">
<code>dispatch</code>
</PossiblyNullReference>
<PossiblyUndefinedArrayOffset occurrences="3">
<code>$fieldMapping['columnName']</code>
<code>$mapping['columnName']</code>
<code>$mapping['columnName']</code>
</PossiblyUndefinedArrayOffset>
<PropertyTypeCoercion occurrences="3">
<code>$query</code>
<code>$this-&gt;queryComponents</code>
Expand Down Expand Up @@ -3640,9 +3600,6 @@
<NonInvariantDocblockPropertyType occurrences="1">
<code>$_extension</code>
</NonInvariantDocblockPropertyType>
<PossiblyUndefinedArrayOffset occurrences="1">
<code>$fieldMapping['columnName']</code>
</PossiblyUndefinedArrayOffset>
<RedundantConditionGivenDocblockType occurrences="2">
<code>$metadata-&gt;table</code>
<code>isset($metadata-&gt;lifecycleCallbacks)</code>
Expand Down

0 comments on commit fa731b1

Please sign in to comment.