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 ( ee03a9...9efbbd )
by Dušan
02:47
created

Collection   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 129
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 15
c 3
b 0
f 0
lcom 1
cbo 2
dl 0
loc 129
ccs 38
cts 38
cp 1
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 17 5
A from() 0 4 1
A iterate() 0 4 1
A repeat() 0 4 1
A range() 0 4 1
A current() 0 4 1
A next() 0 4 1
A key() 0 4 1
A valid() 0 4 1
A rewind() 0 8 2
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
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 78
    public function __construct($input)
30
    {
31 78
        if (is_array($input)) {
32 68
            $input = new RecursiveArrayIterator($input);
33 68
            $this->input = $input;
34 78
        } elseif ($input instanceof IteratorAggregate) {
35 1
            $input = $input->getIterator();
36 1
            $this->input = $input;
37 68
        } elseif (is_callable($input)) {
38 65
            $this->generatorFactory = $input;
39 65
            $this->input = $input();
40 67
        } elseif ($input instanceof Iterator) {
41 2
            $this->input = $input;
42 2
        } else {
43 1
            throw new InvalidArgument;
44
        }
45 77
    }
46
47
    /**
48
     * Static alias of normal constructor.
49
     *
50
     * @param array|Traversable $input
51
     * @return Collection
52
     */
53 4
    public static function from($input)
54
    {
55 4
        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 73
    public function current()
101
    {
102 73
        return $this->input->current();
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108 72
    public function next()
109
    {
110 72
        $this->input->next();
111 72
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116 71
    public function key()
117
    {
118 71
        return $this->input->key();
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124 76
    public function valid()
125
    {
126 76
        return $this->input->valid();
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     */
132 76
    public function rewind()
133
    {
134 76
        if ($this->generatorFactory) {
135 65
            $this->input = call_user_func($this->generatorFactory);
136 65
        }
137
138 76
        $this->input->rewind();
139 76
    }
140
}
141