AbstractReservedWord::is()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WsdlToPhp\PackageGenerator\ConfigurationReader;
6
7
abstract class AbstractReservedWord extends AbstractYamlReader
8
{
9
    public const MAIN_KEY = 'reserved_keywords';
10
    public const CASE_SENSITIVE_KEY = 'case_sensitive';
11
    public const CASE_INSENSITIVE_KEY = 'case_insensitive';
12
13
    protected array $keywords = [];
14
15 12
    protected function __construct(string $filename)
16
    {
17 12
        $this->parseReservedKeywords($filename);
18
    }
19
20 832
    public function is(string $keyword): bool
21
    {
22 832
        return in_array($keyword, $this->keywords[self::CASE_SENSITIVE_KEY], true) || in_array(mb_strtolower($keyword), $this->keywords[self::CASE_INSENSITIVE_KEY], true);
23
    }
24
25 12
    protected function parseReservedKeywords(string $filename): AbstractReservedWord
26
    {
27 12
        $allKeywords = $this->parseSimpleArray($filename, self::MAIN_KEY);
28 10
        $caseSensitiveKeywords = $allKeywords[self::CASE_SENSITIVE_KEY];
29 10
        $caseInsensitiveKeywords = array_map('strtolower', $allKeywords[self::CASE_INSENSITIVE_KEY]);
30 10
        $this->keywords = array_merge_recursive($this->keywords, [
31 10
            self::CASE_SENSITIVE_KEY => $caseSensitiveKeywords,
32 10
            self::CASE_INSENSITIVE_KEY => $caseInsensitiveKeywords,
33 10
        ]);
34
35 10
        return $this;
36
    }
37
}
38