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 ( f7060e...00f73a )
by Brent
10s
created

ProcessCallbacks   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 11
lcom 2
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A then() 0 6 1
A catch() 0 6 1
A timeout() 0 6 1
A triggerSuccess() 0 16 3
A triggerError() 0 12 3
A triggerTimeout() 0 6 2
1
<?php
2
3
namespace Spatie\Async\Process;
4
5
trait ProcessCallbacks
6
{
7
    protected $successCallbacks = [];
8
    protected $errorCallbacks = [];
9
    protected $timeoutCallbacks = [];
10
11
    public function then(callable $callback): self
12
    {
13
        $this->successCallbacks[] = $callback;
14
15
        return $this;
16
    }
17
18
    public function catch(callable $callback): self
0 ignored issues
show
Coding Style introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
19
    {
20
        $this->errorCallbacks[] = $callback;
21
22
        return $this;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $this.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
23
    }
24
25
    public function timeout(callable $callback): self
26
    {
27
        $this->timeoutCallbacks[] = $callback;
28
29
        return $this;
30
    }
31
32
    public function triggerSuccess()
33
    {
34
        if ($this->getErrorOutput()) {
0 ignored issues
show
Bug introduced by
It seems like getErrorOutput() 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...
35
            $this->triggerError();
36
37
            return;
38
        }
39
40
        $output = $this->getOutput();
0 ignored issues
show
Bug introduced by
It seems like getOutput() 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...
41
42
        foreach ($this->successCallbacks as $callback) {
43
            call_user_func_array($callback, [$output]);
44
        }
45
46
        return $output;
47
    }
48
49
    public function triggerError()
50
    {
51
        $exception = $this->resolveErrorOutput();
0 ignored issues
show
Bug introduced by
It seems like resolveErrorOutput() 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...
52
53
        foreach ($this->errorCallbacks as $callback) {
54
            call_user_func_array($callback, [$exception]);
55
        }
56
57
        if (! $this->errorCallbacks) {
58
            throw $exception;
59
        }
60
    }
61
62
    public function triggerTimeout()
63
    {
64
        foreach ($this->timeoutCallbacks as $callback) {
65
            call_user_func_array($callback, []);
66
        }
67
    }
68
}
69