Completed
Push — master ( 739f04...c64576 )
by Peter
01:52
created

Participants::createFromArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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