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

AuthException   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 70
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getReasons() 0 4 1
A addReason() 0 5 1
A hasReasons() 0 4 1
A setType() 0 5 1
A getType() 0 4 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