Completed
Pull Request — master (#35)
by Saif Eddin
02:55 queued 38s
created

ReservedWordReplacer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 55
ccs 39
cts 42
cp 0.9286
rs 10
c 1
b 1
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B replace() 0 52 5
1
<?php
2
3
namespace PhpToZephir;
4
5
class ReservedWordReplacer
6
{
7 82
    public function replace($string)
8
    {
9 82
        if ($string === null) {
10
            return $string;
11
        }
12
13
        $reservedWord = array(
14 82
            'inline' => 'inlinee',
15 82
            'Inline' => 'Inlinee',
16 82
            'array' => 'myArray',
17 82
            'class' => 'classs',
18 82
            'var' => 'varr',
19 82
            'bool' => 'booll',
20 82
            'namespace' => 'namespacee',
21 82
            'const' => 'constt',
22 82
            'enum' => 'enumm',
23 82
            'interface' => 'interfacee',
24 82
            'loop' => 'loopp',
25 82
            'for' => 'forr',
26 82
            'foreach' => 'foreachh',
27 82
            'if' => 'iff',
28 82
            'elseif' => 'elseiff',
29 82
            'else' => 'elsee',
30 82
            'function' => 'functionn',
31 82
            'private' => 'privatee',
32 82
            'protected' => 'protectedd',
33 82
            'public' => 'publicc',
34 82
            'boolean' => 'booleann',
35 82
            'return' => 'returnn',
36 82
            'abstract' => 'abstractt',
37 82
            'resource' => 'resourcee',
38 82
            'callable' => 'callablee',
39 82
            'string' => 'stringg',
40 82
            'float' => 'floatt',
41 82
            'int' => 'intt',
42 82
            'internal' => 'internall',
43
            'deprecated' => 'deprecatedd'
44 82
        );
45
46 82
        foreach ($reservedWord as $word => $replacement) {
47 82
            if ($string == $word) {
48 1
                $string = $replacement;
49 1
                break;
50
            }
51 82
        }
52
53 82
        if (ctype_upper($string)) {
54
            $string = strtolower($string);
55
        }
56
57 82
        return $string;
58
    }
59
}
60