Completed
Branch module_structure (3116d9)
by Pablo
02:56
created

PrePushConfigurator::configure()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 13

Duplication

Lines 22
Ratio 100 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 22
loc 22
rs 9.2
ccs 11
cts 11
cp 1
cc 2
eloc 13
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\Enabled;
7
use PhpGitHooks\Module\Configuration\Domain\Message;
8
use PhpGitHooks\Module\Configuration\Domain\Messages;
9
use PhpGitHooks\Module\Configuration\Domain\PrePush;
10
11 View Code Duplication
class PrePushConfigurator
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...
12
{
13 1
    public static function configure(IOInterface $input, PrePush $prePush)
14
    {
15 1
        $answer = $input->ask(HookQuestions::PRE_PUSH_HOOK_QUESTION, HookQuestions::DEFAULT_TOOL_ANSWER);
16
17 1
        $prePush = $prePush->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer)));
18
19 1
        if (true === $prePush->isEnabled()) {
20
            $rightMessageAnswer = $input
21 1
                ->ask(HookQuestions::PRE_PUSH_RIGHT_MESSAGE, HookQuestions::PRE_PUSH_RIGHT_MESSAGE_DEFAULT);
22
            $errorMessageAnswer = $input
23 1
                ->ask(HookQuestions::PRE_PUSH_ERROR_MESSAGE, HookQuestions::PRE_PUSH_ERROR_MESSAGE_DEFAULT);
24
25 1
            $prePush = $prePush->setMessages(
26 1
                new Messages(
27 1
                    new Message($rightMessageAnswer),
28 1
                    new Message($errorMessageAnswer)
29
                )
30
            );
31
        }
32
33 1
        return $prePush;
34
    }
35
}
36