Passed
Push — master ( 6c3f09...c54108 )
by William
03:43
created

Core::error()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\SqlParser;
6
7
use Exception;
8
9
/**
10
 * Defines the core helper infrastructure of the library.
11
 */
12
class Core
13
{
14
    /**
15
     * Whether errors should throw exceptions or just be stored.
16
     *
17
     * @see static::$errors
18
     *
19
     * @var bool
20
     */
21
    public $strict = false;
22
23
    /**
24
     * List of errors that occurred during lexing.
25
     *
26
     * Usually, the lexing does not stop once an error occurred because that
27
     * error might be false positive or a partial result (even a bad one)
28
     * might be needed.
29
     *
30
     * @see Core::error()
31
     *
32
     * @var Exception[]
33
     */
34
    public $errors = [];
35
36 1320
    public function __construct()
37
    {
38 1320
        if (Context::$keywords !== []) {
39 1320
            return;
40
        }
41
42
        Context::load();
43
    }
44
45
    /**
46
     * Creates a new error log.
47
     *
48
     * @param Exception $error the error exception
49
     *
50
     * @return void
51
     *
52
     * @throws Exception throws the exception, if strict mode is enabled.
53
     */
54 316
    public function error($error)
55
    {
56 316
        if ($this->strict) {
57 4
            throw $error;
58
        }
59
60 312
        $this->errors[] = $error;
61
    }
62
}
63