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

Rosters   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 69.23%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 33
loc 33
ccs 9
cts 13
cp 0.6923
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A createFromArray() 8 8 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 Rosters 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 Roster[]
15
     */
16
    public $rosters;
17
18 3
    public function __construct(array $rosters)
19
    {
20 3
        Assert::allIsInstanceOf($rosters, Roster::class);
21
22 3
        $this->rosters = $rosters;
23 3
    }
24
25 3
    public static function createFromArray(array $rosters): self
26
    {
27 3
        $createdRosters = [];
28 3
        foreach ($rosters as $roster) {
29 3
            $createdRosters[] = Roster::createFromArray($roster);
30
        }
31 3
        return new self($createdRosters);
32
    }
33
34
    public function getIterator(): Traversable
35
    {
36
        return new ArrayIterator($this->rosters);
37
    }
38
39
    public function count(): int
40
    {
41
        return count($this->rosters);
42
    }
43
}
44