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

PxcmsInstaller   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 20
loc 60
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A inflectPackageVars() 0 12 3
A inflectModuleVars() 10 10 1
A inflectThemeVars() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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