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 ( 788e0e...0fca6a )
by Freek
01:28
created

ManipulationSequence::contains()   A

Complexity

Conditions 4
Paths 4

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 4
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
    public function __construct(array $sequenceArray = [])
14
    {
15
        $this->startNewGroup();
16
        $this->mergeArray($sequenceArray);
17
    }
18
19
    /**
20
     * @param string $operation
21
     * @param string $argument
22
     *
23
     * @return $this
24
     */
25
    public function addManipulation(string $operation, string $argument)
26
    {
27
        $lastIndex = count($this->groups) - 1;
28
29
        $this->groups[$lastIndex][$operation] = $argument;
30
31
        return $this;
32
    }
33
34
    /**
35
     * @param \Spatie\Image\ManipulationSequence $sequence
36
     *
37
     * @return $this
38
     */
39
    public function merge(ManipulationSequence $sequence)
40
    {
41
        $sequenceArray = $sequence->toArray();
42
43
        $this->mergeArray($sequenceArray);
44
45
        return $this;
46
    }
47
48
    public function mergeArray(array $sequenceArray)
49
    {
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 $this
63
     */
64
    public function startNewGroup()
65
    {
66
        $this->groups[] = [];
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->toArray());
84
    }
85
86
    /**
87
     * @param string $manipulationName
88
     *
89
     * @return $this
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
    public function isEmpty(): bool
103
    {
104
        if (count($this->groups) > 1) {
105
            return false;
106
        }
107
108
        if (count($this->groups[0]) > 0) {
109
            return false;
110
        }
111
112
        return true;
113
    }
114
115
    protected function sanitizeManipulationSets(array $groups): array
116
    {
117
        return array_values(array_filter($groups, function (array $manipulationSet) {
118
            return count($manipulationSet);
119
        }));
120
    }
121
122
    /*
123
    * Determine if the sequences contain a manipulation with the given name.
124
    */
125
    public function contains($searchManipulationName)
126
    {
127
        foreach ($this->groups as $group) {
128
            foreach ($group as $name => $argument) {
129
                if ($name === $searchManipulationName) {
130
                    return true;
131
                }
132
            }
133
            return false;
134
        }
135
    }
136
}
137