Completed
Push — master ( 0e2cf8...a9244b )
by Pablo
06:07
created

CommitMsgProcessor::hookName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace PhpGitHooks\Application\Composer;
4
5
use PhpGitHooks\Infrastructure\Composer\ProcessorInterface;
6
7
final class CommitMsgProcessor extends Processor implements ProcessorInterface
8
{
9
    /**
10
     * @param array $configData
11
     *
12
     * @return array
13
     */
14 5
    public function execute(array $configData)
15
    {
16 5
        if ($this->enableHook($configData)) {
17 3
            $this->setExpressionRegular();
18 3
        }
19
20 5
        return $this->configData;
21
    }
22
23
    /**
24
     * @param array $configData
25
     *
26
     * @return bool
27
     */
28 5 View Code Duplication
    private function enableHook(array $configData)
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...
29
    {
30 5
        if (!isset($configData[$this->hookName()])) {
31 3
            $enable = $this->setQuestion('Do you want enable commit-msg hook?', '[Y/n]', 'Y');
32 3
            $enabled = 'Y' === strtoupper($enable) ? true : false;
33
34 3
            $this->configData[$this->hookName()] = [
35 3
                'enabled' => $enabled,
36
            ];
37
38 3
            return $enabled;
39
        }
40
41 2
        $this->configData = $configData;
42
43 2
        return $configData[$this->hookName()]['enabled'];
44
    }
45
46 3
    private function setExpressionRegular()
47
    {
48 3
        if (!isset($this->configData[$this->hookName()]['regular-expression'])) {
49 2
            $answer = $this->setQuestion('Write an expression regular', '[#[0-9]{2,7}]', '#[0-9]{2,7}');
50 2
            $this->configData[$this->hookName()]['regular-expression'] = $answer;
51 2
        }
52 3
    }
53
54
    /**
55
     * @return string
56
     */
57 5
    public function hookName()
58
    {
59 5
        return 'commit-msg';
60
    }
61
}
62