add PR annotate workflow

This commit is contained in:
TomasVotruba 2020-03-19 01:23:31 +01:00
parent 97f5ff545c
commit eca4d54f58
6 changed files with 50 additions and 13 deletions

View File

@ -0,0 +1,22 @@
# see https://github.com/staabm/annotate-pull-request-from-checkstyle
name: Anotate Checkstyle
on:
pull_request: null
push:
branches:
- master
jobs:
check_fixtures:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v1
with:
php-version: 7.2
coverage: none # disable xdebug, pcov
tools: cs2pr
- run: composer install --no-progress
- run: |
bin/rector p abz/DeadCode.php --set dead-code -n --autoload-file abz/DeadCode.php --output-format=checkstyle | cs2pr

View File

@ -124,10 +124,13 @@ PHP
/** @var PhpDocInfo|null $phpDocInfo */
$phpDocInfo = $node->getAttribute(AttributeKey::PHP_DOC_INFO);
if ($phpDocInfo === null) {
return $node;
return null;
}
$this->docBlockNameImporter->importNames($phpDocInfo, $node);
$hasChanged = $this->docBlockNameImporter->importNames($phpDocInfo, $node);
if (! $hasChanged) {
return null;
}
return $node;
}

View File

@ -66,8 +66,6 @@ PHP
}
$isDeadAfterReturn = false;
$isDeadAfterReturnRemoved = false;
foreach ($node->stmts as $key => $stmt) {
if ($isDeadAfterReturn) {
// keep comment
@ -75,8 +73,7 @@ PHP
continue;
}
unset($node->stmts[$key]);
$isDeadAfterReturnRemoved = true;
$this->removeStmt($node, $key);
}
if ($stmt instanceof Return_) {
@ -85,10 +82,6 @@ PHP
}
}
if (! $isDeadAfterReturnRemoved) {
return null;
}
return $node;
return null;
}
}

View File

@ -80,7 +80,7 @@ PHP
continue;
}
unset($node->stmts[$key]);
$this->removeStmt($node, $key);
}
$node->stmts = array_merge((array) $node->stmts, (array) $proccesed);

View File

@ -140,7 +140,7 @@ final class Application extends SymfonyApplication
$input->getParameterOption('--output-format') === CheckstyleOutputFormatter::NAME ||
$input->getParameterOption('-o') === CheckstyleOutputFormatter::NAME
);
return !$hasCheckstyleOutput;
return ! $hasCheckstyleOutput;
}
private function removeUnusedOptions(InputDefinition $inputDefinition): void

View File

@ -6,8 +6,12 @@ namespace Rector\Core\Rector\AbstractRector;
use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use Rector\ChangesReporting\Rector\AbstractRector\RectorChangeCollectorTrait;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Doctrine\AbstractRector\DoctrineTrait;
trait AbstractRectorTrait
@ -43,4 +47,19 @@ trait AbstractRectorTrait
return ! Strings::contains($name, 'AnonymousClass');
}
/**
* @param Closure|ClassMethod|Function_ $node
*/
protected function removeStmt(Node $node, $key): void
{
if ($node->stmts === null) {
throw new ShouldNotHappenException();
}
// notify about remove node
$this->notifyNodeChangeFileInfo($node->stmts[$key]);
unset($node->stmts[$key]);
}
}