Test Failed
Push — master ( 33bfdc...47f867 )
by Kirill
02:32
created

CompilerException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 55
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 2
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A rename() 0 6 1
A in() 0 6 1
A throwsIn() 0 10 2
A isPositionDefined() 0 4 1
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Exception;
11
12
use Railt\Io\Exception\ExternalExceptionInterface;
13
use Railt\Io\Exception\ExternalFileException;
14
use Railt\Io\Readable;
15
use Railt\Reflection\Contracts\Definition;
16
17
/**
18
 * Class CompilerException
19
 */
20
class CompilerException extends ExternalFileException
21
{
22
    /**
23
     * @var bool
24
     */
25
    private $defined = false;
26
27
    /**
28
     * @param string $message
29
     * @param array $args
30
     * @return CompilerException
31
     */
32
    public function rename(string $message, ...$args): self
33
    {
34
        $this->message = \sprintf($message, ...$args);
35
36
        return $this;
37
    }
38
39
    /**
40
     * @param Definition $def
41
     * @return CompilerException
42
     */
43
    public function in(Definition $def): self
44
    {
45
        $this->throwsIn($def->getFile(), $def->getLine(), $def->getColumn());
46
47
        return $this;
48
    }
49
50
    /**
51
     * @param Readable $file
52
     * @param int $offsetOrLine
53
     * @param int|null $column
54
     * @return ExternalExceptionInterface|self
55
     */
56
    public function throwsIn(Readable $file, int $offsetOrLine = 0, int $column = null): ExternalExceptionInterface
57
    {
58
        if (! $this->defined) {
59
            $this->defined = true;
60
61
            return parent::throwsIn($file, $offsetOrLine, $column);
62
        }
63
64
        return $this;
65
    }
66
67
    /**
68
     * @return bool
69
     */
70
    public function isPositionDefined(): bool
71
    {
72
        return $this->defined;
73
    }
74
}
75