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

Core   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 49
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A error() 0 7 2
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