Completed
Push — feature/issue-54 ( 0869de...548adc )
by Mikaël
31:27
created

AbstractReservedKeywords::parseReservedKeywords()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\ConfigurationReader;
4
5
class AbstractReservedKeywords extends AbstractYamlReader
6
{
7
    /**
8
     * @var string
9
     */
10
    const MAIN_KEY = 'reserved_keywords';
11
    /**
12
     * @var string
13
     */
14
    const CASE_SENSITIVE_KEY = 'case_sensitive';
15
    /**
16
     * @var string
17
     */
18
    const CASE_INSENSITIVE_KEY = 'case_insensitive';
19
    /**
20
     * List of PHP reserved keywords from config file
21
     * @var array
22
     */
23
    protected $keywords;
24
    /**
25
     * @param string $filename
26
     */
27
    protected function __construct($filename)
28
    {
29
        $this->keywords = array();
30
        $this->parseReservedKeywords($filename);
31
    }
32
    /**
33
     * @param string $filename
34
     * @return AbstractReservedKeywords
35
     */
36
    protected function parseReservedKeywords($filename)
37
    {
38
        $allKeywords = $this->parseSimpleArray($filename, self::MAIN_KEY);
39
        $caseSensitiveKeywords = $allKeywords[self::CASE_SENSITIVE_KEY];
40
        $caseInsensitiveKeywords = array_map('strtolower', $allKeywords[self::CASE_INSENSITIVE_KEY]);
41
42
        $this->keywords = array_merge_recursive($this->keywords, array(
43
            self::CASE_SENSITIVE_KEY => $caseSensitiveKeywords,
44
            self::CASE_INSENSITIVE_KEY => $caseInsensitiveKeywords
45
        ));
46
        return $this;
47
    }
48
    /**
49
     * @throws \InvalidArgumentException
50
     * @param string options's file to parse
51
     * @return AbstractReservedKeywords
52
     */
53
    public static function instance($filename = null)
54
    {
55
        return parent::instance($filename);
56
    }
57
    /**
58
     * @param string $keyword
59
     * @return bool
60
     */
61
    public function is($keyword)
62
    {
63
        return in_array($keyword, $this->keywords[self::CASE_SENSITIVE_KEY], true)
64
            || in_array(strtolower($keyword), $this->keywords[self::CASE_INSENSITIVE_KEY], true);
65
    }
66
}
67