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

PxcmsInstaller::inflectThemeVars()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
namespace Composer\Installers;
3
4
class PxcmsInstaller extends BaseInstaller
5
{
6
    protected $locations = array(
7
        'module' => 'app/Modules/{$name}/',
8
        'theme' => 'themes/{$name}/',
9
    );
10
11
    /**
12
     * Format package name.
13
     *
14
     * @param array $vars
15
     *
16
     * @return array
17
     */
18
    public function inflectPackageVars($vars)
19
    {
20
        if ($vars['type'] === 'pxcms-module') {
21
            return $this->inflectModuleVars($vars);
22
        }
23
24
        if ($vars['type'] === 'pxcms-theme') {
25
            return $this->inflectThemeVars($vars);
26
        }
27
28
        return $vars;
29
    }
30
31
    /**
32
     * For package type pxcms-module, cut off a trailing '-plugin' if present.
33
     *
34
     * return string
35
     */
36 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...
37
    {
38
        $vars['name'] = str_replace('pxcms-', '', $vars['name']);       // strip out pxcms- just incase (legacy)
39
        $vars['name'] = str_replace('module-', '', $vars['name']);      // strip out module-
40
        $vars['name'] = preg_replace('/-module$/', '', $vars['name']);  // strip out -module
41
        $vars['name'] = str_replace('-', '_', $vars['name']);           // make -'s be _'s
42
        $vars['name'] = ucwords($vars['name']);                         // make module name camelcased
43
44
        return $vars;
45
    }
46
47
48
    /**
49
     * For package type pxcms-module, cut off a trailing '-plugin' if present.
50
     *
51
     * return string
52
     */
53 View Code Duplication
    protected function inflectThemeVars($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'] = str_replace('pxcms-', '', $vars['name']);       // strip out pxcms- just incase (legacy)
56
        $vars['name'] = str_replace('theme-', '', $vars['name']);       // strip out theme-
57
        $vars['name'] = preg_replace('/-theme$/', '', $vars['name']);   // strip out -theme
58
        $vars['name'] = str_replace('-', '_', $vars['name']);           // make -'s be _'s
59
        $vars['name'] = ucwords($vars['name']);                         // make module name camelcased
60
61
        return $vars;
62
    }
63
}
64