Completed
Push — master ( f87faf...b3e46e )
by Pablo
03:15
created

PhpCsConfigData   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 1
dl 15
loc 60
ccs 27
cts 27
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createConfigData() 0 8 1
A getToolName() 0 4 1
A setEnabled() 15 15 3
A setStandard() 0 11 2

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
3
namespace PhpGitHooks\Application\CodeSniffer;
4
5
use PhpGitHooks\Application\Config\AbstractToolConfigData;
6
7
final class PhpCsConfigData extends AbstractToolConfigData
8
{
9
    const TOOL = 'phpcs';
10
    const STANDARD_KEY = 'standard';
11
    const STANDARDS_LIST = '[PSR2/PHPCS/MySource/Zend/Squiz/PSR1/PEAR]';
12
    const ENABLED_KEY = 'enabled';
13
    const DEFAULT_ANSWER = 'Y';
14
    /** @var string */
15
    private $standard = 'PSR2';
16
17
    /**
18
     * @param array $data
19
     *
20
     * @return array
21
     */
22 9
    public function createConfigData(array $data)
23
    {
24 9
        $this->configData = $data;
25 9
        $this->setEnabled();
26 9
        $this->setStandard();
27
28 9
        return $this->configData[self::TOOL];
29
    }
30
31
    /**
32
     * @return string
33
     */
34 9
    protected function getToolName()
35
    {
36 9
        return self::TOOL;
37
    }
38
39 9 View Code Duplication
    private function setEnabled()
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...
40
    {
41 9
        if (!isset($this->configData[self::TOOL])) {
42 6
            $answer = $this->setQuestion(
43 6
                sprintf('Do you want enable %s tool: ', strtoupper(self::TOOL)),
44 6
                self::DEFAULT_ANSWER,
45
                '[Y/n]'
46 6
            );
47 6
            $answer = self::DEFAULT_ANSWER === strtoupper($answer) ? true : false;
48 6
        } else {
49 3
            $answer = $this->configData[self::TOOL][self::ENABLED_KEY];
50
        }
51
52 9
        $this->enableTool($answer);
53 9
    }
54
55 9
    private function setStandard()
56
    {
57 9
        if (!isset($this->configData[self::TOOL][self::STANDARD_KEY])) {
58 8
            $answer = $this->setQuestion(
59 8
                sprintf('Which standard do you want to use for %s tool: ', strtoupper(self::TOOL)),
60 8
                $this->standard,
61
                self::STANDARDS_LIST
62 8
            );
63 8
            $this->configData[self::TOOL][self::STANDARD_KEY] = $answer;
64 8
        }
65 9
    }
66
}
67