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.

MapTrait::map()   B
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 32
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 0
loc 32
rs 8.439
cc 6
eloc 19
nc 4
nop 1
1
<?php
2
3
namespace Pipes\Filter;
4
5
use Pipes\Concept\Emittable;
6
7
trait MapTrait
8
{
9
    /**
10
     * Tranforms each element into something else using a callback
11
     * (rough equivalent of array_map()).
12
     *
13
     * The callback should return the new element.
14
     *
15
     * To also change the key, return<code>p()->emit($key,$value)</code>
16
     * <code>
17
     * p()->map(function ($value, $key, $iterator) {
18
     *     return p()->emit($key.'_new', $value);
19
     * });
20
     *
21
     *
22
     * @param callable $callback
0 ignored issues
show
Documentation introduced by
There is no parameter named $callback. Did you maybe mean $______callback?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
23
     *
24
     * @return \Pipes\Pipe
25
     */
26
    public function map(callable $______callback)
27
    {
28
        $iterator = $this->getIterator();
0 ignored issues
show
Bug introduced by
It seems like getIterator() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
29
        $pipe = $this;
30
31
        if (!is_array($______callback)) {
32
            $reflectionFunction = new \ReflectionFunction($______callback);
33
        } else {
34
            $reflectionFunction = new \ReflectionMethod($______callback[0], $______callback[1]);
35
        }
36
37
        if ($reflectionFunction->isGenerator()) {
38
            $generator = $______callback;
39
        } else {
40
            $generator = function ($iterator) use ($pipe, $______callback) {
41
                foreach ($iterator as $key => $value) {
42
                    //                yield $key => $pipe->executeCallback($______callback, true, $value, $key, $iterator);
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
43
                    $value = $pipe->executeCallback($______callback, true, $value, $key, $iterator);
0 ignored issues
show
Bug introduced by
It seems like executeCallback() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
44
                    if ($value instanceof Emittable) {
45
                        if ($value->hasKey()) {
46
                            $key = $value->getKey();
47
                        }
48
                        $value = $value->getValue();
49
                    }
50
                    yield $key => $value;
51
                }
52
            };
53
        }
54
55
        return $this->chainWith($generator($iterator));
0 ignored issues
show
Bug introduced by
It seems like chainWith() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
56
//        return $this->chainWith(new \Pipes\Iterator\MapIterator($this->toIterator(), $callback));
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% 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...
57
    }
58
}
59