Completed
Push — master ( a4e6dd...a851cc )
by Arne
02:45
created

ConsolePromptConflictHandler::handleConflict()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 25
rs 8.5806
cc 4
eloc 14
nc 3
nop 3
1
<?php
2
3
namespace Storeman\Cli\ConflictHandler;
4
5
use Storeman\Cli\ConsoleStyle;
6
use Storeman\ConflictHandler\ConflictHandlerInterface;
7
use Storeman\IndexObject;
8
9
/**
10
 * This implementation of a conflict handler asks the user to resolve it manually.
11
 */
12
class ConsolePromptConflictHandler implements ConflictHandlerInterface
13
{
14
    /**
15
     * @var ConsoleStyle
16
     */
17
    protected $consoleStyle;
18
19
    public function __construct(ConsoleStyle $consoleStyle)
20
    {
21
        $this->consoleStyle = $consoleStyle;
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function handleConflict(IndexObject $remoteObject, IndexObject $localObject = null, IndexObject $lastLocalObject = null): int
28
    {
29
        $text = <<<TXT
30
<question>Encountered conflict at {$remoteObject->getRelativePath()}</question>
31
TXT;
32
33
        $this->consoleStyle->writeln($text);
34
35
        $return = null;
36
        do
37
        {
38
            $choice = $this->consoleStyle->choice('Would you like to use the local (l) or the remote (r) version?', ['l', 'r']);
39
40
            switch ($choice)
41
            {
42
                case 'l': $return = ConflictHandlerInterface::USE_LOCAL; break 2;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
43
                case 'r': $return = ConflictHandlerInterface::USE_REMOTE; break 2;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
44
            }
45
46
            $this->consoleStyle->warning("Invalid choice");
47
        }
48
        while(true);
49
50
        return $return;
51
    }
52
}
53