Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return error code on diff with dry-run option #805

Merged
merged 2 commits into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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