Completed
Push — master ( b7d6fa...54f51b )
by Ryuichi
02:48
created

ApplicationException   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 45
ccs 14
cts 16
cp 0.875
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getExceptionAsString() 0 4 1
B __construct() 0 22 5
1
<?php
2
namespace WebStream\Exception;
3
4
/**
5
 * ApplicationException
6
 * @author Ryuichi TANAKA.
7
 * @since 2014/05/05
8
 * @version 0.4
9
 */
10
class ApplicationException extends \LogicException
11
{
12
    /**
13
     * @var string エラーメッセージ
14
     */
15
    private $errorMessage;
16
17
    /**
18
     * constructor
19
     * @param string $message エラーメッセージ
20
     * @param int $code ステータスコード
21
     * @param Exception $exception 例外オブジェクト
22
     */
23 4
    public function __construct($message, $code = 500, $exception = null)
24
    {
25 4
        parent::__construct($message, $code);
26
27 4
        if ($exception === null) {
28
            $exception = $this;
29
        }
30
31 4
        if (!empty($message)) {
32
            $message .= " ";
33
        }
34
35 4
        $this->errorMessage = get_class($exception) . " is thrown: " . $message . $exception->getFile() . "(" . $exception->getLine() . ")";
36 4
        $stacktraceList = explode("#", $exception->getTraceAsString());
37 4
        foreach ($stacktraceList as $stacktraceLine) {
38 4
            if ($stacktraceLine === "") {
39 4
                continue;
40
            }
41 4
            $this->errorMessage .= PHP_EOL;
42 4
            $this->errorMessage .= "\t#" . trim($stacktraceLine);
43
        }
44 4
    }
45
46
    /**
47
     * エラーメッセージを返却する
48
     * @return string エラーメッセージ
49
     */
50 14
    public function getExceptionAsString(): string
51
    {
52 14
        return $this->errorMessage;
53
    }
54
}
55