Skip to content

Commit

Permalink
Merge pull request #805 from Soullivaneuh/dry-run-return-code
Browse files Browse the repository at this point in the history
Return error code on diff with dry-run option
  • Loading branch information
TomasVotruba authored Dec 3, 2018
2 parents 7039ce8 + 4762edd commit 7528112
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->symfonyStyle->success('Rector is done!');

if ($this->parameterProvider->provideParameter(Option::OPTION_DRY_RUN) && count($this->fileDiffs)) {
return Shell::CODE_ERROR;
}

return Shell::CODE_SUCCESS;
}

Expand Down
5 changes: 2 additions & 3 deletions src/PhpParser/Node/Commander/NodeAddingCommander.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,19 @@ private function wrapToExpression(Node $node): Stmt

private function createNodeVisitor(): NodeVisitor
{
return new class($this->nodesToAdd) extends NodeVisitorAbstract {
return new class($this->nodesToAdd) extends NodeVisitorAbstract
{
/**
* @var Stmt[][]
*/
private $nodesToAdd = [];

/**
* @param Stmt[][] $nodesToAdd
*/
public function __construct(array $nodesToAdd)
{
$this->nodesToAdd = $nodesToAdd;
}

/**
* @return Node[]|Node|null
*/
Expand Down
5 changes: 2 additions & 3 deletions src/PhpParser/Node/Commander/NodeRemovingCommander.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,19 @@ public function isActive(): bool

private function createNodeVisitor(): NodeVisitor
{
return new class($this->nodesToRemove) extends NodeVisitorAbstract {
return new class($this->nodesToRemove) extends NodeVisitorAbstract
{
/**
* @var Stmt[]
*/
private $nodesToRemove = [];

/**
* @param Stmt[] $nodesToRemove
*/
public function __construct(array $nodesToRemove)
{
$this->nodesToRemove = $nodesToRemove;
}

/**
* @return int|Node|Node[]|null
*/
Expand Down
7 changes: 2 additions & 5 deletions src/PhpParser/Node/Commander/PropertyAddingCommander.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,16 @@ public function isActive(): bool

private function createNodeVisitor(): NodeVisitor
{
return new class($this->classMaintainer, $this->propertiesByClass) extends NodeVisitorAbstract {
return new class($this->classMaintainer, $this->propertiesByClass) extends NodeVisitorAbstract
{
/**
* @var ClassMaintainer
*/
private $classMaintainer;

/**
* @var VariableInfo[][]
*/
private $propertiesByClass = [];

/**
* @param VariableInfo[][] $propertiesByClass
*/
Expand All @@ -77,7 +76,6 @@ public function __construct(ClassMaintainer $classMaintainer, array $propertiesB
$this->classMaintainer = $classMaintainer;
$this->propertiesByClass = $propertiesByClass;
}

public function enterNode(Node $node): ?Node
{
if (! $node instanceof Class_ || $node->isAnonymous()) {
Expand All @@ -86,7 +84,6 @@ public function enterNode(Node $node): ?Node

return $this->processClassNode($node);
}

private function processClassNode(Class_ $classNode): Class_
{
$variableInfos = $this->propertiesByClass[spl_object_hash($classNode)] ?? [];
Expand Down
5 changes: 2 additions & 3 deletions src/PhpParser/NodeTraverser/CallableNodeTraverser.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ public function traverseNodesWithCallable(array $nodes, callable $callable): arr

private function createNodeVisitor(callable $callable): NodeVisitor
{
return new class($callable) extends NodeVisitorAbstract {
return new class($callable) extends NodeVisitorAbstract
{
/**
* @var callable
*/
private $callable;

public function __construct(callable $callable)
{
$this->callable = $callable;
}

/**
* @return int|Node|null
*/
Expand Down

0 comments on commit 7528112

Please sign in to comment.