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 ( 352f99...e3c5ff )
by Cees-Jan
09:24
created

LazyPromiseTrait::setFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 1
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace WyriHaximus\Travis;
4
5
use React\Promise\RejectedPromise;
6
7
/**
8
 * Class LazyPromise transformed into a trait
9
 * @source https://github.com/reactphp/promise/blob/fe0d75d660486677791fde20e82d263ab9d1c936/src/LazyPromise.php
10
 * @package WyriHaximus\Travis
11
 */
12
trait LazyPromiseTrait
13
{
14
    private $factory;
15
    private $promise;
16
17
    public function setFactory(callable $factory)
18
    {
19
        $this->factory = $factory;
20
    }
21
22
    public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
23
    {
24
        return $this->promise()->then($onFulfilled, $onRejected, $onProgress);
25
    }
26
27
    public function done(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
28
    {
29
        return $this->promise()->done($onFulfilled, $onRejected, $onProgress);
30
    }
31
32
    public function otherwise(callable $onRejected)
33
    {
34
        return $this->promise()->otherwise($onRejected);
35
    }
36
37
    public function always(callable $onFulfilledOrRejected)
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $onFulfilledOrRejected exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
38
    {
39
        return $this->promise()->always($onFulfilledOrRejected);
40
    }
41
42
    public function progress(callable $onProgress)
43
    {
44
        return $this->promise()->progress($onProgress);
45
    }
46
47
    public function cancel()
48
    {
49
        return $this->promise()->cancel();
50
    }
51
52
    private function promise()
53
    {
54
        if (null === $this->promise) {
55
            try {
56
                $this->promise = \React\Promise\resolve(call_user_func($this->factory));
57
            } catch (\Exception $exception) {
58
                $this->promise = new RejectedPromise($exception);
59
            }
60
        }
61
62
        return $this->promise;
63
    }
64
}
65