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   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 64
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __constructIterator() 0 9 3
B projectElement() 0 28 3
getSourceIterator() 0 1 ?
A isArrayCompatible() 0 4 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