CommitMsgConfigurator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 26
loc 26
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A configure() 17 17 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\Module\Configuration\Service;
4
5
use Composer\IO\IOInterface;
6
use PhpGitHooks\Module\Configuration\Domain\CommitMsg;
7
use PhpGitHooks\Module\Configuration\Domain\Enabled;
8
use PhpGitHooks\Module\Configuration\Domain\RegularExpression;
9
10 View Code Duplication
class CommitMsgConfigurator
0 ignored issues
show
Duplication introduced by
This class 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...
11
{
12
    /**
13
     * @param IOInterface $io
14
     * @param CommitMsg   $commitMsg
15
     *
16
     * @return CommitMsg
17
     */
18 2
    public static function configure(IOInterface $io, CommitMsg $commitMsg)
19
    {
20 2
        $answer = $io->ask(HookQuestions::COMMIT_MSG_HOOK, HookQuestions::DEFAULT_TOOL_ANSWER);
21
22 2
        $commitMsg = $commitMsg->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer)));
23
24 2
        if (true === $commitMsg->isEnabled()) {
25 1
            $regularExpressionAnswer = $io->ask(
26 1
                HookQuestions::COMMIT_MSG_REGULAR_EXPRESSION,
27 1
                HookQuestions::COMMIT_MSG_REGULAR_EXPRESSION_ANSWER
28
            );
29
30 1
            $commitMsg = $commitMsg->addRegularExpression(new RegularExpression($regularExpressionAnswer));
31
        }
32
33 2
        return $commitMsg;
34
    }
35
}
36