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

ReservedWordReplacer::replace()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 52
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 39
CRAP Score 5.009

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 52
ccs 39
cts 42
cp 0.9286
rs 8.6868
c 1
b 1
f 0
cc 5
eloc 41
nc 7
nop 1
crap 5.009

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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