RejectionException::__construct()   B
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 9
nc 4
nop 2
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
 * Rejection Exception class.
16
 *
17
 * @author Karel Osorio Ramírez <[email protected]>
18
 */
19
class RejectionException extends \RuntimeException
20
{
21
    /**
22
     * @var mixed
23
     */
24
    protected $reason;
25
26
    /**
27
     * @param mixed  $reason
28
     * @param string $message
29
     */
30
    public function __construct($reason, $message = null)
31
    {
32
        $this->reason = $reason;
33
        if ($message !== null) {
34
            $message = 'The promise has been rejected';
35
            if (\is_string($reason) || (\is_object($reason) && \method_exists($reason, '__toString'))) {
36
                $message .= ' with reason: '.$this->reason;
37
            } else {
38
                $message .= ' with unknown reason: '.\is_object($reason) ? \get_class($reason) : \gettype($reason);
39
            }
40
        }
41
42
        parent::__construct($message);
43
    }
44
45
    /**
46
     * @return mixed
47
     */
48
    public function reason()
49
    {
50
        return $this->reason;
51
    }
52
}
53