Completed
Pull Request — master (#41)
by Vladimir
02:46
created

FileAwareException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
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
 * @package allejo\stakx\Exception
14
 */
15
class FileAwareException extends \RuntimeException
16
{
17
    private $lineNumber;
18
    private $filePath;
19
20 11
    public function __construct($message = "", $code = 0, \Exception $previous = null, $path = "", $line = -1)
21
    {
22 11
        parent::__construct($message, $code, $previous);
23
24 11
        $this->filePath = $path;
25 11
        $this->lineNumber = $line;
26 11
    }
27
28
    public function getLineNumber ()
29
    {
30
        return $this->lineNumber;
31
    }
32
33
    public function getPath ()
34
    {
35
        return $this->filePath;
36
    }
37
38 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 2.

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...
39
    {
40 1
        $lineNumber = ($e instanceof \Twig_Error_Syntax) ? $e->getTemplateLine() : -1;
41
42 1
        $exception = new self(
43 1
            $e->getMessage(),
44 1
            $e->getCode(),
45
            $e,
46
            $filePath,
47
            $lineNumber
48
        );
49
50 1
        return $exception;
51
    }
52
}