Completed
Push — master ( 5183cf...5343ca )
by Tobias
8s
created

HttpFulfilledPromise::__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\Client\Promise;
4
5
use Http\Client\Exception;
6
use Http\Promise\Promise;
7
use Psr\Http\Message\ResponseInterface;
8
9 View Code Duplication
final class HttpFulfilledPromise 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...
10
{
11
    /**
12
     * @var ResponseInterface
13
     */
14
    private $response;
15
16
    /**
17
     * @param ResponseInterface $response
18
     */
19 10
    public function __construct(ResponseInterface $response)
20
    {
21 10
        $this->response = $response;
22 10
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 4
    public function then(callable $onFulfilled = null, callable $onRejected = null)
28
    {
29 4
        if (null === $onFulfilled) {
30 1
            return $this;
31
        }
32
33
        try {
34 3
            return new self($onFulfilled($this->response));
35 2
        } catch (Exception $e) {
36 1
            return new HttpRejectedPromise($e);
37
        }
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 3
    public function getState()
44
    {
45 3
        return Promise::FULFILLED;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 4
    public function wait($unwrap = true)
52
    {
53 4
        if ($unwrap) {
54 3
            return $this->response;
55
        }
56 1
    }
57
}
58