From 2ea6a1a5fb0ad61906b32632057ce7f996312b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 19 Jun 2024 21:45:34 +0200 Subject: [PATCH 1/4] Remove unneeded CS rule --- phpcs.xml.dist | 1 - src/Mapping/InverseJoinColumn.php | 1 - 2 files changed, 2 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 6de9ebe57a2..fa28a585b6e 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -14,7 +14,6 @@ src tests - */src/Mapping/InverseJoinColumn.php */tests/Tests/Proxies/__CG__* */tests/Tests/ORM/Tools/Export/export/* diff --git a/src/Mapping/InverseJoinColumn.php b/src/Mapping/InverseJoinColumn.php index 89c8db0006b..2a77f3fc73b 100644 --- a/src/Mapping/InverseJoinColumn.php +++ b/src/Mapping/InverseJoinColumn.php @@ -2,7 +2,6 @@ declare(strict_types=1); - namespace Doctrine\ORM\Mapping; use Attribute; From c06f6b93761a12380e57d5d241eb0d6e22a0d3df Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 20 Jun 2024 09:08:10 +0200 Subject: [PATCH 2/4] Add the propoer void return type on the __load method of proxies When using ghost objects, the method was leaking a `static` return type due to the way it was implemented, which is incompatible with the native return type that will be added in doctrine/persistence v4. --- src/Proxy/ProxyFactory.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Proxy/ProxyFactory.php b/src/Proxy/ProxyFactory.php index b5426a014e4..b2d114a6698 100644 --- a/src/Proxy/ProxyFactory.php +++ b/src/Proxy/ProxyFactory.php @@ -387,12 +387,18 @@ private function generateUseLazyGhostTrait(ClassMetadata $class): string $code = substr($code, 7 + (int) strpos($code, "\n{")); $code = substr($code, 0, (int) strpos($code, "\n}")); $code = str_replace('LazyGhostTrait;', str_replace("\n ", "\n", 'LazyGhostTrait { - initializeLazyObject as __load; + initializeLazyObject as private; setLazyObjectAsInitialized as public __setInitialized; isLazyObjectInitialized as private; createLazyGhost as private; resetLazyObject as private; - }'), $code); + } + + public function __load(): void + { + $this->initializeLazyObject(); + } + '), $code); return $code; } From 77467cd824091102cf8f82a9ff582c474d312ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 20 Jun 2024 21:47:54 +0200 Subject: [PATCH 3/4] Address doctrine/persistence 3.3.3 release FileDriver became templatable, and some very wrong phpdoc has been fixed, causing Psalm to better understand the 2 FileDriver classes in this project. --- phpstan-dbal2.neon | 6 ++++ phpstan-persistence2.neon | 6 ++++ psalm-baseline.xml | 47 ------------------------------- src/Mapping/Driver/XmlDriver.php | 5 +++- src/Mapping/Driver/YamlDriver.php | 2 ++ 5 files changed, 18 insertions(+), 48 deletions(-) diff --git a/phpstan-dbal2.neon b/phpstan-dbal2.neon index 31f0f2823ab..98cba7badc1 100644 --- a/phpstan-dbal2.neon +++ b/phpstan-dbal2.neon @@ -74,3 +74,9 @@ parameters: - message: '#^Call to method injectObjectManager\(\) on an unknown class Doctrine\\Persistence\\ObjectManagerAware\.$#' path: src/UnitOfWork.php + + - + message: '#contains generic type.*but class.*is not generic#' + paths: + - src/Mapping/Driver/XmlDriver.php + - src/Mapping/Driver/YamlDriver.php diff --git a/phpstan-persistence2.neon b/phpstan-persistence2.neon index dfa68ac9ec8..931876129c3 100644 --- a/phpstan-persistence2.neon +++ b/phpstan-persistence2.neon @@ -64,3 +64,9 @@ parameters: # Symfony cache supports passing a key prefix to the clear method. - '/^Method Psr\\Cache\\CacheItemPoolInterface\:\:clear\(\) invoked with 1 parameter, 0 required\.$/' + + - + message: '#contains generic type.*but class.*is not generic#' + paths: + - src/Mapping/Driver/XmlDriver.php + - src/Mapping/Driver/YamlDriver.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 2be2ff0b8c3..b9473bebb66 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -932,13 +932,8 @@ table]]> - - {'discriminator-column'}]]> - {'discriminator-map'}]]> - - $usage, 'region' => $region, @@ -962,7 +957,6 @@ * options?: array * }]]> - @@ -971,15 +965,6 @@ - - {'discriminator-column'}]]> - {'discriminator-map'}]]> - - - getName() === 'embeddable']]> - getName() === 'entity']]> - getName() === 'mapped-superclass']]> - @@ -1011,38 +996,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Mapping/Driver/XmlDriver.php b/src/Mapping/Driver/XmlDriver.php index 60223020dc9..c993a2ba794 100644 --- a/src/Mapping/Driver/XmlDriver.php +++ b/src/Mapping/Driver/XmlDriver.php @@ -37,6 +37,8 @@ * XmlDriver is a metadata driver that enables mapping through XML files. * * @link www.doctrine-project.org + * + * @template-extends FileDriver */ class XmlDriver extends FileDriver { @@ -79,7 +81,6 @@ public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENS public function loadMetadataForClass($className, PersistenceClassMetadata $metadata) { $xmlRoot = $this->getElement($className); - assert($xmlRoot instanceof SimpleXMLElement); if ($xmlRoot->getName() === 'entity') { if (isset($xmlRoot['repository-class'])) { @@ -203,6 +204,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad ]; if (isset($discrColumn['options'])) { + assert($discrColumn['options'] instanceof SimpleXMLElement); $columnDef['options'] = $this->parseOptions($discrColumn['options']->children()); } @@ -214,6 +216,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad // Evaluate if (isset($xmlRoot->{'discriminator-map'})) { $map = []; + assert($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} instanceof SimpleXMLElement); foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) { $map[(string) $discrMapElement['value']] = (string) $discrMapElement['class']; } diff --git a/src/Mapping/Driver/YamlDriver.php b/src/Mapping/Driver/YamlDriver.php index c6ff83e0f17..5e24b0b3a45 100644 --- a/src/Mapping/Driver/YamlDriver.php +++ b/src/Mapping/Driver/YamlDriver.php @@ -31,6 +31,8 @@ * The YamlDriver reads the mapping metadata from yaml schema files. * * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement + * + * @template-extends FileDriver> */ class YamlDriver extends FileDriver { From 1153b9468ccfef452625064c66b4a135d0ea8a46 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Fri, 21 Jun 2024 13:31:45 +0200 Subject: [PATCH 4/4] Fix deprecated array access usage (#11517) --- src/Persisters/Collection/OneToManyPersister.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Persisters/Collection/OneToManyPersister.php b/src/Persisters/Collection/OneToManyPersister.php index 7354daa5627..0727b1f8a7e 100644 --- a/src/Persisters/Collection/OneToManyPersister.php +++ b/src/Persisters/Collection/OneToManyPersister.php @@ -174,9 +174,9 @@ private function deleteEntityCollection(PersistentCollection $collection): int if ($targetClass->isInheritanceTypeSingleTable()) { $discriminatorColumn = $targetClass->getDiscriminatorColumn(); - $statement .= ' AND ' . $discriminatorColumn['name'] . ' = ?'; + $statement .= ' AND ' . $discriminatorColumn->name . ' = ?'; $parameters[] = $targetClass->discriminatorValue; - $types[] = $discriminatorColumn['type']; + $types[] = $discriminatorColumn->type; } $numAffected = $this->conn->executeStatement($statement, $parameters, $types);