Completed
Push — master ( cd9351...1bb790 )
by Márk
02:17
created

RejectedPromise::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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