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

Maps::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 4
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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 Maps 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 Map[]
14
     */
15
    public $items;
16
17
18 1
    protected function __construct(array $assets)
19
    {
20 1
        parent::__construct(Map::class, $assets);
21 1
    }
22
23 1
    public static function createFromArray(array $mapStats): self
24
    {
25 1
        Assert::notNull($mapStats);
26
27 1
        $createdAssets = [];
28 1
        foreach ($mapStats as $mapName => $map) {
29
            $createdAssets[] = Map::createFromArray($mapName, $map);
30
        }
31 1
        return new self($createdAssets);
32
    }
33
34
    /**
35
     * @return Traversable|Map[]
36
     */
37
    public function getIterator(): Traversable
38
    {
39
        return new ArrayIterator($this->items);
40
    }
41
}
42