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

PrePushConfigurator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 5
dl 25
loc 25
rs 10
ccs 11
cts 11
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A configure() 22 22 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\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