mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
phpstan lvl 6 wip
This commit is contained in:
parent
df701033ad
commit
fa1b58a559
@ -57,7 +57,7 @@
|
|||||||
"all": ["@check-cs", "phpunit"],
|
"all": ["@check-cs", "phpunit"],
|
||||||
"check-cs": "ecs check bin packages src tests",
|
"check-cs": "ecs check bin packages src tests",
|
||||||
"fix-cs": "ecs check bin packages src tests --fix",
|
"fix-cs": "ecs check bin packages src tests --fix",
|
||||||
"phpstan": "vendor/bin/phpstan.phar analyse packages src tests --level 5 --configuration phpstan.neon"
|
"phpstan": "vendor/bin/phpstan.phar analyse packages src tests --level 6 --configuration phpstan.neon"
|
||||||
},
|
},
|
||||||
"bin": [
|
"bin": [
|
||||||
"bin/rector",
|
"bin/rector",
|
||||||
|
@ -23,6 +23,10 @@ parameters:
|
|||||||
- '#Array \(PhpParser\\Node\\Stmt\[\]\) does not accept PhpParser\\Node#'
|
- '#Array \(PhpParser\\Node\\Stmt\[\]\) does not accept PhpParser\\Node#'
|
||||||
- '#Property Rector\\NodeTypeResolver\\NodeVisitor\\NamespaceResolver::\$useNodes \(PhpParser\\Node\\Stmt\\Use_\[\]\) does not accept PhpParser\\Node\[\]#'
|
- '#Property Rector\\NodeTypeResolver\\NodeVisitor\\NamespaceResolver::\$useNodes \(PhpParser\\Node\\Stmt\\Use_\[\]\) does not accept PhpParser\\Node\[\]#'
|
||||||
|
|
||||||
|
# buggy
|
||||||
|
- '#Property Rector\\Rector\\Contrib\\PHPUnit\\SpecificMethodRector::\$oldToNewMethods \(false\[\]\[\]|string\[\]\[\]\) does not accept default value of type \(false|string\)\[\]\[\]#'
|
||||||
|
- '#Parameter \#1 \$classLikeNode of method Rector\\NodeAnalyzer\\ClassLikeAnalyzer::resolveExtendsTypes\(\) expects PhpParser\\Node\\Stmt\\Class_\|PhpParser\\Node\\Stmt\\Interface_, PhpParser\\Node\\Stmt\\ClassLike given#'
|
||||||
|
|
||||||
excludes_analyse:
|
excludes_analyse:
|
||||||
# test files
|
# test files
|
||||||
- '*tests/Rector/Contrib/Nette/Routing/BootstrapToRouterFactoryRector/Wrong/bootstrap.php'
|
- '*tests/Rector/Contrib/Nette/Routing/BootstrapToRouterFactoryRector/Wrong/bootstrap.php'
|
||||||
|
@ -4,7 +4,7 @@ namespace Rector\Builder;
|
|||||||
|
|
||||||
use Nette\Utils\Strings;
|
use Nette\Utils\Strings;
|
||||||
use PhpParser\BuilderFactory;
|
use PhpParser\BuilderFactory;
|
||||||
use PhpParser\Node\Identifier;
|
use PhpParser\Node\Name;
|
||||||
use PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
use PhpParser\Node\Stmt\Class_;
|
use PhpParser\Node\Stmt\Class_;
|
||||||
use PhpParser\Node\Stmt\ClassMethod;
|
use PhpParser\Node\Stmt\ClassMethod;
|
||||||
@ -77,7 +77,7 @@ final class MethodBuilder
|
|||||||
|
|
||||||
if ($propertyType && $operation === 'get') {
|
if ($propertyType && $operation === 'get') {
|
||||||
$typeHint = Strings::endsWith($propertyType, '[]') ? 'array' : $propertyType;
|
$typeHint = Strings::endsWith($propertyType, '[]') ? 'array' : $propertyType;
|
||||||
$methodBuild->setReturnType(new Identifier($typeHint));
|
$methodBuild->setReturnType(new Name($typeHint));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($operation === 'add' || $operation === 'set') {
|
if ($operation === 'add' || $operation === 'set') {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Rector\NodeAnalyzer;
|
namespace Rector\NodeAnalyzer;
|
||||||
|
|
||||||
|
use PhpParser\Builder\Trait_;
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Name;
|
use PhpParser\Node\Name;
|
||||||
use PhpParser\Node\Name\FullyQualified;
|
use PhpParser\Node\Name\FullyQualified;
|
||||||
@ -34,7 +35,7 @@ final class ClassLikeAnalyzer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Class_|Interface_ $classLikeNode
|
* @param Class_|Interface_|Trait_ $classLikeNode
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public function resolveTypeAndParentTypes(ClassLike $classLikeNode): array
|
public function resolveTypeAndParentTypes(ClassLike $classLikeNode): array
|
||||||
|
@ -5,6 +5,7 @@ namespace Rector\Rector\Contrib\Nette\Application;
|
|||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Arg;
|
use PhpParser\Node\Arg;
|
||||||
use PhpParser\Node\Expr\MethodCall;
|
use PhpParser\Node\Expr\MethodCall;
|
||||||
|
use PhpParser\Node\Identifier;
|
||||||
use Rector\Node\NodeFactory;
|
use Rector\Node\NodeFactory;
|
||||||
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
||||||
use Rector\Rector\AbstractRector;
|
use Rector\Rector\AbstractRector;
|
||||||
@ -48,9 +49,9 @@ final class ValidateControlRector extends AbstractRector
|
|||||||
*/
|
*/
|
||||||
public function refactor(Node $methodCallNode): Node
|
public function refactor(Node $methodCallNode): Node
|
||||||
{
|
{
|
||||||
$methodCallNode->name = 'redrawControl';
|
$methodCallNode->name = new Identifier('redrawControl');
|
||||||
|
|
||||||
$methodCallNode->args[0] = $methodCallNode->args[0] ?? $this->nodeFactory->createNullConstant();
|
$methodCallNode->args[0] = $methodCallNode->args[0] ?? new Arg($this->nodeFactory->createNullConstant());
|
||||||
$methodCallNode->args[1] = new Arg($this->nodeFactory->createFalseConstant());
|
$methodCallNode->args[1] = new Arg($this->nodeFactory->createFalseConstant());
|
||||||
|
|
||||||
return $methodCallNode;
|
return $methodCallNode;
|
||||||
|
@ -5,6 +5,7 @@ namespace Rector\Rector\Contrib\Nette\DI;
|
|||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Arg;
|
use PhpParser\Node\Arg;
|
||||||
use PhpParser\Node\Expr\MethodCall;
|
use PhpParser\Node\Expr\MethodCall;
|
||||||
|
use PhpParser\Node\Identifier;
|
||||||
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
||||||
use Rector\Rector\AbstractRector;
|
use Rector\Rector\AbstractRector;
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ final class CompilerCompileArgumentsRector extends AbstractRector
|
|||||||
Arg $argNode
|
Arg $argNode
|
||||||
): MethodCall {
|
): MethodCall {
|
||||||
$addConfigMethodCallNode = clone $methodCallNode;
|
$addConfigMethodCallNode = clone $methodCallNode;
|
||||||
$addConfigMethodCallNode->name = $method;
|
$addConfigMethodCallNode->name = new Identifier($method);
|
||||||
$addConfigMethodCallNode->args = [$argNode];
|
$addConfigMethodCallNode->args = [$argNode];
|
||||||
|
|
||||||
return $addConfigMethodCallNode;
|
return $addConfigMethodCallNode;
|
||||||
|
@ -5,6 +5,7 @@ namespace Rector\Rector\Contrib\Nette\DI;
|
|||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Arg;
|
use PhpParser\Node\Arg;
|
||||||
use PhpParser\Node\Expr\MethodCall;
|
use PhpParser\Node\Expr\MethodCall;
|
||||||
|
use PhpParser\Node\Identifier;
|
||||||
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
||||||
use Rector\Rector\AbstractRector;
|
use Rector\Rector\AbstractRector;
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ final class CompilerGenerateCodeArgumentsRector extends AbstractRector
|
|||||||
Arg $argNode
|
Arg $argNode
|
||||||
): MethodCall {
|
): MethodCall {
|
||||||
$addConfigMethodCallNode = clone $methodCallNode;
|
$addConfigMethodCallNode = clone $methodCallNode;
|
||||||
$addConfigMethodCallNode->name = $method;
|
$addConfigMethodCallNode->name = new Identifier($method);
|
||||||
$addConfigMethodCallNode->args = [$argNode];
|
$addConfigMethodCallNode->args = [$argNode];
|
||||||
|
|
||||||
return $addConfigMethodCallNode;
|
return $addConfigMethodCallNode;
|
||||||
|
@ -3,11 +3,12 @@
|
|||||||
namespace Rector\Rector\Contrib\Nette\DI;
|
namespace Rector\Rector\Contrib\Nette\DI;
|
||||||
|
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
|
use PhpParser\Node\Arg;
|
||||||
use PhpParser\Node\Expr\Assign;
|
use PhpParser\Node\Expr\Assign;
|
||||||
use PhpParser\Node\Expr\MethodCall;
|
use PhpParser\Node\Expr\MethodCall;
|
||||||
use PhpParser\Node\Expr\New_;
|
use PhpParser\Node\Expr\New_;
|
||||||
use PhpParser\Node\Expr\PropertyFetch;
|
use PhpParser\Node\Expr\PropertyFetch;
|
||||||
use PhpParser\Node\Identifier;
|
use PhpParser\Node\Name;
|
||||||
use Rector\Node\Attribute;
|
use Rector\Node\Attribute;
|
||||||
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
||||||
use Rector\Rector\AbstractRector;
|
use Rector\Rector\AbstractRector;
|
||||||
@ -57,10 +58,10 @@ final class SetEntityToStatementRector extends AbstractRector
|
|||||||
return new Assign(
|
return new Assign(
|
||||||
$methodCallNode->var,
|
$methodCallNode->var,
|
||||||
new New_(
|
new New_(
|
||||||
new Identifier('Nette\DI\Statement'),
|
new Name('Nette\DI\Statement'),
|
||||||
[
|
[
|
||||||
$methodCallNode->args[0],
|
$methodCallNode->args[0],
|
||||||
new PropertyFetch($methodCallNode->var, 'arguments'),
|
new Arg(new PropertyFetch($methodCallNode->var, 'arguments')),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -18,7 +18,7 @@ use Rector\Rector\AbstractRector;
|
|||||||
final class SpecificMethodRector extends AbstractRector
|
final class SpecificMethodRector extends AbstractRector
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string[][]|bool[][]
|
* @var string[][]|false[][]
|
||||||
*/
|
*/
|
||||||
private $oldToNewMethods = [
|
private $oldToNewMethods = [
|
||||||
'is_readable' => ['assertIsReadable', 'assertNotIsReadable'],
|
'is_readable' => ['assertIsReadable', 'assertNotIsReadable'],
|
||||||
|
@ -5,6 +5,7 @@ namespace Rector\Rector\Contrib\PhpParser;
|
|||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Expr\PropertyFetch;
|
use PhpParser\Node\Expr\PropertyFetch;
|
||||||
use PhpParser\Node\Expr\Variable;
|
use PhpParser\Node\Expr\Variable;
|
||||||
|
use PhpParser\Node\Identifier;
|
||||||
use Rector\Node\Attribute;
|
use Rector\Node\Attribute;
|
||||||
use Rector\Node\PropertyFetchNodeFactory;
|
use Rector\Node\PropertyFetchNodeFactory;
|
||||||
use Rector\NodeAnalyzer\PropertyFetchAnalyzer;
|
use Rector\NodeAnalyzer\PropertyFetchAnalyzer;
|
||||||
@ -63,10 +64,10 @@ final class CatchAndClosureUseNameRector extends AbstractRector
|
|||||||
$variableNode = $propertyFetchNode->var;
|
$variableNode = $propertyFetchNode->var;
|
||||||
|
|
||||||
$propertyFetchNode->var = $this->propertyFetchNodeFactory->createWithVariableNameAndPropertyName(
|
$propertyFetchNode->var = $this->propertyFetchNodeFactory->createWithVariableNameAndPropertyName(
|
||||||
$variableNode->name,
|
(string) $variableNode->name,
|
||||||
'var'
|
'var'
|
||||||
);
|
);
|
||||||
$propertyFetchNode->name = 'name';
|
$propertyFetchNode->name = new Identifier('name');
|
||||||
|
|
||||||
return $propertyFetchNode;
|
return $propertyFetchNode;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ namespace Rector\Rector\Contrib\PhpParser;
|
|||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Arg;
|
use PhpParser\Node\Arg;
|
||||||
use PhpParser\Node\Expr\MethodCall;
|
use PhpParser\Node\Expr\MethodCall;
|
||||||
|
use PhpParser\Node\Identifier;
|
||||||
use PhpParser\Node\Scalar\String_;
|
use PhpParser\Node\Scalar\String_;
|
||||||
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
||||||
use Rector\Rector\AbstractRector;
|
use Rector\Rector\AbstractRector;
|
||||||
@ -38,7 +39,7 @@ final class SetLineRector extends AbstractRector
|
|||||||
*/
|
*/
|
||||||
public function refactor(Node $methodCallNode): ?Node
|
public function refactor(Node $methodCallNode): ?Node
|
||||||
{
|
{
|
||||||
$methodCallNode->name = 'setAttribute';
|
$methodCallNode->name = new Identifier('setAttribute');
|
||||||
|
|
||||||
$methodCallNode->args[1] = $methodCallNode->args[0];
|
$methodCallNode->args[1] = $methodCallNode->args[0];
|
||||||
$methodCallNode->args[0] = new Arg(new String_('line'));
|
$methodCallNode->args[0] = new Arg(new String_('line'));
|
||||||
|
@ -60,7 +60,7 @@ final class FormIsValidRector extends AbstractRector
|
|||||||
{
|
{
|
||||||
/** @var Variable $variableNode */
|
/** @var Variable $variableNode */
|
||||||
$variableNode = $node->var;
|
$variableNode = $node->var;
|
||||||
$variableName = $variableNode->name;
|
$variableName = (string) $variableNode->name;
|
||||||
|
|
||||||
return new BooleanAnd(
|
return new BooleanAnd(
|
||||||
$this->methodCallNodeFactory->createWithVariableNameAndMethodName($variableName, 'isSubmitted'),
|
$this->methodCallNodeFactory->createWithVariableNameAndMethodName($variableName, 'isSubmitted'),
|
||||||
|
@ -129,7 +129,7 @@ final class ParentTypehintedArgumentRector extends AbstractRector
|
|||||||
): ClassMethod {
|
): ClassMethod {
|
||||||
/** @var Param $param */
|
/** @var Param $param */
|
||||||
foreach ($classMethodNode->params as $param) {
|
foreach ($classMethodNode->params as $param) {
|
||||||
$parameterName = $param->var->name;
|
$parameterName = (string) $param->var->name;
|
||||||
|
|
||||||
if (! isset($parametersToTypehints[$parameterName])) {
|
if (! isset($parametersToTypehints[$parameterName])) {
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user