Passed
Push — master ( 550b9e...103607 )
by Sébastien
09:49 queued 07:35
created

JavaException   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 117
ccs 21
cts 27
cp 0.7778
rs 10
c 0
b 0
f 0
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setDriverException() 0 3 1
A setJavaClassName() 0 3 1
A setCause() 0 3 1
A setStackTrace() 0 3 1
A getJavaClassName() 0 3 1
A __construct() 0 15 2
A getDriverException() 0 3 1
A getCause() 0 3 1
A getStackTrace() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Soluble Japha
7
 *
8
 * @link      https://github.com/belgattitude/soluble-japha
9
 * @copyright Copyright (c) 2013-2019 Vanvelthem Sébastien
10
 * @license   MIT License https://github.com/belgattitude/soluble-japha/blob/master/LICENSE.md
11
 */
12
13
namespace Soluble\Japha\Bridge\Exception;
14
15
use Exception;
16
17
class JavaException extends Exception implements JavaExceptionInterface
18
{
19
    /**
20
     * @var string
21
     */
22
    protected $javaClassName;
23
24
    /**
25
     * @var string
26
     */
27
    protected $cause;
28
29
    /**
30
     * @var string
31
     */
32
    protected $stackTrace;
33
34
    /**
35
     * @var Exception
36
     */
37
    protected $driverException;
38
39
    /**
40
     * Constructor.
41
     *
42
     * @param string    $message
43
     * @param string    $javaCause
44
     * @param string    $stackTrace
45
     * @param string    $javaClassName   originating java FQCN
46
     * @param int       $code
47
     * @param Exception $driverException
48
     * @param Exception $previous
49
     */
50 3
    public function __construct(
51
        $message,
52
        $javaCause,
53
        $stackTrace,
54
        $javaClassName,
55
        $code = null,
56
        Exception $driverException = null,
57
        Exception $previous = null
58
    ) {
59 3
        parent::__construct($message, $code, $previous);
60 3
        $this->setCause($javaCause);
61 3
        $this->setStackTrace($stackTrace);
62 3
        $this->setJavaClassName($javaClassName);
63 3
        if ($driverException !== null) {
64 3
            $this->setDriverException($driverException);
65
        }
66 3
    }
67
68
    /**
69
     * Set original exception as throw by the driver.
70
     *
71
     * @param Exception $driverException
72
     */
73 3
    private function setDriverException(Exception $driverException): void
74
    {
75 3
        $this->driverException = $driverException;
76 3
    }
77
78
    /**
79
     * Return underlying driver exception.
80
     *
81
     * @return Exception|null
82
     */
83
    public function getDriverException(): ?Exception
84
    {
85
        return $this->driverException;
86
    }
87
88
    /**
89
     * Set Java cause.
90
     */
91 3
    private function setCause(string $cause): void
92
    {
93 3
        $this->cause = $cause;
94 3
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99
    public function getCause(): string
100
    {
101
        return $this->cause;
102
    }
103
104
    /**
105
     * Set JVM Stack trace.
106
     */
107 3
    private function setStackTrace(string $stackTrace): void
108
    {
109 3
        $this->stackTrace = $stackTrace;
110 3
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115
    public function getStackTrace(): string
116
    {
117
        return $this->stackTrace;
118
    }
119
120
    /**
121
     * {@inheritdoc}
122
     */
123 1
    public function getJavaClassName(): string
124
    {
125 1
        return $this->javaClassName;
126
    }
127
128
    /**
129
     * Set java exception class name.
130
     */
131 3
    private function setJavaClassName(string $javaClassName): void
132
    {
133 3
        $this->javaClassName = $javaClassName;
134 3
    }
135
}
136