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

CompilerException::isPositionDefined()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
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