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

CommitMsgProcessor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 30.91 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 8
Bugs 1 Features 0
Metric Value
wmc 8
c 8
b 1
f 0
lcom 1
cbo 1
dl 17
loc 55
ccs 22
cts 22
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 8 2
A enableHook() 17 17 3
A setExpressionRegular() 0 7 2
A hookName() 0 4 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
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