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.

PipenessTrait::executeCallback()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4286
cc 2
eloc 4
nc 1
nop 5
1
<?php
2
3
namespace Pipes;
4
5
use Pipes\Iterator\AppendIterator;
6
7
trait PipenessTrait
8
{
9
    //    use Filter\AppendTrait;
10
    use Filter\ChunkTrait;
11
    use Filter\EachTrait;
12
    use Concept\EmitTrait;
13
    use Filter\FilesTrait;
14
    use Filter\FilterTrait;
15
    use Filter\LimitTrait;
16
    use Filter\MapTrait;
17
    use Filter\SkipTrait;
18
    use Filter\ValuesTrait;
19
    use Filter\SleepTrait;
20
    use Filter\InfiniteTrait;
21
    use Filter\StopIfTrait;
22
23
    /**
24
     * @param \Iterator $iterator
25
     *
26
     * @return static
27
     */
28
    protected function chainWith(\Iterator $iterator)
29
    {
30
        $this->var = $iterator;
0 ignored issues
show
Bug introduced by
The property var does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31
32
        return $this;
33
    }
34
35
    public function toArray()
36
    {
37
        $iterator = $this->var;
38
39
        return iterator_to_array($iterator, true);
40
    }
41
42
    /**
43
     * Returns a complete iterator.
44
     * (an instance of \IteratorIterator which in turn
45
     * implements \OuterIterator).
46
     *
47
     * Use this method if you need to comply with type-hinting
48
     * from external libraries
49
     *
50
     * @return \IteratorIterator
51
     */
52
    public function toIterator()
53
    {
54
        $iterator = $this->unwrap();
55
56
        if (is_array($iterator)) {
57
            $iterator = new \ArrayIterator($iterator);
58
        }
59
60
        $appendIterator = new AppendIterator();
61
        $appendIterator->append($iterator);
0 ignored issues
show
Compatibility introduced by
$iterator of type object<Traversable> is not a sub-type of object<Iterator>. It seems like you assume a child interface of the interface Traversable to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
62
63
        return new PipeIterator($appendIterator);
64
    }
65
66
//    /**
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
67
//     * @return \Traversable
68
//     */
69
//    protected function getRoot()
70
//    {
71
//        return $this->getBaseOfChain($this, true);
72
//    }
73
74
    /**
75
     * Returns the latest non pipe Iterator/Traversable in the
76
     * chain.
77
     *
78
     * @return \Traversable
79
     */
80
    public function unwrap()
81
    {
82
        $iterator = func_num_args() ? func_get_arg(0) : $this;
83
84
        return $this->getBaseOfChain($iterator);
85
    }
86
87
    public function getBaseOfChain($iterator, $pipeInstance = false)
0 ignored issues
show
Unused Code introduced by
The parameter $pipeInstance is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
88
    {
89
        $last = $iterator;
0 ignored issues
show
Unused Code introduced by
$last is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
90
        while (true) {
91
            switch (true) {
92
                case is_a($iterator, '\\Pipes\\PipeIterator'):
93
                    $last = $iterator;
94
                    $iterator = $last->getInnerIterator();
95
                    break;
96
                case is_a($iterator, '\\Pipes\\Pipe'):
97
                    $last = $iterator;
98
                    $iterator = $last->getIterator();
99
                    break;
100
                case is_a($iterator, '\\ArrayIterator'):
101
                    $iterator = $iterator->getArrayCopy();
102
                    break;
103
                default:
104
//                  --- was used by getRoot()
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
105
//                    if ($pipeInstance) {
106
//                        return $last;
107
//                    }
108
109
                    return $iterator;
110
            }
111
        }
112
    } // @codeCoverageIgnore
113
114
    protected function executeCallback($______callback, $______allArgs, $value, $key, $iterator)
115
    {
116
        return call_user_func_array(
117
            $______callback,
118
            $______allArgs ? [$value, $key, $iterator] : [$value]
119
       );
120
    }
121
}
122