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

TYPO3FlowInstaller   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A inflectPackageVars() 8 14 5

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
/**
5
 * An installer to handle TYPO3 Flow specifics when installing packages.
6
 */
7
class TYPO3FlowInstaller extends BaseInstaller
8
{
9
    protected $locations = array(
10
        'package'       => 'Packages/Application/{$name}/',
11
        'framework'     => 'Packages/Framework/{$name}/',
12
        'plugin'        => 'Packages/Plugins/{$name}/',
13
        'site'          => 'Packages/Sites/{$name}/',
14
        'boilerplate'   => 'Packages/Boilerplates/{$name}/',
15
        'build'         => 'Build/{$name}/',
16
    );
17
18
    /**
19
     * Modify the package name to be a TYPO3 Flow style key.
20
     *
21
     * @param  array $vars
22
     * @return array
23
     */
24
    public function inflectPackageVars($vars)
25
    {
26
        $autoload = $this->package->getAutoload();
27 View Code Duplication
        if (isset($autoload['psr-0']) && is_array($autoload['psr-0'])) {
28
            $namespace = key($autoload['psr-0']);
29
            $vars['name'] = str_replace('\\', '.', $namespace);
30
        }
31 View Code Duplication
        if (isset($autoload['psr-4']) && is_array($autoload['psr-4'])) {
32
            $namespace = key($autoload['psr-4']);
33
            $vars['name'] = rtrim(str_replace('\\', '.', $namespace), '.');
34
        }
35
36
        return $vars;
37
    }
38
}
39