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

Maps   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 3
dl 32
loc 32
ccs 8
cts 11
cp 0.7272
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A createFromArray() 10 10 2
A getIterator() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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