Completed
Pull Request — master (#6)
by Peter
03:25 queued 31s
created

Champions::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
c 0
b 0
f 0
dl 10
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
3
namespace PtrTn\Battlerite\Dto\Player;
4
5
use ArrayIterator;
6
use PtrTn\Battlerite\Dto\CollectionDto;
7
use Traversable;
8
use Webmozart\Assert\Assert;
9
10 View Code Duplication
class Champions extends CollectionDto
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...
11
{
12
    /**
13
     * @var Champion[]
14
     */
15
    public $items;
16
17
18 1
    protected function __construct(array $assets)
19
    {
20 1
        parent::__construct(Champion::class, $assets);
21 1
    }
22
23 1
    public static function createFromArray(array $championStats): self
24
    {
25 1
        Assert::notNull($championStats);
26
27 1
        $createdAssets = [];
28 1
        foreach ($championStats as $championName => $champion) {
29 1
            $createdAssets[] = Champion::createFromArray($championName, $champion);
30
        }
31 1
        return new self($createdAssets);
32
    }
33
34
    /**
35
     * @return Traversable|Champion[]
36
     */
37
    public function getIterator(): Traversable
38
    {
39
        return new ArrayIterator($this->items);
40
    }
41
}
42