Passed
Push — master ( aa4419...7e0f99 )
by James
01:57
created

Changes   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A new() 0 3 1
A fromArray() 0 6 1
A mergeWith() 0 7 1
A getIterator() 0 3 1
A withAddedChange() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Roave\ApiCompare;
5
6
use ArrayIterator;
7
use Assert\Assert;
8
use IteratorAggregate;
9
10
final class Changes implements IteratorAggregate
11
{
12
    /** @var Change[] */
13
    private $changes = [];
14
15
    private function __construct()
16
    {
17
    }
18
19
    public static function new(): self
20
    {
21
        return new self();
22
    }
23
24
    public static function fromArray(array $changes): self
25
    {
26
        Assert::that($changes)->all()->isInstanceOf(Change::class);
27
        $instance = self::new();
28
        $instance->changes = $changes;
29
        return $instance;
30
    }
31
32
    public function mergeWith(self $other) : self
33
    {
34
        $instance = new self();
35
36
        $instance->changes = array_merge($this->changes, $other->changes);
37
38
        return $instance;
39
    }
40
41
    public function withAddedChange(Change $change): self
42
    {
43
        $new = clone $this;
44
        $new->changes[] = $change;
45
        return $new;
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     *
51
     * @return Change[]
52
     */
53
    public function getIterator() : ArrayIterator
54
    {
55
        return new ArrayIterator($this->changes);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new ArrayIterator($this->changes) returns the type ArrayIterator which is incompatible with the documented return type Roave\ApiCompare\Change[].
Loading history...
56
    }
57
}
58