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.
Failed Conditions
Push — master ( 0cbf54...b6a90e )
by Dušan
02:44
created

Collection::unserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace DusanKasan\Knapsack;
4
5
use Closure;
6
use DusanKasan\Knapsack\Exceptions\InvalidArgument;
7
use Iterator;
8
use IteratorAggregate;
9
use RecursiveArrayIterator;
10
use Traversable;
11
12
class Collection implements Iterator, \Serializable
13
{
14
    use CollectionTrait;
15
16
    /**
17
     * @var Iterator
18
     */
19
    protected $input;
20
21
    /**
22
     * @var callable
23
     */
24
    private $generatorFactory;
25
26
    /**
27
     * @param callable|Closure|array|Traversable $input If callable is passed, it must be a generator factory function
28
     */
29 80
    public function __construct($input)
30
    {
31 80
        if (is_callable($input)) {
32 67
            $this->generatorFactory = $input;
33 67
            $this->input = $input();
34 80
        } elseif (is_array($input)) {
35 69
            $input = new RecursiveArrayIterator($input);
36 69
            $this->input = $input;
37 72
        } elseif ($input instanceof IteratorAggregate) {
38 2
            $input = $input->getIterator();
39 1
            $this->input = $input;
40 4
        } elseif ($input instanceof Iterator) {
41 2
            $this->input = $input;
42 2
        } else {
43 1
            throw new InvalidArgument;
44
        }
45 79
    }
46
47
    /**
48
     * Static alias of normal constructor.
49
     *
50
     * @param array|Traversable $input
51
     * @return Collection
52
     */
53 6
    public static function from($input)
54
    {
55 6
        return new self($input);
56
    }
57
58
    /**
59
     * Returns lazy collection of values, where first value is $input and all subsequent values are computed by applying
60
     * $function to the last value in the collection. By default this produces an infinite collection. However you can
61
     * end the collection by throwing a NoMoreItems exception.
62
     *
63
     * @param mixed $input
64
     * @param callable $function
65
     * @return Collection
66
     */
67 2
    public static function iterate($input, callable $function)
68
    {
69 2
        return iterate($input, $function);
70
    }
71
72
    /**
73
     * Returns a lazy collection of $value repeated $times times. If $times is not provided the collection is infinite.
74
     *
75
     * @param mixed $value
76
     * @param int $times
77
     * @return Collection
78
     */
79 3
    public static function repeat($value, $times = -1)
80
    {
81 3
        return repeat($value, $times);
82
    }
83
84
    /**
85
     * Returns a lazy collection of numbers starting at $start, incremented by $step until $end is reached.
86
     *
87
     * @param int $start
88
     * @param int|null $end
89
     * @param int $step
90
     * @return Collection
91
     */
92 2
    public static function range($start = 0, $end = null, $step = 1)
93
    {
94 2
        return \DusanKasan\Knapsack\range($start, $end, $step);
95
    }
96
97
    /**
98
     * @inheritdoc
99
     */
100 75
    public function current()
101
    {
102 75
        return $this->input->current();
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108 74
    public function next()
109
    {
110 74
        $this->input->next();
111 74
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116 73
    public function key()
117
    {
118 73
        return $this->input->key();
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124 78
    public function valid()
125
    {
126 78
        return $this->input->valid();
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     */
132 78
    public function rewind()
133
    {
134 78
        if ($this->generatorFactory) {
135 67
            $this->input = call_user_func($this->generatorFactory);
136 67
        }
137
138 78
        $this->input->rewind();
139 78
    }
140
141
    /**
142
     * {@inheritdoc}
143
     */
144 1
    public function serialize()
145
    {
146 1
        return serialize(
147 1
            toArray(
148 1
                map(
149 1
                    $this->input,
150 1
                    function ($value, $key) {
151 1
                        return [$key, $value];
152
                    }
153 1
                )
154 1
            )
155 1
        );
156
    }
157
158
    /**
159
     * {@inheritdoc}
160
     */
161 1
    public function unserialize($serialized)
162
    {
163 1
        $this->input = dereferenceKeyValue(unserialize($serialized));
164 1
    }
165
}
166