Completed
Push — develop ( 667cd2...043012 )
by Vladimir
01:48
created

FileAwareException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 5
crap 1
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 1
            $e,
44 1
            $filePath,
45 1
            $lineNumber
46
        );
47
48 1
        return $exception;
49
    }
50
}
51