apply Rector CI

This commit is contained in:
TomasVotruba 2019-12-29 22:47:10 +01:00
parent 42b34b66a1
commit c8316f4e0e
13 changed files with 26 additions and 49 deletions

View File

@ -8,6 +8,7 @@ use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Expr\Include_;
use PhpParser\Node\Scalar\MagicConst\Dir;
use PhpParser\Node\Scalar\String_;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
@ -85,7 +86,7 @@ PHP
}
}
$node->expr = new Concat(new Node\Scalar\MagicConst\Dir(), $node->expr);
$node->expr = new Concat(new Dir(), $node->expr);
return $node;
}

View File

@ -95,11 +95,6 @@ PHP
if (! $this->areNodesEqual($arrayDimFetch->var, $valuesExpr)) {
return false;
}
if (! $this->areNodesEqual($arrayDimFetch->dim, $keyExpr)) {
return false;
}
return true;
return $this->areNodesEqual($arrayDimFetch->dim, $keyExpr);
}
}

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Rector\DeadCode\Rector\Ternary;
use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
use PhpParser\Node\Expr\Ternary;
use PHPStan\Type\BooleanType;
use Rector\Rector\AbstractRector;
@ -80,6 +81,6 @@ PHP
return null;
}
return new Node\Expr\BinaryOp\BooleanAnd($node->cond, $node->if);
return new BooleanAnd($node->cond, $node->if);
}
}

View File

@ -125,11 +125,6 @@ PHP
if (! $this->isTraitMatch($class)) {
return true;
}
if ($this->classManipulator->hasPropertyName($class, 'id')) {
return true;
}
return false;
return $this->classManipulator->hasPropertyName($class, 'id');
}
}

View File

@ -6,6 +6,7 @@ namespace Rector\DoctrineGedmoToKnplabs\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Return_;
use PHPStan\Type\ArrayType;
@ -130,7 +131,7 @@ PHP
$this->classManipulator->addAsFirstTrait($node, 'Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait');
$node->implements[] = new Node\Name\FullyQualified('Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface');
$node->implements[] = new FullyQualified('Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface');
$this->addGetSluggableFieldsClassMethod($node, $slugFields);

View File

@ -240,7 +240,7 @@ PHP
throw new ShouldNotHappenException();
}
$classShortName = (string) $class->name . 'Translation';
$classShortName = $class->name . 'Translation';
$filePath = dirname($fileInfo->getRealPath()) . DIRECTORY_SEPARATOR . $classShortName . '.php';
$namespace = $class->getAttribute(AttributeKey::PARENT_NODE);

View File

@ -205,11 +205,6 @@ PHP
if ($phpDocInfo->hasByType(TreeParentTagValueNode::class)) {
return true;
}
if ($phpDocInfo->hasByType(TreeLevelTagValueNode::class)) {
return true;
}
return false;
return $phpDocInfo->hasByType(TreeLevelTagValueNode::class);
}
}

View File

@ -277,11 +277,6 @@ PHP
if ($classMethod === null) {
return true;
}
if ($classMethod->isStatic()) {
return true;
}
return false;
return $classMethod->isStatic();
}
}

View File

@ -7,6 +7,7 @@ namespace Rector\Nette\Rector\ClassMethod;
use Nette\Application\UI\Control;
use Nette\Application\UI\Presenter;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use Rector\Nette\NodeFactory\ActionRenderFactory;
@ -108,7 +109,7 @@ PHP
private function createRenderMethodCall(
ClassMethod $classMethod,
MagicTemplatePropertyCalls $magicTemplatePropertyCalls
): Node\Expr\MethodCall {
): MethodCall {
if ($this->isObjectType($classMethod, Presenter::class)) {
return $this->actionRenderFactory->createThisTemplateRenderMethodCall($magicTemplatePropertyCalls);
}

View File

@ -6,6 +6,8 @@ namespace Rector\Nette;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\ClassMethod;
@ -56,11 +58,11 @@ final class TemplatePropertyAssignCollector
$this->callableNodeTraverser->traverseNodesWithCallable(
(array) $classMethod->stmts,
function (Node $node): void {
if ($node instanceof Expr\MethodCall) {
if ($node instanceof MethodCall) {
$this->collectTemplateFileExpr($node);
}
if ($node instanceof Expr\Assign) {
if ($node instanceof Assign) {
$this->collectVariableFromAssign($node);
}
}
@ -69,7 +71,7 @@ final class TemplatePropertyAssignCollector
return new MagicTemplatePropertyCalls($this->templateFileExpr, $this->templateVariables, $this->nodesToRemove);
}
private function collectTemplateFileExpr(Expr\MethodCall $methodCall): void
private function collectTemplateFileExpr(MethodCall $methodCall): void
{
if ($this->nameResolver->isName($methodCall->name, 'render')) {
if (isset($methodCall->args[0])) {
@ -85,7 +87,7 @@ final class TemplatePropertyAssignCollector
}
}
private function collectVariableFromAssign(Expr\Assign $assign): void
private function collectVariableFromAssign(Assign $assign): void
{
// $this->template = x
if ($assign->var instanceof PropertyFetch) {

View File

@ -293,12 +293,12 @@ final class DocBlockManipulator
return;
}
if ($node->getDocComment()) {
if ($node->getDocComment() !== null) {
$phpDocInfo = $this->createPhpDocInfoFromNode($node);
$returnTagValueNode = $phpDocInfo->getByType(ReturnTagValueNode::class);
// overide existing type
if ($returnTagValueNode) {
if ($returnTagValueNode !== null) {
$newPHPStanPhpDocType = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode($newType);
$returnTagValueNode->type = $newPHPStanPhpDocType;
@ -663,12 +663,7 @@ final class DocBlockManipulator
if ($firstType instanceof FloatType && $secondType instanceof FloatType) {
return true;
}
if ($firstType instanceof BooleanType && $secondType instanceof BooleanType) {
return true;
}
return false;
return $firstType instanceof BooleanType && $secondType instanceof BooleanType;
}
private function areAliasedObjectMatchingFqnObject(Type $firstType, Type $secondType): bool

View File

@ -129,11 +129,6 @@ PHP
if ($this->isAtLeastPhpVersion(PhpVersionFeature::ARRAY_KEY_FIRST_LAST)) {
return false;
}
if (function_exists(self::ARRAY_KEY_FIRST) && function_exists(self::ARRAY_KEY_LAST)) {
return false;
}
return true;
return ! (function_exists(self::ARRAY_KEY_FIRST) && function_exists(self::ARRAY_KEY_LAST));
}
}

View File

@ -8,6 +8,7 @@ use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
@ -112,7 +113,7 @@ final class ClassManipulator
public function addAsFirstTrait(Class_ $class, string $traitName): void
{
$trait = new TraitUse([new Name\FullyQualified($traitName)]);
$trait = new TraitUse([new FullyQualified($traitName)]);
$this->addStatementToClassBeforeTypes($class, $trait, TraitUse::class, Property::class);
}
@ -417,7 +418,7 @@ final class ClassManipulator
continue;
}
$traitUse->traits[$key] = new Name\FullyQualified($newTrait);
$traitUse->traits[$key] = new FullyQualified($newTrait);
break;
}
}