MicroweberInstaller   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 53
c 0
b 0
f 0
dl 0
loc 114
rs 10
wmc 18

8 Methods

Rating   Name   Duplication   Size   Complexity  
A inflectTemplateVars() 0 6 1
A inflectCoreVars() 0 7 1
A inflectModulesVars() 0 6 1
A inflectSkinVars() 0 6 1
B inflectPackageVars() 0 36 11
A inflectElementVars() 0 8 1
A inflectTemplatesVars() 0 6 1
A inflectModuleVars() 0 6 1
1
<?php
2
namespace Composer\Installers;
3
4
class MicroweberInstaller extends BaseInstaller
5
{
6
    protected $locations = array(
7
        'module' => 'userfiles/modules/{$install_item_dir}/',
8
        'module-skin' => 'userfiles/modules/{$install_item_dir}/templates/',
9
        'template' => 'userfiles/templates/{$install_item_dir}/',
10
        'element' => 'userfiles/elements/{$install_item_dir}/',
11
        'vendor' => 'vendor/{$install_item_dir}/',
12
        'components' => 'components/{$install_item_dir}/'
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
26
27
        if ($this->package->getTargetDir()) {
0 ignored issues
show
Bug introduced by
The method getTargetDir() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        if ($this->package->/** @scrutinizer ignore-call */ getTargetDir()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
            $vars['install_item_dir'] = $this->package->getTargetDir();
29
        } else {
30
            $vars['install_item_dir'] = $vars['name'];
31
            if ($vars['type'] === 'microweber-template') {
32
                return $this->inflectTemplateVars($vars);
33
            }
34
            if ($vars['type'] === 'microweber-templates') {
35
                return $this->inflectTemplatesVars($vars);
36
            }
37
            if ($vars['type'] === 'microweber-core') {
38
                return $this->inflectCoreVars($vars);
39
            }
40
            if ($vars['type'] === 'microweber-adapter') {
41
                return $this->inflectCoreVars($vars);
42
            }
43
            if ($vars['type'] === 'microweber-module') {
44
                return $this->inflectModuleVars($vars);
45
            }
46
            if ($vars['type'] === 'microweber-modules') {
47
                return $this->inflectModulesVars($vars);
48
            }
49
            if ($vars['type'] === 'microweber-skin') {
50
                return $this->inflectSkinVars($vars);
51
            }
52
            if ($vars['type'] === 'microweber-element' or $vars['type'] === 'microweber-elements') {
53
                return $this->inflectElementVars($vars);
54
            }
55
        }
56
57
58
        return $vars;
59
    }
60
61
    protected function inflectTemplateVars($vars)
62
    {
63
        $vars['install_item_dir'] = preg_replace('/-template$/', '', $vars['install_item_dir']);
64
        $vars['install_item_dir'] = preg_replace('/template-$/', '', $vars['install_item_dir']);
65
66
        return $vars;
67
    }
68
69
    protected function inflectTemplatesVars($vars)
70
    {
71
        $vars['install_item_dir'] = preg_replace('/-templates$/', '', $vars['install_item_dir']);
72
        $vars['install_item_dir'] = preg_replace('/templates-$/', '', $vars['install_item_dir']);
73
74
        return $vars;
75
    }
76
77
    protected function inflectCoreVars($vars)
78
    {
79
        $vars['install_item_dir'] = preg_replace('/-providers$/', '', $vars['install_item_dir']);
80
        $vars['install_item_dir'] = preg_replace('/-provider$/', '', $vars['install_item_dir']);
81
        $vars['install_item_dir'] = preg_replace('/-adapter$/', '', $vars['install_item_dir']);
82
83
        return $vars;
84
    }
85
86
    protected function inflectModuleVars($vars)
87
    {
88
        $vars['install_item_dir'] = preg_replace('/-module$/', '', $vars['install_item_dir']);
89
        $vars['install_item_dir'] = preg_replace('/module-$/', '', $vars['install_item_dir']);
90
91
        return $vars;
92
    }
93
94
    protected function inflectModulesVars($vars)
95
    {
96
        $vars['install_item_dir'] = preg_replace('/-modules$/', '', $vars['install_item_dir']);
97
        $vars['install_item_dir'] = preg_replace('/modules-$/', '', $vars['install_item_dir']);
98
99
        return $vars;
100
    }
101
102
    protected function inflectSkinVars($vars)
103
    {
104
        $vars['install_item_dir'] = preg_replace('/-skin$/', '', $vars['install_item_dir']);
105
        $vars['install_item_dir'] = preg_replace('/skin-$/', '', $vars['install_item_dir']);
106
107
        return $vars;
108
    }
109
110
    protected function inflectElementVars($vars)
111
    {
112
        $vars['install_item_dir'] = preg_replace('/-elements$/', '', $vars['install_item_dir']);
113
        $vars['install_item_dir'] = preg_replace('/elements-$/', '', $vars['install_item_dir']);
114
        $vars['install_item_dir'] = preg_replace('/-element$/', '', $vars['install_item_dir']);
115
        $vars['install_item_dir'] = preg_replace('/element-$/', '', $vars['install_item_dir']);
116
117
        return $vars;
118
    }
119
}
120