Completed
Push — feature/issue-45 ( 7692eb...be53bc )
by Mikaël
26:59
created

ReservedKeywords   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 65
ccs 21
cts 21
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A parseReservedKeywords() 0 16 2
A instance() 0 4 2
A is() 0 5 2
1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\ConfigurationReader;
4
5
class ReservedKeywords 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 12
    protected function __construct($filename)
28
    {
29 12
        $this->keywords = array();
30 12
        $this->parseReservedKeywords($filename);
31 8
    }
32
    /**
33
     * @param string $filename
34
     * @return ReservedKeywords
35
     */
36 12
    protected function parseReservedKeywords($filename)
37
    {
38 12
        $allKeywords = $this->parseSimpleArray($filename, self::MAIN_KEY);
39 8
        $caseSensitiveKeywords = $allKeywords[self::CASE_SENSITIVE_KEY];
40 8
        $caseInsensitiveKeywords = $allKeywords[self::CASE_INSENSITIVE_KEY];
41
42 8
        foreach ($caseInsensitiveKeywords as $index => $keyword) {
43 8
            $caseInsensitiveKeywords[$index] = strtolower($keyword);
44 6
        }
45
46 8
        $this->keywords = array(
47 8
            self::CASE_SENSITIVE_KEY => $caseSensitiveKeywords,
48 8
            self::CASE_INSENSITIVE_KEY => $caseInsensitiveKeywords
49 6
        );
50 8
        return $this;
51
    }
52
    /**
53
     * @param string options's file to parse
54
     * @return ReservedKeywords
55
     */
56 680
    public static function instance($filename = null)
57
    {
58 680
        return parent::instance(empty($filename) ? dirname(__FILE__) . '/../resources/config/reserved_keywords.yml' : $filename);
59
    }
60
    /**
61
     * @param string $keyword
62
     * @return bool
63
     */
64 672
    public function is($keyword)
65
    {
66 672
        return in_array($keyword, $this->keywords[self::CASE_SENSITIVE_KEY], true)
67 672
            || in_array(strtolower($keyword), $this->keywords[self::CASE_INSENSITIVE_KEY], true);
68
    }
69
}
70