GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 0eed44...2a32a9 )
by Freek
01:42
created

ManipulationSequence::mergeArray()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 5
nop 1
1
<?php
2
3
namespace Spatie\Image;
4
5
use ArrayIterator;
6
use IteratorAggregate;
7
8
class ManipulationSequence implements IteratorAggregate
9
{
10
    /** @var array */
11
    protected $groups = [];
12
13
    /** @var bool */
14
    protected $startNewGroup = true;
15
16
    public function __construct(array $sequenceArray = [])
17
    {
18
        $this->mergeArray($sequenceArray);
19
    }
20
21
    /**
22
     * @param string $operation
23
     * @param string $argument
24
     *
25
     * @return static
26
     */
27
    public function addManipulation(string $operation, string $argument)
28
    {
29
        if ($this->startNewGroup) {
30
            $this->groups[] = [];
31
        }
32
33
        $lastIndex = count($this->groups) - 1;
34
35
        $this->groups[$lastIndex][$operation] = $argument;
36
37
        $this->startNewGroup = false;
38
39
        return $this;
40
    }
41
42
    public function merge(ManipulationSequence $sequence)
43
    {
44
        $sequenceArray = $sequence->toArray();
45
46
        $this->mergeArray($sequenceArray);
47
    }
48
49
    public function mergeArray(array $sequenceArray) {
50
        foreach ($sequenceArray as $group) {
51
            foreach ($group as $name => $argument) {
52
                $this->addManipulation($name, $argument);
53
            }
54
55
            if (next($sequenceArray)) {
56
                $this->startNewGroup();
57
            }
58
        }
59
    }
60
61
    /**
62
     * @return static
63
     */
64
    public function startNewGroup()
65
    {
66
        $this->startNewGroup = true;
67
68
        return $this;
69
    }
70
71
    public function toArray(): array
72
    {
73
        return $this->getGroups();
74
    }
75
76
    public function getGroups(): array
77
    {
78
        return $this->sanitizeManipulationSets($this->groups);
79
    }
80
81
    public function getIterator(): ArrayIterator
82
    {
83
        return new ArrayIterator($this->groups);
84
    }
85
86
    /**
87
     * @param string $manipulationName
88
     *
89
     * @return static
90
     */
91
    public function removeManipulation(string $manipulationName)
92
    {
93
        foreach ($this->groups as &$group) {
94
            if (array_key_exists($manipulationName, $group)) {
95
                unset($group[$manipulationName]);
96
            }
97
        }
98
99
        return $this;
100
    }
101
102
    protected function sanitizeManipulationSets(array $groups): array
103
    {
104
        return array_values(array_filter($groups, function (array $manipulationSet) {
105
            return count($manipulationSet);
106
        }));
107
    }
108
}
109