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   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 53
rs 10
c 1
b 0
f 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setFactory() 0 4 1
A then() 0 4 1
A done() 0 4 1
A otherwise() 0 4 1
A always() 0 4 1
A progress() 0 4 1
A cancel() 0 4 1
A promise() 0 12 3
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