Completed
Pull Request — master (#116)
by Joel
07:29
created

HttpRejectedPromise::wait()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 6
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Http\Client\Promise;
4
5
use Http\Client\Exception;
6
7 View Code Duplication
final class HttpRejectedPromise implements HttpPromise
0 ignored issues
show
Duplication introduced by
This class 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...
8
{
9
    /**
10
     * @var Exception
11
     */
12
    private $exception;
13
14
    /**
15
     * @param Exception $exception
16
     */
17
    public function __construct(Exception $exception)
18
    {
19
        $this->exception = $exception;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function then(callable $onFulfilled = null, callable $onRejected = null)
26
    {
27
        if (null === $onRejected) {
28
            return $this;
29
        }
30
31
        try {
32
            return new HttpFulfilledPromise($onRejected($this->exception));
33
        } catch (Exception $e) {
34
            return new self($e);
35
        }
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getState()
42
    {
43
        return HttpPromise::REJECTED;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function wait($unwrap = true)
50
    {
51
        if ($unwrap) {
52
            throw $this->exception;
53
        }
54
    }
55
}
56