From 5aba762a333e1a0f5e235897fc613ee2f5409cab Mon Sep 17 00:00:00 2001 From: Julien LARY <47776596+laryjulien@users.noreply.github.com> Date: Mon, 22 Nov 2021 21:27:33 +0100 Subject: [PATCH] Add a psalm type for field mapping Field mapping have different definitions in property definition and method return. As suggested in issue and to avoid further desynchronization, a psalm type has been created. Fixes #9193 --- .../ORM/Mapping/ClassMetadataInfo.php | 54 ++++++++----------- phpstan-baseline.neon | 22 +------- 2 files changed, 23 insertions(+), 53 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index c898198f675..442de0ae98c 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -70,6 +70,26 @@ * * @template-covariant T of object * @template-implements ClassMetadata + * @psalm-type FieldMapping = array{ + * type: string, + * fieldName: string, + * columnName?: string, + * length?: int, + * id?: bool, + * nullable?: bool, + * columnDefinition?: string, + * precision?: int, + * scale?: int, + * unique?: string, + * inherited?: class-string, + * originalClass?: class-string, + * originalField?: string, + * quoted?: bool, + * requireSQLConversion?: bool, + * declared?: class-string, + * declaredField?: string, + * options?: array + * } */ class ClassMetadataInfo implements ClassMetadata { @@ -427,26 +447,7 @@ class ClassMetadataInfo implements ClassMetadata * Whether a unique constraint should be generated for the column. * * @var mixed[] - * @psalm-var array - * }> + * @psalm-var array */ public $fieldMappings = []; @@ -1285,18 +1286,7 @@ public function getColumnName($fieldName) * @param string $fieldName The field name. * * @return mixed[] The field mapping. - * @psalm-return array{ - * type: string, - * fieldName: string, - * columnName?: string, - * inherited?: class-string, - * nullable?: bool, - * originalClass?: class-string, - * originalField?: string, - * scale?: int, - * precision?: int, - * length?: int - * } + * @psalm-return FieldMapping * * @throws MappingException */ diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ecde6563d6c..ba2039fa06c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -575,21 +575,11 @@ parameters: count: 1 path: lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php - - - message: "#^Offset 'unique' on array\\{type\\: string, fieldName\\: string, columnName\\?\\: string, inherited\\?\\: class\\-string, nullable\\?\\: bool, originalClass\\?\\: class\\-string, originalField\\?\\: string, scale\\?\\: int, \\.\\.\\.\\} in isset\\(\\) does not exist\\.$#" - count: 1 - path: lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php - - message: "#^Parameter \\#2 \\$type of static method Doctrine\\\\ORM\\\\Mapping\\\\MappingException\\:\\:invalidInheritanceType\\(\\) expects string, int given\\.$#" count: 1 path: lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php - - - message: "#^Result of && is always false\\.$#" - count: 2 - path: lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php - - message: "#^Array \\(array\\\\) does not accept key string\\.$#" count: 1 @@ -2211,11 +2201,6 @@ parameters: count: 1 path: lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php - - - message: "#^Offset 'options' on array\\{type\\: string, fieldName\\: string, columnName\\?\\: string, length\\?\\: int, id\\?\\: bool, nullable\\?\\: bool, columnDefinition\\?\\: string, precision\\?\\: int, \\.\\.\\.\\} in isset\\(\\) always exists and is not nullable\\.$#" - count: 1 - path: lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php - - message: "#^Offset 'schema' on array\\{name\\: string, schema\\: string, indexes\\: array, uniqueConstraints\\: array, options\\: array\\, quoted\\?\\: bool\\} in isset\\(\\) always exists and is not nullable\\.$#" count: 1 @@ -2227,7 +2212,7 @@ parameters: path: lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php - - message: "#^Offset 'version' on array\\{type\\: string, fieldName\\: string, options\\: array, columnName\\?\\: string, length\\?\\: int, id\\?\\: bool, nullable\\?\\: bool, columnDefinition\\?\\: string, \\.\\.\\.\\} 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 @@ -2316,11 +2301,6 @@ parameters: count: 1 path: lib/Doctrine/ORM/Tools/SchemaTool.php - - - message: "#^Offset 'columnDefinition' on array\\{type\\: string, fieldName\\: string, columnName\\?\\: string, inherited\\?\\: class\\-string, nullable\\?\\: bool, originalClass\\?\\: class\\-string, originalField\\?\\: string, scale\\?\\: int, \\.\\.\\.\\} in isset\\(\\) does not exist\\.$#" - count: 1 - path: lib/Doctrine/ORM/Tools/SchemaTool.php - - message: "#^Offset 'indexes' on array\\{name\\: string, schema\\: string, indexes\\: array, uniqueConstraints\\: array, options\\: array\\, quoted\\?\\: bool\\} in isset\\(\\) always exists and is not nullable\\.$#" count: 1