Completed
Pull Request — master (#99)
by Vladimir
02:58
created

FileAwareException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 38
ccs 11
cts 15
cp 0.7332
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getLineNumber() 0 4 1
A getPath() 0 4 1
A castException() 0 14 2
1
<?php
2
3
/**
4
 * @copyright 2018 Vladimir Jimenez
5
 * @license   https://github.com/stakx-io/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\Exception;
9
10
/**
11
 * Exception thrown when an error is found in a file.
12
 */
13
class FileAwareException extends \RuntimeException
14
{
15
    private $lineNumber;
16
    private $filePath;
17
18 11
    public function __construct($message = '', $code = 0, \Exception $previous = null, $path = '', $line = -1)
19
    {
20 11
        parent::__construct($message, $code, $previous);
21
22 11
        $this->filePath = $path;
23 11
        $this->lineNumber = $line;
24 11
    }
25
26
    public function getLineNumber()
27
    {
28
        return $this->lineNumber;
29
    }
30
31
    public function getPath()
32
    {
33
        return $this->filePath;
34
    }
35
36 1
    public static function castException(\Exception $e, $filePath)
37
    {
38 1
        $lineNumber = ($e instanceof \Twig_Error_Syntax) ? $e->getTemplateLine() : -1;
39
40 1
        $exception = new self(
41 1
            $e->getMessage(),
42 1
            $e->getCode(),
43
            $e,
44
            $filePath,
45
            $lineNumber
46
        );
47
48 1
        return $exception;
49
    }
50
}
51