diff --git a/composer.json b/composer.json index 14646162ad9..866a8a09cc3 100644 --- a/composer.json +++ b/composer.json @@ -42,14 +42,14 @@ "doctrine/annotations": "^1.13 || ^2", "doctrine/coding-standard": "^9.0.2 || ^12.0", "phpbench/phpbench": "^0.16.10 || ^1.0", - "phpstan/phpstan": "~1.4.10 || 1.10.28", + "phpstan/phpstan": "~1.4.10 || 1.10.35", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.6", "psr/log": "^1 || ^2 || ^3", "squizlabs/php_codesniffer": "3.7.2", "symfony/cache": "^4.4 || ^5.4 || ^6.0", "symfony/var-exporter": "^4.4 || ^5.4 || ^6.2", "symfony/yaml": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "vimeo/psalm": "4.30.0 || 5.14.1" + "vimeo/psalm": "4.30.0 || 5.15.0" }, "conflict": { "doctrine/annotations": "<1.13 || >= 3.0" diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 827ef873b5a..82ad11a2981 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -128,7 +128,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad // Evaluate named queries if (isset($xmlRoot->{'named-queries'})) { - foreach ($xmlRoot->{'named-queries'}->{'named-query'} as $namedQueryElement) { + foreach ($xmlRoot->{'named-queries'}->{'named-query'} ?? [] as $namedQueryElement) { $metadata->addNamedQuery( [ 'name' => (string) $namedQueryElement['name'], @@ -140,7 +140,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad // Evaluate native named queries if (isset($xmlRoot->{'named-native-queries'})) { - foreach ($xmlRoot->{'named-native-queries'}->{'named-native-query'} as $nativeQueryElement) { + foreach ($xmlRoot->{'named-native-queries'}->{'named-native-query'} ?? [] as $nativeQueryElement) { $metadata->addNamedNativeQuery( [ 'name' => isset($nativeQueryElement['name']) ? (string) $nativeQueryElement['name'] : null, @@ -154,7 +154,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad // Evaluate sql result set mapping if (isset($xmlRoot->{'sql-result-set-mappings'})) { - foreach ($xmlRoot->{'sql-result-set-mappings'}->{'sql-result-set-mapping'} as $rsmElement) { + foreach ($xmlRoot->{'sql-result-set-mappings'}->{'sql-result-set-mapping'} ?? [] as $rsmElement) { $entities = []; $columns = []; foreach ($rsmElement as $entityElement) { @@ -240,7 +240,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad // Evaluate if (isset($xmlRoot->indexes)) { $metadata->table['indexes'] = []; - foreach ($xmlRoot->indexes->index as $indexXml) { + foreach ($xmlRoot->indexes->index ?? [] as $indexXml) { $index = []; if (isset($indexXml['columns']) && ! empty($indexXml['columns'])) { @@ -283,7 +283,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad // Evaluate if (isset($xmlRoot->{'unique-constraints'})) { $metadata->table['uniqueConstraints'] = []; - foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $uniqueXml) { + foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} ?? [] as $uniqueXml) { $unique = []; if (isset($uniqueXml['columns']) && ! empty($uniqueXml['columns'])) { @@ -370,7 +370,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad // Evaluate mappings $associationIds = []; - foreach ($xmlRoot->id as $idElement) { + foreach ($xmlRoot->id ?? [] as $idElement) { if (isset($idElement['association-key']) && $this->evaluateBoolean($idElement['association-key'])) { $associationIds[(string) $idElement['name']] = true; continue; @@ -439,7 +439,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad if (isset($oneToOneElement->{'join-column'})) { $joinColumns[] = $this->joinColumnToArray($oneToOneElement->{'join-column'}); } elseif (isset($oneToOneElement->{'join-columns'})) { - foreach ($oneToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { + foreach ($oneToOneElement->{'join-columns'}->{'join-column'} ?? [] as $joinColumnElement) { $joinColumns[] = $this->joinColumnToArray($joinColumnElement); } } @@ -490,7 +490,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad if (isset($oneToManyElement->{'order-by'})) { $orderBy = []; - foreach ($oneToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) { + foreach ($oneToManyElement->{'order-by'}->{'order-by-field'} ?? [] as $orderByField) { $orderBy[(string) $orderByField['name']] = isset($orderByField['direction']) ? (string) $orderByField['direction'] : Criteria::ASC; @@ -542,7 +542,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad if (isset($manyToOneElement->{'join-column'})) { $joinColumns[] = $this->joinColumnToArray($manyToOneElement->{'join-column'}); } elseif (isset($manyToOneElement->{'join-columns'})) { - foreach ($manyToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { + foreach ($manyToOneElement->{'join-columns'}->{'join-column'} ?? [] as $joinColumnElement) { $joinColumns[] = $this->joinColumnToArray($joinColumnElement); } } @@ -601,11 +601,11 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad $joinTable['options'] = $this->parseOptions($joinTableElement->options->children()); } - foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { + foreach ($joinTableElement->{'join-columns'}->{'join-column'} ?? [] as $joinColumnElement) { $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement); } - foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} as $joinColumnElement) { + foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} ?? [] as $joinColumnElement) { $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement); } @@ -618,7 +618,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad if (isset($manyToManyElement->{'order-by'})) { $orderBy = []; - foreach ($manyToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) { + foreach ($manyToManyElement->{'order-by'}->{'order-by-field'} ?? [] as $orderByField) { $orderBy[(string) $orderByField['name']] = isset($orderByField['direction']) ? (string) $orderByField['direction'] : Criteria::ASC; @@ -644,9 +644,9 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad // Evaluate association-overrides if (isset($xmlRoot->{'attribute-overrides'})) { - foreach ($xmlRoot->{'attribute-overrides'}->{'attribute-override'} as $overrideElement) { + foreach ($xmlRoot->{'attribute-overrides'}->{'attribute-override'} ?? [] as $overrideElement) { $fieldName = (string) $overrideElement['name']; - foreach ($overrideElement->field as $field) { + foreach ($overrideElement->field ?? [] as $field) { $mapping = $this->columnToArray($field); $mapping['fieldName'] = $fieldName; $metadata->setAttributeOverride($fieldName, $mapping); @@ -656,14 +656,14 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad // Evaluate association-overrides if (isset($xmlRoot->{'association-overrides'})) { - foreach ($xmlRoot->{'association-overrides'}->{'association-override'} as $overrideElement) { + foreach ($xmlRoot->{'association-overrides'}->{'association-override'} ?? [] as $overrideElement) { $fieldName = (string) $overrideElement['name']; $override = []; // Check for join-columns if (isset($overrideElement->{'join-columns'})) { $joinColumns = []; - foreach ($overrideElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { + foreach ($overrideElement->{'join-columns'}->{'join-column'} ?? [] as $joinColumnElement) { $joinColumns[] = $this->joinColumnToArray($joinColumnElement); } @@ -685,13 +685,13 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad } if (isset($joinTableElement->{'join-columns'})) { - foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { + foreach ($joinTableElement->{'join-columns'}->{'join-column'} ?? [] as $joinColumnElement) { $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement); } } if (isset($joinTableElement->{'inverse-join-columns'})) { - foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} as $joinColumnElement) { + foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} ?? [] as $joinColumnElement) { $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement); } } @@ -715,14 +715,14 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad // Evaluate if (isset($xmlRoot->{'lifecycle-callbacks'})) { - foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) { + foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} ?? [] as $lifecycleCallback) { $metadata->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\ORM\Events::' . (string) $lifecycleCallback['type'])); } } // Evaluate entity listener if (isset($xmlRoot->{'entity-listeners'})) { - foreach ($xmlRoot->{'entity-listeners'}->{'entity-listener'} as $listenerElement) { + foreach ($xmlRoot->{'entity-listeners'}->{'entity-listener'} ?? [] as $listenerElement) { $className = (string) $listenerElement['class']; // Evaluate the listener using naming convention. if ($listenerElement->count() === 0) { @@ -744,16 +744,14 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad /** * Parses (nested) option elements. * - * @param SimpleXMLElement $options The XML element. - * * @return mixed[] The options array. * @psalm-return array|bool|string> */ - private function parseOptions(SimpleXMLElement $options): array + private function parseOptions(?SimpleXMLElement $options): array { $array = []; - foreach ($options as $option) { + foreach ($options ?? [] as $option) { if ($option->count()) { $value = $this->parseOptions($option->children()); } else { @@ -816,7 +814,7 @@ private function joinColumnToArray(SimpleXMLElement $joinColumnElement): array } if (isset($joinColumnElement['options'])) { - $joinColumn['options'] = $this->parseOptions($joinColumnElement['options']->children()); + $joinColumn['options'] = $this->parseOptions($joinColumnElement['options'] ? $joinColumnElement['options']->children() : null); } return $joinColumn; @@ -972,19 +970,19 @@ protected function loadMappingFile($file) if (isset($xmlElement->entity)) { foreach ($xmlElement->entity as $entityElement) { - /** @psalm-var class-string */ + /** @psalm-var class-string $entityName */ $entityName = (string) $entityElement['name']; $result[$entityName] = $entityElement; } } elseif (isset($xmlElement->{'mapped-superclass'})) { foreach ($xmlElement->{'mapped-superclass'} as $mappedSuperClass) { - /** @psalm-var class-string */ + /** @psalm-var class-string $className */ $className = (string) $mappedSuperClass['name']; $result[$className] = $mappedSuperClass; } } elseif (isset($xmlElement->embeddable)) { foreach ($xmlElement->embeddable as $embeddableElement) { - /** @psalm-var class-string */ + /** @psalm-var class-string $embeddableName */ $embeddableName = (string) $embeddableElement['name']; $result[$embeddableName] = $embeddableElement; } diff --git a/psalm-baseline.xml b/psalm-baseline.xml index fd8707f0806..1414b70c24d 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + IterableResult @@ -916,13 +916,12 @@ table]]> - options]]> - options]]> {'discriminator-column'}]]> {'discriminator-map'}]]> $mapping + $result $usage, 'region' => $region, @@ -946,6 +945,7 @@ * options?: array * } array{usage: int|null, region?: string} + loadMappingFile $fileExtension @@ -955,15 +955,9 @@ $metadata - options]]> - options]]> {'discriminator-column'}]]> {'discriminator-map'}]]> - - children()]]> - children()]]> - getName() === 'embeddable']]> getName() === 'entity']]> @@ -2557,9 +2551,6 @@ $_extension - - asXML()]]> -