Passed
Push — master ( bdc105...ec8122 )
by Peter
01:57
created

Spectators::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace PtrTn\Battlerite\Dto\Match;
4
5
use ArrayIterator;
6
use Countable;
7
use IteratorAggregate;
8
use Traversable;
9
use Webmozart\Assert\Assert;
10
11 View Code Duplication
class Spectators implements IteratorAggregate, 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...
12
{
13
    /**
14
     * @var Spectator[]
15
     */
16
    public $spectators;
17
18 1
    private function __construct(array $spectators)
19
    {
20 1
        Assert::allIsInstanceOf($spectators, Spectator::class);
21
22 1
        $this->spectators = $spectators;
23 1
    }
24
25 1
    public static function createFromArray(array $spectators): self
26
    {
27 1
        $createdSpectators = [];
28 1
        foreach ($spectators as $spectator) {
29
            $createdSpectators[] = Spectator::createFromArray($spectator);
30
        }
31 1
        return new self($createdSpectators);
32
    }
33
34
    public function getIterator(): Traversable
35
    {
36
        return new ArrayIterator($this->spectators);
37
    }
38
39
    public function count(): int
40
    {
41
        return count($this->spectators);
42
    }
43
}
44