Completed
Push — master ( 298e09...565401 )
by Ivannis Suárez
02:36
created

RejectedPromise::rejectActual()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Core\Async\Promise;
13
14
/**
15
 * Rejected Promise class.
16
 *
17
 * @author Karel Osorio Ramírez <[email protected]>
18
 */
19
class RejectedPromise extends AbstractPromise
20
{
21
    /**
22
     * @var mixed
23
     */
24
    protected $reason;
25
26
    /**
27
     * @param mixed $value
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
28
     */
29
    public function __construct($reason = null)
30
    {
31
        $this->reason = $reason;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onNotify = null)
38
    {
39
        if ($onRejected === null) {
40
            return $this;
41
        }
42
43
        return new self($this->rejectActual($onRejected));
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function state()
50
    {
51
        return State::REJECTED();
52
    }
53
54
    /**
55
     * @param callable $onRejected
56
     *
57
     * @return mixed
58
     */
59
    private function rejectActual(callable $onRejected)
60
    {
61
        try {
62
            $onRejected($this->reason);
63
        } catch (\Exception $e) {
64
            return $e;
65
        }
66
67
        return $this->reason;
68
    }
69
}
70