mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-25 04:03:55 +01:00
commit
12978b4bdf
@ -18,7 +18,7 @@
|
||||
"jean85/pretty-package-versions": "^1.2",
|
||||
"nette/robot-loader": "^3.1",
|
||||
"nette/utils": "^2.5|^3.0",
|
||||
"nikic/php-parser": "^4.2.4",
|
||||
"nikic/php-parser": "^4.3",
|
||||
"ondram/ci-detector": "^3.1",
|
||||
"phpstan/phpdoc-parser": "^0.3.5",
|
||||
"phpstan/phpstan": "^0.11.13",
|
||||
|
@ -1351,32 +1351,6 @@ Import fully qualified names to use statements
|
||||
}
|
||||
```
|
||||
|
||||
```yaml
|
||||
services:
|
||||
Rector\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector:
|
||||
$shouldImportRootNamespaceClasses: false
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
+use SomeAnother\AnotherClass;
|
||||
+
|
||||
class SomeClass
|
||||
{
|
||||
public function create()
|
||||
{
|
||||
- return SomeAnother\AnotherClass;
|
||||
+ return AnotherClass;
|
||||
}
|
||||
|
||||
public function createDate()
|
||||
{
|
||||
return new \DateTime(); // this remains untouched
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### `MakeInheritedMethodVisibilitySameAsParentRector`
|
||||
|
@ -1112,3 +1112,10 @@ $someVariable
|
||||
```
|
||||
<br>
|
||||
|
||||
#### `PhpParser\Node\UnionType`
|
||||
|
||||
```php
|
||||
string|null
|
||||
```
|
||||
<br>
|
||||
|
||||
|
@ -158,10 +158,6 @@ PHP
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($node->name instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$propertyName = $this->getName($node->name);
|
||||
if ($propertyName === null) {
|
||||
return null;
|
||||
|
@ -107,7 +107,11 @@ PHP
|
||||
|
||||
/** @var Return_ $ifInnerNode */
|
||||
$ifInnerNode = $ifNode->stmts[0];
|
||||
if (! $this->isBool($ifInnerNode->expr)) {
|
||||
|
||||
/** @var Expr $returnedExpr */
|
||||
$returnedExpr = $ifInnerNode->expr;
|
||||
|
||||
if (! $this->isBool($returnedExpr)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -117,7 +121,7 @@ PHP
|
||||
}
|
||||
|
||||
// negate + negate → skip for now
|
||||
if ($this->isFalse($ifInnerNode->expr) && Strings::contains($this->print($ifNode->cond), '!=')) {
|
||||
if ($this->isFalse($returnedExpr) && Strings::contains($this->print($ifNode->cond), '!=')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -97,11 +97,6 @@ PHP
|
||||
return null;
|
||||
}
|
||||
|
||||
// method name is a variable name
|
||||
if ($node->name instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$methodName = $this->getName($node->name);
|
||||
if ($methodName === null) {
|
||||
return null;
|
||||
|
@ -8,12 +8,12 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\NullableType;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Interface_;
|
||||
use PhpParser\Node\UnionType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\StaticType;
|
||||
@ -128,11 +128,16 @@ abstract class AbstractTypeDeclarationRector extends AbstractRector
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Name|NullableType|Identifier $possibleSubtype
|
||||
* @param Name|NullableType|Identifier $type
|
||||
* @param Name|NullableType|UnionType|Identifier $possibleSubtype
|
||||
* @param Name|NullableType|UnionType|Identifier $type
|
||||
*/
|
||||
protected function isSubtypeOf(Node $possibleSubtype, Node $type): bool
|
||||
{
|
||||
// skip until PHP 8 is out
|
||||
if ($possibleSubtype instanceof UnionType || $type instanceof UnionType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$type = $type instanceof NullableType ? $type->type : $type;
|
||||
|
||||
if ($possibleSubtype instanceof NullableType) {
|
||||
|
@ -4,7 +4,7 @@ namespace Rector\Doctrine\Tests\Rector\ClassMethod\AddMethodCallBasedParamTypeRe
|
||||
|
||||
use Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddMethodCallBasedParamTypeRector\Source\Apple;
|
||||
|
||||
class StaticCall
|
||||
class TestingStaticCall
|
||||
{
|
||||
public static function process($name, $id)
|
||||
{
|
||||
@ -17,7 +17,7 @@ class CallerClassForStaticCall
|
||||
{
|
||||
$building = new Apple();
|
||||
|
||||
StaticCall::process('hi', $building->getId());
|
||||
TestingStaticCall::process('hi', $building->getId());
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ namespace Rector\Doctrine\Tests\Rector\ClassMethod\AddMethodCallBasedParamTypeRe
|
||||
|
||||
use Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddMethodCallBasedParamTypeRector\Source\Apple;
|
||||
|
||||
class StaticCall
|
||||
class TestingStaticCall
|
||||
{
|
||||
public static function process(string $name, \Ramsey\Uuid\UuidInterface $id)
|
||||
{
|
||||
@ -42,7 +42,7 @@ class CallerClassForStaticCall
|
||||
{
|
||||
$building = new Apple();
|
||||
|
||||
StaticCall::process('hi', $building->getId());
|
||||
TestingStaticCall::process('hi', $building->getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,3 +215,5 @@ parameters:
|
||||
- '#Method Rector\\DeadCode\\Rector\\Stmt\\RemoveDeadStmtRector\:\:keepLivingCodeFromExpr\(\) should return array<PhpParser\\Node\\Expr\> but returns array<int, PhpParser\\Node\>#'
|
||||
- '#Parameter \#1 \$unversionedSets of method Rector\\Bootstrap\\SetOptionResolver\:\:createSetListInString\(\) expects array<string\>, array<array<string\>\|string\> given#'
|
||||
- '#Parameter \#2 \$versionedSets of method Rector\\Bootstrap\\SetOptionResolver\:\:createSetListInString\(\) expects array<array<string\>\>, array<array<string\>\|string\> given#'
|
||||
- '#Parameter \#1 \$node of method Rector\\Rector\\AbstractRector\:\:removeNode\(\) expects PhpParser\\Node, PhpParser\\Node\|null given#'
|
||||
- '#Cannot access property \$props on PhpParser\\Node\|null#'
|
||||
|
@ -10,6 +10,7 @@ use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Expr\Empty_;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name;
|
||||
@ -170,6 +171,20 @@ final class NameResolver
|
||||
if ($parentNode instanceof StaticCall) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// skip $some->$dynamicMethodName()
|
||||
if ($parentNode instanceof MethodCall) {
|
||||
if ($node === $parentNode->name) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// skip $some->$dynamicPropertyName
|
||||
if ($parentNode instanceof PropertyFetch) {
|
||||
if ($node === $parentNode->name) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (string) $node->name;
|
||||
|
@ -27,6 +27,7 @@ use PhpParser\Node\Expr\Instanceof_;
|
||||
use PhpParser\Node\Expr\Isset_;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\StaticPropertyFetch;
|
||||
use PhpParser\Node\Expr\UnaryMinus;
|
||||
use PhpParser\Node\Expr\UnaryPlus;
|
||||
@ -62,17 +63,12 @@ trait ComplexRemovalTrait
|
||||
/**
|
||||
* @required
|
||||
*/
|
||||
public function setPropertyManipulator(PropertyManipulator $propertyManipulator): void
|
||||
{
|
||||
$this->propertyManipulator = $propertyManipulator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @required
|
||||
*/
|
||||
public function setParsedNodesByType(ParsedNodesByType $parsedNodesByType): void
|
||||
{
|
||||
public function autowireComplextRemovalTrait(
|
||||
PropertyManipulator $propertyManipulator,
|
||||
ParsedNodesByType $parsedNodesByType
|
||||
): void {
|
||||
$this->parsedNodesByType = $parsedNodesByType;
|
||||
$this->propertyManipulator = $propertyManipulator;
|
||||
}
|
||||
|
||||
abstract protected function removeNode(Node $node): void;
|
||||
@ -86,6 +82,10 @@ trait ComplexRemovalTrait
|
||||
|
||||
$classMethodCalls = $this->parsedNodesByType->findClassMethodCalls($classMethod);
|
||||
foreach ($classMethodCalls as $classMethodCall) {
|
||||
if ($classMethodCall instanceof Array_) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->removeMethodCall($classMethodCall);
|
||||
}
|
||||
}
|
||||
@ -216,7 +216,7 @@ trait ComplexRemovalTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MethodCall|Expr\StaticCall|Array_ $node
|
||||
* @param MethodCall|StaticCall $node
|
||||
*/
|
||||
private function removeMethodCall(Node $node): void
|
||||
{
|
||||
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace Rector\Utils\DocumentationGenerator\Command;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Const_;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
@ -94,6 +93,7 @@ use PhpParser\Node\Stmt\Unset_;
|
||||
use PhpParser\Node\Stmt\Use_;
|
||||
use PhpParser\Node\Stmt\UseUse;
|
||||
use PhpParser\Node\Stmt\While_;
|
||||
use PhpParser\Node\UnionType;
|
||||
use PhpParser\Node\VarLikeIdentifier;
|
||||
use Rector\Console\Command\AbstractCommand;
|
||||
use Rector\Console\Shell;
|
||||
@ -393,6 +393,8 @@ final class DumpNodesCommand extends AbstractCommand
|
||||
$node = new Param($someVariableNode);
|
||||
} elseif ($nodeClass === Arg::class) {
|
||||
$node = new Arg($someVariableNode);
|
||||
} elseif ($nodeClass === UnionType::class) {
|
||||
$node = new UnionType([new Identifier('string'), new Identifier('null')]);
|
||||
} else {
|
||||
throw new ShouldNotHappenException(sprintf(
|
||||
'Implement a new printer for "%s" node in "%s"',
|
||||
|
Loading…
x
Reference in New Issue
Block a user