EventDataCollection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 96.88 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 5
lcom 1
cbo 1
dl 31
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 12 12 3
A count() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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