Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leverage generic persistence event classes #9633

Merged
merged 1 commit into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Event/LifecycleEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Lifecycle Events are triggered by the UnitOfWork during lifecycle transitions
* of entities.
*
* @link www.doctrine-project.org
* @extends BaseLifecycleEventArgs<EntityManagerInterface>
*/
class LifecycleEventArgs extends BaseLifecycleEventArgs
{
Expand Down
3 changes: 1 addition & 2 deletions lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
/**
* Class that holds event arguments for a loadMetadata event.
*
* @method __construct(ClassMetadata $classMetadata, EntityManagerInterface $objectManager)
* @method ClassMetadata getClassMetadata()
* @extends BaseLoadClassMetadataEventArgs<ClassMetadata<object>, EntityManagerInterface>
*/
class LoadClassMetadataEventArgs extends BaseLoadClassMetadataEventArgs
{
Expand Down
6 changes: 5 additions & 1 deletion lib/Doctrine/ORM/Event/OnClassMetadataNotFoundEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\ORM\Event;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\ManagerEventArgs;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
Expand All @@ -13,6 +14,8 @@
*
* This object is mutable by design, allowing callbacks having access to it to set the
* found metadata in it, and therefore "cancelling" a `onClassMetadataNotFound` event
*
* @extends ManagerEventArgs<EntityManagerInterface>
*/
class OnClassMetadataNotFoundEventArgs extends ManagerEventArgs
{
Expand All @@ -23,7 +26,8 @@ class OnClassMetadataNotFoundEventArgs extends ManagerEventArgs
private $foundMetadata;

/**
* @param string $className
* @param string $className
* @param EntityManagerInterface $objectManager
*/
public function __construct($className, ObjectManager $objectManager)
{
Expand Down
11 changes: 1 addition & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,6 @@ parameters:
count: 1
path: lib/Doctrine/ORM/EntityRepository.php

-
message: "#^Method Doctrine\\\\ORM\\\\Event\\\\LifecycleEventArgs\\:\\:getEntityManager\\(\\) should return Doctrine\\\\ORM\\\\EntityManagerInterface but returns Doctrine\\\\Persistence\\\\ObjectManager\\.$#"
count: 1
path: lib/Doctrine/ORM/Event/LifecycleEventArgs.php

-
message: "#^Method Doctrine\\\\ORM\\\\Event\\\\LoadClassMetadataEventArgs\\:\\:getEntityManager\\(\\) should return Doctrine\\\\ORM\\\\EntityManagerInterface but returns Doctrine\\\\Persistence\\\\ObjectManager\\.$#"
count: 1
path: lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php

-
message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Platforms\\\\AbstractPlatform\\:\\:getTableHiLoCurrentValSql\\(\\)\\.$#"
count: 1
Expand Down Expand Up @@ -1744,3 +1734,4 @@ parameters:
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$subClasses\\.$#"
count: 1
path: lib/Doctrine/ORM/Utility/HierarchyDiscriminatorResolver.php

22 changes: 6 additions & 16 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -346,22 +346,6 @@
<code>find</code>
</TooManyArguments>
</file>
<file src="lib/Doctrine/ORM/Event/LifecycleEventArgs.php">
<LessSpecificReturnStatement occurrences="1">
<code>$this-&gt;getObjectManager()</code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType occurrences="1">
<code>EntityManagerInterface</code>
</MoreSpecificReturnType>
</file>
<file src="lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php">
<LessSpecificReturnStatement occurrences="1">
<code>$this-&gt;getObjectManager()</code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType occurrences="1">
<code>EntityManagerInterface</code>
</MoreSpecificReturnType>
</file>
<file src="lib/Doctrine/ORM/Event/OnClassMetadataNotFoundEventArgs.php">
<RedundantCastGivenDocblockType occurrences="1">
<code>(string) $className</code>
Expand Down Expand Up @@ -2662,6 +2646,12 @@
</RedundantConditionGivenDocblockType>
</file>
<file src="lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php">
<InvalidReturnStatement occurrences="1">
<code>$this-&gt;repositoryList[$repositoryHash] = $this-&gt;createRepository($entityManager, $entityName)</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="1">
<code>ObjectRepository</code>
</InvalidReturnType>
<TypeDoesNotContainType occurrences="1">
<code>$repository instanceof EntityRepository</code>
</TypeDoesNotContainType>
Expand Down
6 changes: 2 additions & 4 deletions tests/Doctrine/Tests/EventListener/CacheMetadataListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
namespace Doctrine\Tests\EventListener;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;

use function assert;
use function strstr;

class CacheMetadataListener
Expand All @@ -26,8 +25,7 @@ class CacheMetadataListener
public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
{
$metadata = $event->getClassMetadata();
assert($metadata instanceof ClassMetadata);
$em = $event->getObjectManager();
$em = $event->getObjectManager();

if (strstr($metadata->name, 'Doctrine\Tests\Models\Cache')) {
return;
Expand Down