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

Participants   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 28.57%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 35
loc 35
ccs 4
cts 14
cp 0.2857
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\Match;
4
5
use ArrayIterator;
6
use Countable;
7
use IteratorAggregate;
8
use Traversable;
9
use Webmozart\Assert\Assert;
10
11 View Code Duplication
class Participants 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 Participant[]
15
     */
16
    public $participants;
17
18 1
    public function __construct(array $participants)
19
    {
20 1
        Assert::allIsInstanceOf($participants, Participant::class);
21
22 1
        $this->participants = $participants;
23 1
    }
24
25
    public static function createFromArray(array $participants): self
26
    {
27
        Assert::notNull($participants);
28
29
        $createdParticipants = [];
30
        foreach ($participants as $participant) {
31
            $createdParticipants[] = Participant::createFromArray($participant);
32
        }
33
        return new self($createdParticipants);
34
    }
35
36
    public function getIterator(): Traversable
37
    {
38
        return new ArrayIterator($this->participants);
39
    }
40
41
    public function count(): int
42
    {
43
        return count($this->participants);
44
    }
45
}
46