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

AbstractReservedKeywords   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 1
cbo 1
dl 0
loc 62
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A parseReservedKeywords() 0 12 1
A instance() 0 4 1
A is() 0 5 2
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