fix static

This commit is contained in:
Tomas Votruba 2019-05-31 08:52:12 +02:00
parent 6398090e1a
commit f6da9d2854
7 changed files with 32 additions and 25 deletions

View File

@ -18,23 +18,23 @@
"nette/robot-loader": "^3.1",
"nette/utils": "^2.5|^3.0",
"nikic/php-parser": "^4.2.2",
"phpstan/phpdoc-parser": "0.3.3",
"phpstan/phpdoc-parser": "^0.3.4",
"phpstan/phpstan": "0.11.6",
"sebastian/diff": "^3.0",
"symfony/console": "^3.4|^4.2",
"symfony/dependency-injection": "^3.4|^4.2",
"symfony/finder": "^3.4|^4.2",
"symfony/process": "^3.4|^4.2",
"symplify/package-builder": "^6.0"
"symplify/package-builder": "^6.0.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.14",
"ocramius/package-versions": "^1.4",
"phpunit/phpunit": "^7.5|^8.0",
"symplify/changelog-linker": "^6.0",
"symplify/easy-coding-standard": "^6.0",
"symplify/monorepo-builder": "^6.0",
"symplify/phpstan-extensions": "^6.0",
"symplify/changelog-linker": "^6.0.1",
"symplify/easy-coding-standard": "^6.0.1",
"symplify/monorepo-builder": "^6.0.1",
"symplify/phpstan-extensions": "^6.0.1",
"thecodingmachine/phpstan-strict-rules": "^0.11",
"tracy/tracy": "^2.5"
},

View File

@ -2,7 +2,6 @@
namespace Rector\CodeQuality\Rector\Array_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
@ -15,6 +14,7 @@ use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Param;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use Rector\NodeContainer\ParsedNodesByType;
use Rector\Rector\AbstractRector;

View File

@ -8,7 +8,6 @@ use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Nop;
use Rector\Exception\ShouldNotHappenException;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;

View File

@ -2,9 +2,9 @@
namespace Rector\Php\Rector\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Scalar\LNumber;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;

View File

@ -93,15 +93,7 @@ CODE_SAMPLE
return null;
}
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof Assign || $this->isStaticVariable($parentNode)) {
return null;
}
/** @var Scope|null $nodeScope */
$nodeScope = $node->getAttribute(AttributeKey::SCOPE);
if ($nodeScope === null) {
// possible in foreach variable
if ($this->shouldSkipVariable($node)) {
return null;
}
@ -111,14 +103,12 @@ CODE_SAMPLE
}
// defined 100 %
/** @var Scope $nodeScope */
$nodeScope = $node->getAttribute(AttributeKey::SCOPE);
if ($nodeScope->hasVariableType($variableName)->yes()) {
return null;
}
if ($parentNode instanceof Unset_ || $parentNode instanceof Node\Expr\Cast\Unset_) {
return null;
}
// @todo improve
$this->undefinedVariables[] = $variableName;
});
@ -151,4 +141,23 @@ CODE_SAMPLE
return false;
}
private function shouldSkipVariable(Variable $variable): bool
{
$parentNode = $variable->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof Node) {
if ($parentNode instanceof Assign || $this->isStaticVariable($parentNode)) {
return true;
}
}
if ($parentNode instanceof Unset_ || $parentNode instanceof Node\Expr\Cast\Unset_) {
return true;
}
/** @var Scope|null $nodeScope */
$nodeScope = $variable->getAttribute(AttributeKey::SCOPE);
return $nodeScope === null;
}
}

View File

@ -15,6 +15,3 @@ parameters:
# so Rector code is still PHP 7.1 compatible
php_version_features: '7.1'
services:
Rector\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector: ~

View File

@ -15,5 +15,7 @@ final class AutowiredEventDispatcher extends EventDispatcher
foreach ($eventSubscribers as $eventSubscriber) {
$this->addSubscriber($eventSubscriber);
}
parent::__construct();
}
}