Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractReservedWord
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 is
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 parseReservedKeywords
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace WsdlToPhp\PackageGenerator\ConfigurationReader;
6
7abstract 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    protected function __construct(string $filename)
16    {
17        $this->parseReservedKeywords($filename);
18    }
19
20    public function is(string $keyword): bool
21    {
22        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    protected function parseReservedKeywords(string $filename): AbstractReservedWord
26    {
27        $allKeywords = $this->parseSimpleArray($filename, self::MAIN_KEY);
28        $caseSensitiveKeywords = $allKeywords[self::CASE_SENSITIVE_KEY];
29        $caseInsensitiveKeywords = array_map('strtolower', $allKeywords[self::CASE_INSENSITIVE_KEY]);
30        $this->keywords = array_merge_recursive($this->keywords, [
31            self::CASE_SENSITIVE_KEY => $caseSensitiveKeywords,
32            self::CASE_INSENSITIVE_KEY => $caseInsensitiveKeywords,
33        ]);
34
35        return $this;
36    }
37}