cubiche /
event-publisher
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of the Cubiche package. |
||
| 4 | * |
||
| 5 | * Copyright (c) Cubiche |
||
| 6 | * |
||
| 7 | * For the full copyright and license information, please view the LICENSE |
||
| 8 | * file that was distributed with this source code. |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace Cubiche\Domain\EventPublisher; |
||
| 12 | |||
| 13 | use Cubiche\Core\EventBus\Event\Event; |
||
| 14 | use DateTime; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * DomainEvent class. |
||
| 18 | * |
||
| 19 | * @author Ivannis Suárez Jerez <[email protected]> |
||
| 20 | */ |
||
| 21 | class DomainEvent extends Event implements DomainEventInterface |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var array |
||
| 25 | */ |
||
| 26 | private $metadata = []; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var array |
||
| 30 | */ |
||
| 31 | private $payload = []; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * DomainEvent constructor. |
||
| 35 | * |
||
| 36 | * @param string|null $eventName |
||
| 37 | */ |
||
| 38 | public function __construct($eventName = null) |
||
| 39 | { |
||
| 40 | parent::__construct($eventName); |
||
| 41 | |||
| 42 | $this->setMetadata('occurredOn', new DateTime()); |
||
| 43 | $this->setMetadata('eventType', parent::eventName()); |
||
|
0 ignored issues
–
show
|
|||
| 44 | $this->setMetadata('propagationStopped', parent::isPropagationStopped()); |
||
|
0 ignored issues
–
show
It seems like you call parent on a different method (
isPropagationStopped() instead of __construct()). Are you sure this is correct? If so, you might want to change this to $this->isPropagationStopped().
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The Loading history...
|
|||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @return DateTime |
||
| 49 | */ |
||
| 50 | public function occurredOn() |
||
| 51 | { |
||
| 52 | return $this->getMetadata('occurredOn'); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * {@inheritdoc} |
||
| 57 | */ |
||
| 58 | public function eventName() |
||
| 59 | { |
||
| 60 | return $this->getMetadata('eventType'); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | public function stopPropagation() |
||
| 67 | { |
||
| 68 | $this->setMetadata('propagationStopped', true); |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * {@inheritdoc} |
||
| 73 | */ |
||
| 74 | public function isPropagationStopped() |
||
| 75 | { |
||
| 76 | return $this->getMetadata('propagationStopped'); |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param string $property |
||
| 81 | * @param mixed $value |
||
| 82 | */ |
||
| 83 | protected function setMetadata($property, $value) |
||
| 84 | { |
||
| 85 | $this->metadata[$property] = $value; |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @param string $property |
||
| 90 | * |
||
| 91 | * @return mixed |
||
| 92 | */ |
||
| 93 | protected function getMetadata($property) |
||
| 94 | { |
||
| 95 | return $this->metadata[$property]; |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param string $property |
||
| 100 | * @param mixed $value |
||
| 101 | */ |
||
| 102 | protected function setPayload($property, $value) |
||
| 103 | { |
||
| 104 | $this->payload[$property] = $value; |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @param string $property |
||
| 109 | * |
||
| 110 | * @return mixed |
||
| 111 | */ |
||
| 112 | protected function getPayload($property) |
||
| 113 | { |
||
| 114 | return $this->payload[$property]; |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * {@inheritdoc} |
||
| 119 | */ |
||
| 120 | public static function fromArray(array $data) |
||
| 121 | { |
||
| 122 | $reflectionClass = new \ReflectionClass(static::class); |
||
| 123 | |||
| 124 | /** @var DomainEvent $domainEvent */ |
||
| 125 | $domainEvent = $reflectionClass->newInstanceWithoutConstructor(); |
||
| 126 | $domainEvent->metadata = $data['metadata']; |
||
| 127 | $domainEvent->payload = $data['payload']; |
||
| 128 | |||
| 129 | return $domainEvent; |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * {@inheritdoc} |
||
| 134 | */ |
||
| 135 | public function toArray() |
||
| 136 | { |
||
| 137 | return array( |
||
| 138 | 'metadata' => $this->metadata, |
||
| 139 | 'payload' => $this->payload, |
||
| 140 | ); |
||
| 141 | } |
||
| 142 | } |
||
| 143 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.