Passed
Push — master ( 2dfc84...94e87c )
by Edward
05:17
created

PropertyLoader::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\UniLex\RegExp;
6
7
use Remorhaz\UniLex\RegExp\FSM\RangeSet;
8
9
final class PropertyLoader implements PropertyLoaderInterface
10
{
11
12
    private $index;
13
14
    private $cache = [];
15
16
    public static function create(): self
17
    {
18
        $index = require __DIR__ . '/PropertyIndex.php';
19
20
        return new self($index);
21
    }
22
23
    public function __construct(array $index)
24
    {
25
        $this->index = $index;
26
    }
27
28
    public function getPropertyRangeSet(string $name): RangeSet
29
    {
30
        if (!isset($this->cache[$name])) {
31
            $this->cache[$name] = $this->loadPropertyRangeSet($name);
32
        }
33
34
        return $this->cache[$name];
35
    }
36
37
    private function loadPropertyRangeSet(string $name): RangeSet
38
    {
39
        if (!isset($this->index[$name])) {
40
            throw new Exception\PropertyRangeSetNotFoundException($name);
0 ignored issues
show
Bug introduced by
The type Remorhaz\UniLex\RegExp\E...ngeSetNotFoundException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
41
        }
42
43
        $file = $this->index[$name];
44
        /** @noinspection PhpIncludeInspection */
45
        $rangeSet = require __DIR__ . $file;
46
        if ($rangeSet instanceof RangeSet) {
47
            return $rangeSet;
48
        }
49
50
        throw new Exception\UnicodePropertyRangeSetException($name);
0 ignored issues
show
Bug introduced by
The type Remorhaz\UniLex\RegExp\E...opertyRangeSetException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
51
    }
52
}
53