Code Duplication    Length = 7-9 lines in 4 locations

Snapshot/SnapshotAggregateRepository.php 1 location

@@ 75-81 (lines=7) @@
72
     */
73
    public function persist($element)
74
    {
75
        if (!$element instanceof EventSourcedAggregateRootInterface) {
76
            throw new \InvalidArgumentException(sprintf(
77
                'The object must be an instance of %s. Instance of %s given',
78
                EventSourcedAggregateRootInterface::class,
79
                is_object($element) ? get_class($element) : gettype($element)
80
            ));
81
        }
82
83
        if ($this->snapshottingPolicy->shouldCreateSnapshot($element)) {
84
            $this->saveSnapshot($element);

AggregateRepository.php 2 locations

@@ 76-82 (lines=7) @@
73
     */
74
    public function persist($element)
75
    {
76
        if (!$element instanceof EventSourcedAggregateRootInterface) {
77
            throw new \InvalidArgumentException(sprintf(
78
                'The object must be an instance of %s. Instance of %s given',
79
                EventSourcedAggregateRootInterface::class,
80
                is_object($element) ? get_class($element) : gettype($element)
81
            ));
82
        }
83
84
        $this->saveHistory($element);
85
    }
@@ 102-108 (lines=7) @@
99
     */
100
    public function remove($element)
101
    {
102
        if (!$element instanceof EventSourcedAggregateRootInterface) {
103
            throw new \InvalidArgumentException(sprintf(
104
                'The object must be an instance of %s. Instance of %s given',
105
                EventSourcedAggregateRootInterface::class,
106
                is_object($element) ? get_class($element) : gettype($element)
107
            ));
108
        }
109
110
        DomainEventPublisher::publish(new PreRemoveEvent($element));
111

EventStore/EventStream.php 1 location

@@ 51-59 (lines=9) @@
48
        $this->aggregateId = $aggregateId;
49
50
        foreach ($events as $event) {
51
            if (!$event instanceof DomainEventInterface) {
52
                throw new \InvalidArgumentException(
53
                    sprintf(
54
                        'The event must be an instance of %s. Instance of %s given',
55
                        DomainEventInterface::class,
56
                        is_object($event) ? get_class($event) : gettype($event)
57
                    )
58
                );
59
            }
60
61
            $this->events[] = $event;
62
        }