Passed
Push — master ( bdc105...ec8122 )
by Peter
01:57
created

Matches   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 35
loc 35
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A createFromArray() 10 10 2
A getIterator() 4 4 1
A count() 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\Matches;
4
5
use ArrayIterator;
6
use Countable;
7
use IteratorAggregate;
8
use Traversable;
9
use Webmozart\Assert\Assert;
10
11 View Code Duplication
class Matches 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 Match[]
15
     */
16
    public $matches;
17
18 5
    private function __construct(array $matches)
19
    {
20 5
        Assert::allIsInstanceOf($matches, Match::class);
21
22 5
        $this->matches = $matches;
23 5
    }
24
25 5
    public static function createFromArray(array $matches): self
26
    {
27 5
        Assert::notNull($matches);
28
29 5
        $createdMatches = [];
30 5
        foreach ($matches as $match) {
31 3
            $createdMatches[] = Match::createFromArray($match);
32
        }
33 5
        return new self($createdMatches);
34
    }
35
36 1
    public function getIterator(): Traversable
37
    {
38 1
        return new ArrayIterator($this->matches);
39
    }
40
41 2
    public function count(): int
42
    {
43 2
        return count($this->matches);
44
    }
45
}
46