Passed
Push — master ( 1d60eb...03dff3 )
by Stiofan
06:44 queued 03:02
created

MicroweberInstaller::inflectPackageVars()   B

Complexity

Conditions 10
Paths 9

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
nc 9
nop 1
dl 0
loc 29
rs 7.6666
c 0
b 0
f 0

How to fix   Complexity   

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
namespace Composer\Installers;
3
4
class MicroweberInstaller extends BaseInstaller
5
{
6
    protected $locations = array(
7
        'module'      => 'userfiles/modules/{$name}/',
8
        'module-skin' => 'userfiles/modules/{$name}/templates/',
9
        'template'    => 'userfiles/templates/{$name}/',
10
        'element'     => 'userfiles/elements/{$name}/',
11
        'vendor'      => 'vendor/{$name}/',
12
        'components'  => 'components/{$name}/'
13
    );
14
15
    /**
16
     * Format package name.
17
     *
18
     * For package type microweber-module, cut off a trailing '-module' if present
19
     *
20
     * For package type microweber-template, cut off a trailing '-template' if present.
21
     *
22
     */
23
    public function inflectPackageVars($vars)
24
    {
25
        if ($vars['type'] === 'microweber-template') {
26
            return $this->inflectTemplateVars($vars);
27
        }
28
        if ($vars['type'] === 'microweber-templates') {
29
            return $this->inflectTemplatesVars($vars);
30
        }
31
        if ($vars['type'] === 'microweber-core') {
32
            return $this->inflectCoreVars($vars);
33
        }
34
        if ($vars['type'] === 'microweber-adapter') {
35
            return $this->inflectCoreVars($vars);
36
        }
37
        if ($vars['type'] === 'microweber-module') {
38
            return $this->inflectModuleVars($vars);
39
        }
40
        if ($vars['type'] === 'microweber-modules') {
41
            return $this->inflectModulesVars($vars);
42
        }
43
        if ($vars['type'] === 'microweber-skin') {
44
            return $this->inflectSkinVars($vars);
45
        }
46
        if ($vars['type'] === 'microweber-element' or $vars['type'] === 'microweber-elements') {
47
            return $this->inflectElementVars($vars);
48
        }
49
50
        return $vars;
51
    }
52
53 View Code Duplication
    protected function inflectTemplateVars($vars)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        $vars['name'] = preg_replace('/-template$/', '', $vars['name']);
56
        $vars['name'] = preg_replace('/template-$/', '', $vars['name']);
57
58
        return $vars;
59
    }
60
61 View Code Duplication
    protected function inflectTemplatesVars($vars)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        $vars['name'] = preg_replace('/-templates$/', '', $vars['name']);
64
        $vars['name'] = preg_replace('/templates-$/', '', $vars['name']);
65
66
        return $vars;
67
    }
68
69 View Code Duplication
    protected function inflectCoreVars($vars)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        $vars['name'] = preg_replace('/-providers$/', '', $vars['name']);
72
        $vars['name'] = preg_replace('/-provider$/', '', $vars['name']);
73
        $vars['name'] = preg_replace('/-adapter$/', '', $vars['name']);
74
75
        return $vars;
76
    }
77
78 View Code Duplication
    protected function inflectModuleVars($vars)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
    {
80
        $vars['name'] = preg_replace('/-module$/', '', $vars['name']);
81
        $vars['name'] = preg_replace('/module-$/', '', $vars['name']);
82
83
        return $vars;
84
    }
85
86 View Code Duplication
    protected function inflectModulesVars($vars)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88
        $vars['name'] = preg_replace('/-modules$/', '', $vars['name']);
89
        $vars['name'] = preg_replace('/modules-$/', '', $vars['name']);
90
91
        return $vars;
92
    }
93
94 View Code Duplication
    protected function inflectSkinVars($vars)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
95
    {
96
        $vars['name'] = preg_replace('/-skin$/', '', $vars['name']);
97
        $vars['name'] = preg_replace('/skin-$/', '', $vars['name']);
98
99
        return $vars;
100
    }
101
102 View Code Duplication
    protected function inflectElementVars($vars)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
    {
104
        $vars['name'] = preg_replace('/-elements$/', '', $vars['name']);
105
        $vars['name'] = preg_replace('/elements-$/', '', $vars['name']);
106
        $vars['name'] = preg_replace('/-element$/', '', $vars['name']);
107
        $vars['name'] = preg_replace('/element-$/', '', $vars['name']);
108
109
        return $vars;
110
    }
111
}
112