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

FulfilledPromise   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 1
dl 49
loc 49
ccs 16
cts 16
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getState() 4 4 1
A wait() 6 6 2
A then() 12 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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