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

MicroweberInstaller::inflectSkinVars()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 7
loc 7
rs 10
c 0
b 0
f 0
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