EventDataCollection::count()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %
Metric Value
dl 8
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace RayRutjes\GetEventStore;
4
5
use RayRutjes\GetEventStore\Util\InternalIterator;
6
7 View Code Duplication
final class EventDataCollection extends InternalIterator implements \Iterator, \Countable
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    /**
10
     * @param array $events
11
     *
12
     * @return EventDataCollection
13
     */
14
    public static function fromArray(array $events = []): EventDataCollection
15
    {
16
        $indexed = [];
17
        foreach ($events as $event) {
18
            if (!$event instanceof EventData) {
19
                throw new \InvalidArgumentException(sprintf('Invalid EventData, got: %s', get_class($event)));
20
            }
21
            $indexed[] = $event;
22
        }
23
24
        return new self(new \ArrayIterator($indexed));
25
    }
26
27
    /**
28
     * @return int
29
     */
30
    public function count()
31
    {
32
        if ($this->iterator instanceof \Countable) {
33
            return $this->iterator->count();
34
        }
35
36
        return 0;
37
    }
38
}
39