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.

StopIfTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 44.74 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 6
c 2
b 1
f 1
lcom 0
cbo 0
dl 34
loc 76
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A stopIf() 17 17 3
A continueIf() 17 17 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Pipes\Filter;
4
5
trait StopIfTrait
6
{
7
    /**
8
     * Stops the iteration if the callback returns a true-ish value.
9
     * The current element will not be included.
10
     *
11
     * The passed callback will be invoked with the following argument:
12
     *
13
     *      - $value (iterator's current())
14
     *
15
     * If the second parameter is true the following arguments will be added
16
     * to the call:
17
     *
18
     *      - $key (iterator's key())
19
     *      - $iterator (the iterator itself)
20
     *
21
     * @param $______callback
22
     * @param bool $______allArgs
23
     *
24
     * @return \Pipes\Pipe
25
     */
26 View Code Duplication
    public function stopIf($______callback, $______allArgs = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
        $generator = function () use ($pipe, $iterator, $______callback, $______allArgs) {
32
            foreach ($iterator as $key => $value) {
33
                if ($pipe->executeCallback($______callback, $______allArgs, $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...
34
                ) {
35
                    return;
36
                } // @codeCoverageIgnore
37
                yield $key => $value;
38
            }
39
        };
40
41
        return $this->chainWith($generator());
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...
42
    }
43
44
    /**
45
     * Stops the iteration if the callback returns a true-ish value.
46
     * The current element will not be included.
47
     *
48
     * The passed callback will be invoked with the following argument:
49
     *
50
     *      - $value (iterator's current())
51
     *
52
     * If the second parameter is true the following arguments will be added
53
     * to the call:
54
     *
55
     *      - $key (iterator's key())
56
     *      - $iterator (the iterator itself)
57
     *
58
     * @param $______callback
59
     * @param bool $______allArgs
60
     *
61
     * @return \Pipes\Pipe
62
     */
63 View Code Duplication
    public function continueIf($______callback, $______allArgs = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        $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...
66
        $pipe = $this;
67
68
        $generator = function () use ($pipe, $iterator, $______callback, $______allArgs) {
69
            foreach ($iterator as $key => $value) {
70
                if (!$pipe->executeCallback($______callback, $______allArgs, $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...
71
                ) {
72
                    return;
73
                } // @codeCoverageIgnore
74
                yield $key => $value;
75
            }
76
        };
77
78
        return $this->chainWith($generator());
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...
79
    }
80
}
81