CommitMsgConfigurator::configure()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 17
loc 17
rs 9.7
c 0
b 0
f 0
ccs 9
cts 9
cp 1
cc 2
nc 2
nop 2
crap 2
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