Completed
Push — master ( 832a22...d853d3 )
by Bruno
6s
created

AuthException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace SitePoint\Rauth\Exception;
4
5
class AuthException extends \Exception
6
{
7
    private $reasons = [];
8
9
    /** @var string */
10
    private $type = '';
11
12
    public function __construct($type = '')
13
    {
14
        $this->setType($type);
15
    }
16
17
    /**
18
     * Returns the collection of reasons. Can be empty.
19
     *
20
     * @return array
21
     */
22
    public function getReasons() : array
23
    {
24
        return $this->reasons;
25
    }
26
27
    /**
28
     * Adds a reason to the reason bag in the exception
29
     *
30
     * @param Reason $reason
31
     * @return AuthException
32
     */
33
    public function addReason(Reason $reason) : AuthException
34
    {
35
        $this->reasons[] = $reason;
36
        return $this;
37
    }
38
39
    /**
40
     * Checks if any reasons have been defined in the exception
41
     *
42
     * @return bool
43
     */
44
    public function hasReasons() : bool
45
    {
46
        return (count($this->reasons) > 0);
47
    }
48
49
    /**
50
     * Sets the context in which the exception was thrown
51
     *
52
     * Example "ban" or "and"
53
     *
54
     * @param string $type
55
     * @return AuthException
56
     */
57
    public function setType(string $type) : AuthException
58
    {
59
        $this->type = $type;
60
        return $this;
61
    }
62
63
    /**
64
     * Returns context in which exception occurred.
65
     *
66
     * Example "ban" or "and"
67
     *
68
     * @return string
69
     */
70
    public function getType() : string
71
    {
72
        return $this->type;
73
    }
74
}
75