ExceptionContext   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 18
c 1
b 0
f 0
dl 0
loc 59
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getNextExceptionContext() 0 3 1
A getLastException() 0 7 2
A getException() 0 3 1
A __construct() 0 3 1
A addException() 0 15 3
1
<?php
2
3
/*
4
 * This file is part of the LightSAML-Core package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace LightSaml\Context\Profile;
13
14
class ExceptionContext extends AbstractProfileContext
15
{
16
    /** @var \Exception */
17
    protected $exception;
18
19
    /** @var ExceptionContext|null */
20
    protected $nextExceptionContext;
21
22
    public function __construct(\Exception $exception = null)
23
    {
24
        $this->exception = $exception;
25
    }
26
27
    /**
28
     * @return \Exception
29
     */
30
    public function getException()
31
    {
32
        return $this->exception;
33
    }
34
35
    /**
36
     * @return \Exception|null
37
     */
38
    public function getLastException()
39
    {
40
        if (null == $this->nextExceptionContext) {
41
            return $this->exception;
42
        }
43
44
        return $this->nextExceptionContext->getException();
45
    }
46
47
    /**
48
     * @return ExceptionContext|null
49
     */
50
    public function getNextExceptionContext()
51
    {
52
        return $this->nextExceptionContext;
53
    }
54
55
    /**
56
     * @return ExceptionContext
57
     */
58
    public function addException(\Exception $exception)
59
    {
60
        if ($this->exception) {
61
            if (null == $this->nextExceptionContext) {
62
                $this->nextExceptionContext = new self($exception);
63
64
                return $this->nextExceptionContext;
65
            } else {
66
                return $this->nextExceptionContext->addException($exception);
67
            }
68
        } else {
69
            $this->exception = $exception;
70
        }
71
72
        return $this;
73
    }
74
}
75