RejectionException   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 14 6
A reason() 0 4 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
 * 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