Completed
Push — master ( b785dd...3df4eb )
by Vladimir
03:46
created

FileAwareException::castException()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 0
loc 14
ccs 9
cts 9
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/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)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $e. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
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
            $lineNumber
46 1
        );
47
48 1
        return $exception;
49
    }
50
}
51