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

Matches::createFromArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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