Completed
Pull Request — master (#3)
by Peter
06:35 queued 01:32
created

Rosters   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 43.75%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 41
ccs 7
cts 16
cp 0.4375
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createFromArray() 0 10 2
A getIterator() 0 4 1
A getWinningParticipants() 0 9 3
1
<?php
2
3
namespace PtrTn\Battlerite\Dto\Match;
4
5
use ArrayIterator;
6
use PtrTn\Battlerite\Dto\CollectionDto;
7
use RuntimeException;
8
use Traversable;
9
use Webmozart\Assert\Assert;
10
11
class Rosters extends CollectionDto
12
{
13
    /**
14
     * @var Roster[]
15
     */
16
    public $items;
17
18 4
    public function __construct(array $rosters)
19
    {
20 4
        parent::__construct(Roster::class, $rosters);
21 4
    }
22
23
    public static function createFromArray(array $rosters): self
24
    {
25
        Assert::notNull($rosters);
26
27
        $createdRosters = [];
28
        foreach ($rosters as $roster) {
29
            $createdRosters[] = Roster::createFromArray($roster);
30
        }
31
        return new self($createdRosters);
32
    }
33
34
    /**
35
     * @return Traversable|Roster[]
36
     */
37
    public function getIterator(): Traversable
38
    {
39
        return new ArrayIterator($this->items);
40
    }
41
42 2
    public function getWinningParticipants(): References
43
    {
44 2
        foreach ($this->items as $roster) {
45 2
            if ($roster->won === true) {
46 2
                return $roster->participants;
47
            }
48
        }
49
        throw new RuntimeException('Invalid data, match should always have a victor');
50
    }
51
}
52