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

PhpCsConfigData::checkConfigData()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 12
loc 12
rs 9.4285
cc 3
eloc 6
nc 3
nop 0
ccs 5
cts 7
cp 0.7143
crap 3.2098

1 Method

Rating   Name   Duplication   Size   Complexity  
A PhpCsConfigData::getToolName() 0 4 1
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