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 ( 9000d2...f19783 )
by Time
06:05
created

ProjectionIterator::__constructIterator()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.6667
cc 3
eloc 7
nc 4
nop 2
1
<?php
2
3
namespace Pinq\Iterators\Common;
4
5
use Pinq\Iterators\IIterator;
6
7
/**
8
 * Common functionality for the projection iterator
9
 *
10
 * @author Elliot Levin <[email protected]>
11
 */
12
trait ProjectionIterator
13
{
14
    /**
15
     * @var callable|null
16
     */
17
    private $keyProjectionFunction;
18
19
    /**
20
     * @var callable|null
21
     */
22
    private $valueProjectionFunction;
23
24
    protected function __constructIterator(
25
            callable $keyProjectionFunction = null,
26
            callable $valueProjectionFunction = null
27
    ) {
28
        $this->keyProjectionFunction   = $keyProjectionFunction === null ?
29
                null : Functions::allowExcessiveArguments($keyProjectionFunction);
30
        $this->valueProjectionFunction = $valueProjectionFunction === null ?
31
                null : Functions::allowExcessiveArguments($valueProjectionFunction);
32
    }
33
34
    final protected function projectElement(&$key, &$value)
35
    {
36
        $keyProjectionFunction   = $this->keyProjectionFunction;
37
        $valueProjectionFunction = $this->valueProjectionFunction;
38
39
        $keyCopy   = $key;
40
        $valueCopy = $value;
41
42
        if ($keyProjectionFunction !== null) {
43
            $keyCopyForKey   = $keyCopy;
44
            $valueCopyForKey = $valueCopy;
45
46
            $keyProjection = $keyProjectionFunction($valueCopyForKey, $keyCopyForKey);
47
        } else {
48
            $keyProjection =& $key;
49
        }
50
51
        if ($valueProjectionFunction !== null) {
52
            $keyCopyForValue   = $keyCopy;
53
            $valueCopyForValue = $valueCopy;
54
55
            $valueProjection = $valueProjectionFunction($valueCopyForValue, $keyCopyForValue);
56
        } else {
57
            $valueProjection =& $value;
58
        }
59
60
        return [&$keyProjection, &$valueProjection];
61
    }
62
63
    /**
64
     * @return IIterator
65
     */
66
    abstract protected function getSourceIterator();
67
68
    /**
69
     * @return bool
70
     */
71
    final public function isArrayCompatible()
72
    {
73
        return $this->keyProjectionFunction === null && $this->getSourceIterator()->isArrayCompatible();
74
    }
75
}
76