Skip to content

Commit

Permalink
PreUpdateEventArgs inherits from persistence PreUpdateEventArgs event
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Nov 20, 2023
1 parent ec9f131 commit 754fde3
Showing 1 changed file with 3 additions and 86 deletions.
89 changes: 3 additions & 86 deletions lib/Doctrine/ORM/Event/PreUpdateEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,96 +4,13 @@

namespace Doctrine\ORM\Event;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use InvalidArgumentException;

use function get_debug_type;
use function sprintf;
use Doctrine\Persistence\Event\PreUpdateEventArgs as BasePreUpdateEventArgs;

/**
* Class that holds event arguments for a preUpdate event.
*
* @extends LifecycleEventArgs<EntityManagerInterface>
* @extends PreUpdateEventArgs<EntityManagerInterface>
*/
class PreUpdateEventArgs extends LifecycleEventArgs
class PreUpdateEventArgs extends BasePreUpdateEventArgs

Check failure on line 14 in lib/Doctrine/ORM/Event/PreUpdateEventArgs.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (default, phpstan.neon)

The @extends tag of class Doctrine\ORM\Event\PreUpdateEventArgs describes Doctrine\ORM\Event\PreUpdateEventArgs but the class extends Doctrine\Persistence\Event\PreUpdateEventArgs.

Check failure on line 14 in lib/Doctrine/ORM/Event/PreUpdateEventArgs.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (default)

InvalidDocblock

lib/Doctrine/ORM/Event/PreUpdateEventArgs.php:14:1: InvalidDocblock: @template-extends must include the name of an extended class, got Doctrine\ORM\Event\PreUpdateEventArgs<Doctrine\ORM\Event\EntityManagerInterface> (see https://psalm.dev/008)

Check failure on line 14 in lib/Doctrine/ORM/Event/PreUpdateEventArgs.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (default)

MissingTemplateParam

lib/Doctrine/ORM/Event/PreUpdateEventArgs.php:14:7: MissingTemplateParam: Doctrine\ORM\Event\PreUpdateEventArgs has missing template params when extending Doctrine\Persistence\Event\PreUpdateEventArgs, expecting 1 (see https://psalm.dev/182)

Check failure on line 14 in lib/Doctrine/ORM/Event/PreUpdateEventArgs.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (3.7, phpstan-dbal3.neon)

The @extends tag of class Doctrine\ORM\Event\PreUpdateEventArgs describes Doctrine\ORM\Event\PreUpdateEventArgs but the class extends Doctrine\Persistence\Event\PreUpdateEventArgs.

Check failure on line 14 in lib/Doctrine/ORM/Event/PreUpdateEventArgs.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (3.7)

InvalidDocblock

lib/Doctrine/ORM/Event/PreUpdateEventArgs.php:14:1: InvalidDocblock: @template-extends must include the name of an extended class, got Doctrine\ORM\Event\PreUpdateEventArgs<Doctrine\ORM\Event\EntityManagerInterface> (see https://psalm.dev/008)

Check failure on line 14 in lib/Doctrine/ORM/Event/PreUpdateEventArgs.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (3.7)

MissingTemplateParam

lib/Doctrine/ORM/Event/PreUpdateEventArgs.php:14:7: MissingTemplateParam: Doctrine\ORM\Event\PreUpdateEventArgs has missing template params when extending Doctrine\Persistence\Event\PreUpdateEventArgs, expecting 1 (see https://psalm.dev/182)
{
/** @var array<string, array{mixed, mixed}> */
private array $entityChangeSet;

/**
* @param mixed[][] $changeSet
* @psalm-param array<string, array{mixed, mixed}> $changeSet
*/
public function __construct(object $entity, EntityManagerInterface $em, array &$changeSet)
{
parent::__construct($entity, $em);

$this->entityChangeSet = &$changeSet;
}

/**
* Retrieves entity changeset.
*
* @return mixed[][]
* @psalm-return array<string, array{mixed, mixed}>
*/
public function getEntityChangeSet(): array
{
return $this->entityChangeSet;
}

/**
* Checks if field has a changeset.
*/
public function hasChangedField(string $field): bool
{
return isset($this->entityChangeSet[$field]);
}

/**
* Gets the old value of the changeset of the changed field.
*/
public function getOldValue(string $field): mixed
{
$this->assertValidField($field);

return $this->entityChangeSet[$field][0];
}

/**
* Gets the new value of the changeset of the changed field.
*/
public function getNewValue(string $field): mixed
{
$this->assertValidField($field);

return $this->entityChangeSet[$field][1];
}

/**
* Sets the new value of this field.
*/
public function setNewValue(string $field, mixed $value): void
{
$this->assertValidField($field);

$this->entityChangeSet[$field][1] = $value;
}

/**
* Asserts the field exists in changeset.
*
* @throws InvalidArgumentException
*/
private function assertValidField(string $field): void
{
if (! isset($this->entityChangeSet[$field])) {
throw new InvalidArgumentException(sprintf(
'Field "%s" is not a valid field of the entity "%s" in PreUpdateEventArgs.',
$field,
get_debug_type($this->getObject()),
));
}
}
}

0 comments on commit 754fde3

Please sign in to comment.