for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Storeman\Cli\ConflictHandler;
use Storeman\Cli\ConsoleStyle;
use Storeman\ConflictHandler\ConflictHandlerInterface;
use Storeman\IndexObject;
/**
* This implementation of a conflict handler asks the user to resolve it manually.
*/
class ConsolePromptConflictHandler implements ConflictHandlerInterface
{
* @var ConsoleStyle
protected $consoleStyle;
public function __construct(ConsoleStyle $consoleStyle)
$this->consoleStyle = $consoleStyle;
}
* {@inheritdoc}
public function handleConflict(IndexObject $remoteObject, IndexObject $localObject = null, IndexObject $lastLocalObject = null): int
$text = <<<TXT
<question>Encountered conflict at {$remoteObject->getRelativePath()}</question>
TXT;
$this->consoleStyle->writeln($text);
$return = null;
do
$choice = $this->consoleStyle->choice('Would you like to use the local (l) or the remote (r) version?', ['l', 'r']);
switch ($choice)
case 'l': $return = ConflictHandlerInterface::USE_LOCAL; break 2;
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.
As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.
break
switch ($expr) { case "A": doSomething(); break; //wrong case "B": doSomething(); break; //right case "C:": doSomething(); return true; //right }
case 'r': $return = ConflictHandlerInterface::USE_REMOTE; break 2;
$this->consoleStyle->warning("Invalid choice");
while(true);
return $return;
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.