Code Duplication    Length = 33-41 lines in 2 locations

src/Command/AbstractCommand.php 1 location

@@ 20-60 (lines=41) @@
17
 * rely on user data without checking their input.
18
 * It will be the responsibility of the Aggregate to validate the data coming from the Command.
19
 */
20
abstract class AbstractCommand
21
{
22
    use PopulatePropertiesTrait;
23
24
    /**
25
     * List of aggregate root impacted by this command.
26
     * This should be set by the CommandHandler when it get all the aggregate roots according to the command's data.
27
     * You'll probably manage only one aggregate root per command. It's an array just in case you need more.
28
     *
29
     * See CommandHandler for more details on the purpose of this.
30
     *
31
     * @var AbstractAggregateRoot[]
32
     */
33
    public $aggregateRoots = [];
34
35
    /**
36
     * The command requester.
37
     * We use the same object type (Author) as for an event in order to keep the track of the Command Requester
38
     * in the Event ($author).
39
     *
40
     * @var Author
41
     */
42
    public $requester;
43
44
    /**
45
     * @param array $data An array ['propertyName' => 'value', ...]
46
     */
47
    public function __construct(array $data = [])
48
    {
49
        $data['requester'] = isset($data['requester']) ? $data['requester'] : Author::robot();
50
        $this->populate($data);
51
    }
52
53
    /**
54
     * @param AbstractAggregateRoot $abstractAggregateRoot
55
     */
56
    public function addAggregateRoot(AbstractAggregateRoot $abstractAggregateRoot)
57
    {
58
        $this->aggregateRoots[] = $abstractAggregateRoot;
59
    }
60
}
61

src/Event/AbstractEvent.php 1 location

@@ 14-46 (lines=33) @@
11
/**
12
 * Base class for every event.
13
 */
14
abstract class AbstractEvent implements Serializable
15
{
16
    use PopulatePropertiesTrait;
17
18
    /**
19
     * Get the aggregate root from which is the event is triggered.
20
     *
21
     * @var AbstractAggregateRoot
22
     */
23
    public $aggregateRoot;
24
25
    /**
26
     * @var Author
27
     */
28
    public $author;
29
30
    /**
31
     * @var DateTime
32
     */
33
    public $date;
34
35
    /**
36
     * @param array $data The list of properties values. The key represent the property name.
37
     */
38
    public function __construct(array $data = [])
39
    {
40
        // Enforce the date property to be set.
41
        // Should not rely on the one given by the user.
42
        $data['date']   = new DateTime();
43
        $data['author'] = isset($data['author']) ? $data['author'] : Author::robot();
44
        $this->populate($data);
45
    }
46
}
47