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 ( ae0afe...3c2226 )
by Freek
01:50
created

ManipulationSequence::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
    /**
17
     * @param string $operation
18
     * @param string $argument
19
     *
20
     * @return static
21
     */
22
    public function addManipulation(string $operation, string $argument)
23
    {
24
        if ($this->startNewGroup) {
25
            $this->groups[] = [];
26
        }
27
28
        $lastIndex = count($this->groups) - 1;
29
30
        $this->groups[$lastIndex][$operation] = $argument;
31
32
        $this->startNewGroup = false;
33
34
        return $this;
35
    }
36
37
    public function merge(ManipulationSequence $manipulationSets)
38
    {
39
        foreach($manipulationSets->toArray() as $manipulationSet) {
0 ignored issues
show
Bug introduced by
It seems like $manipulationSets is not always an object, but can also be of type array. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
40
            foreach($manipulationSet as $name => $argument) {
41
                $this->addManipulation($name, $argument);
42
            }
43
44
            if(next($manipulationSets)) {
45
                $this->startNewGroup();
46
            }
47
        }
48
    }
49
50
    /**
51
     * @return static
52
     */
53
    public function startNewGroup()
54
    {
55
        $this->startNewGroup = true;
56
57
        return $this;
58
    }
59
60
    public function toArray(): array
61
    {
62
        return $this->getGroups();
63
    }
64
65
    public function getGroups(): array
66
    {
67
        return $this->sanitizeManipulationSets($this->groups);
68
    }
69
70
    public function getIterator(): ArrayIterator
71
    {
72
        return new ArrayIterator($this->groups);
73
    }
74
75
    public function removeManipulation($manipulationName)
76
    {
77
        foreach($this->groups as &$group) {
78
            if (array_key_exists($manipulationName, $group)) {
79
                unset($group[$manipulationName]);
80
            }
81
        }
82
83
        return $this;
84
    }
85
86
    protected function sanitizeManipulationSets(array $groups): array
87
    {
88
        return array_values(array_filter($groups, function(array $manipulationSet) {
89
            return count($manipulationSet);
90
        }));
91
    }
92
}