mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit f6f7431ce7
f6f7431ce7
[DX] Merge getObjectType() and getStaticType() methods to single getType() (#973)
This commit is contained in:
parent
4fa8da0c31
commit
61389a9b2c
|
@ -10,7 +10,7 @@
|
|||
|
||||
- [Carbon](#carbon) (2)
|
||||
|
||||
- [CodeQuality](#codequality) (68)
|
||||
- [CodeQuality](#codequality) (69)
|
||||
|
||||
- [CodingStyle](#codingstyle) (39)
|
||||
|
||||
|
@ -90,7 +90,7 @@
|
|||
|
||||
- [Renaming](#renaming) (11)
|
||||
|
||||
- [Restoration](#restoration) (6)
|
||||
- [Restoration](#restoration) (5)
|
||||
|
||||
- [Strict](#strict) (5)
|
||||
|
||||
|
@ -845,6 +845,38 @@ Make if conditions more explicit
|
|||
|
||||
<br>
|
||||
|
||||
### ExplicitMethodCallOverMagicGetSetRector
|
||||
|
||||
Replace magic property fetch using `__get()` and `__set()` with existing method get*()/set*() calls
|
||||
|
||||
- class: [`Rector\CodeQuality\Rector\PropertyFetch\ExplicitMethodCallOverMagicGetSetRector`](../rules/CodeQuality/Rector/PropertyFetch/ExplicitMethodCallOverMagicGetSetRector.php)
|
||||
|
||||
```diff
|
||||
class MagicCallsObject
|
||||
{
|
||||
// adds magic __get() and __set() methods
|
||||
use \Nette\SmartObject;
|
||||
|
||||
private $name;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
|
||||
class SomeClass
|
||||
{
|
||||
public function run(MagicObject $magicObject)
|
||||
{
|
||||
- return $magicObject->name;
|
||||
+ return $magicObject->getName();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### FixClassCaseSensitivityNameRector
|
||||
|
||||
Change miss-typed case sensitivity name to correct one
|
||||
|
@ -9651,53 +9683,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
|
||||
<br>
|
||||
|
||||
### InferParamFromClassMethodReturnRector
|
||||
|
||||
Change `@param` doc based on another method return type
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\Restoration\Rector\ClassMethod\InferParamFromClassMethodReturnRector`](../rules/Restoration/Rector/ClassMethod/InferParamFromClassMethodReturnRector.php)
|
||||
|
||||
```php
|
||||
use Rector\Restoration\Rector\ClassMethod\InferParamFromClassMethodReturnRector;
|
||||
use Rector\Restoration\ValueObject\InferParamFromClassMethodReturn;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(InferParamFromClassMethodReturnRector::class)
|
||||
->call('configure', [[
|
||||
InferParamFromClassMethodReturnRector::INFER_PARAMS_FROM_CLASS_METHOD_RETURNS => ValueObjectInliner::inline([
|
||||
new InferParamFromClassMethodReturn('SomeClass', 'process', 'getNodeTypes'),
|
||||
]),
|
||||
]]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [String_::class];
|
||||
}
|
||||
|
||||
+ /**
|
||||
+ * @param String_ $node
|
||||
+ */
|
||||
public function process(Node $node)
|
||||
{
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### MakeTypedPropertyNullableIfCheckedRector
|
||||
|
||||
Make typed property nullable if checked
|
||||
|
|
|
@ -19,7 +19,6 @@ use PhpParser\Node\Scalar;
|
|||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\Accessory\NonEmptyArrayType;
|
||||
use PHPStan\Type\ArrayType;
|
||||
|
@ -38,7 +37,6 @@ use PHPStan\Type\TypeCombinator;
|
|||
use PHPStan\Type\TypeWithClassName;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\Core\Configuration\RenamedClassesDataCollector;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\NodeAnalyzer\ClassAnalyzer;
|
||||
use Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
|
@ -134,7 +132,7 @@ final class NodeTypeResolver
|
|||
if ($node instanceof \PhpParser\Node\Expr\ClassConstFetch) {
|
||||
return \false;
|
||||
}
|
||||
$resolvedType = $this->resolve($node);
|
||||
$resolvedType = $this->getType($node);
|
||||
if ($resolvedType instanceof \PHPStan\Type\MixedType) {
|
||||
return \false;
|
||||
}
|
||||
|
@ -146,28 +144,25 @@ final class NodeTypeResolver
|
|||
}
|
||||
return $this->isMatchingUnionType($resolvedType, $requiredObjectType);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see use NodeTypeResolver::getType() instead
|
||||
*/
|
||||
public function resolve(\PhpParser\Node $node) : \PHPStan\Type\Type
|
||||
{
|
||||
return $this->getType($node);
|
||||
}
|
||||
public function getType(\PhpParser\Node $node) : \PHPStan\Type\Type
|
||||
{
|
||||
if ($node instanceof \PhpParser\Node\Expr\Ternary) {
|
||||
if ($node->if !== null) {
|
||||
$first = $this->resolve($node->if);
|
||||
$second = $this->resolve($node->else);
|
||||
if ($this->isUnionTypeable($first, $second)) {
|
||||
return new \PHPStan\Type\UnionType([$first, $second]);
|
||||
}
|
||||
}
|
||||
$condType = $this->resolve($node->cond);
|
||||
if ($this->isNullableType($node->cond) && $condType instanceof \PHPStan\Type\UnionType) {
|
||||
$first = $condType->getTypes()[0];
|
||||
$second = $this->resolve($node->else);
|
||||
if ($this->isUnionTypeable($first, $second)) {
|
||||
return new \PHPStan\Type\UnionType([$first, $second]);
|
||||
}
|
||||
$ternaryType = $this->resolveTernaryType($node);
|
||||
if (!$ternaryType instanceof \PHPStan\Type\MixedType) {
|
||||
return $ternaryType;
|
||||
}
|
||||
}
|
||||
if ($node instanceof \PhpParser\Node\Expr\BinaryOp\Coalesce) {
|
||||
$first = $this->resolve($node->left);
|
||||
$second = $this->resolve($node->right);
|
||||
$first = $this->getType($node->left);
|
||||
$second = $this->getType($node->right);
|
||||
if ($this->isUnionTypeable($first, $second)) {
|
||||
return new \PHPStan\Type\UnionType([$first, $second]);
|
||||
}
|
||||
|
@ -175,6 +170,7 @@ final class NodeTypeResolver
|
|||
$type = $this->resolveByNodeTypeResolvers($node);
|
||||
if ($type !== null) {
|
||||
$type = $this->accessoryNonEmptyStringTypeCorrector->correct($type);
|
||||
$type = $this->genericClassStringTypeCorrector->correct($type);
|
||||
return $this->hasOffsetTypeCorrector->correct($type);
|
||||
}
|
||||
$scope = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
|
||||
|
@ -200,6 +196,7 @@ final class NodeTypeResolver
|
|||
}
|
||||
$type = $scope->getType($node);
|
||||
$type = $this->accessoryNonEmptyStringTypeCorrector->correct($type);
|
||||
$type = $this->genericClassStringTypeCorrector->correct($type);
|
||||
// hot fix for phpstan not resolving chain method calls
|
||||
if (!$node instanceof \PhpParser\Node\Expr\MethodCall) {
|
||||
return $type;
|
||||
|
@ -207,14 +204,14 @@ final class NodeTypeResolver
|
|||
if (!$type instanceof \PHPStan\Type\MixedType) {
|
||||
return $type;
|
||||
}
|
||||
return $this->resolve($node->var);
|
||||
return $this->getType($node->var);
|
||||
}
|
||||
/**
|
||||
* e.g. string|null, ObjectNull|null
|
||||
*/
|
||||
public function isNullableType(\PhpParser\Node $node) : bool
|
||||
{
|
||||
$nodeType = $this->resolve($node);
|
||||
$nodeType = $this->getType($node);
|
||||
return \PHPStan\Type\TypeCombinator::containsNull($nodeType);
|
||||
}
|
||||
public function getNativeType(\PhpParser\Node\Expr $expr) : \PHPStan\Type\Type
|
||||
|
@ -227,14 +224,8 @@ final class NodeTypeResolver
|
|||
}
|
||||
public function getStaticType(\PhpParser\Node $node) : \PHPStan\Type\Type
|
||||
{
|
||||
if ($node instanceof \PhpParser\Node\Param) {
|
||||
return $this->resolve($node);
|
||||
}
|
||||
if ($node instanceof \PhpParser\Node\Expr\New_) {
|
||||
return $this->resolve($node);
|
||||
}
|
||||
if ($node instanceof \PhpParser\Node\Stmt\Return_) {
|
||||
return $this->resolve($node);
|
||||
if ($node instanceof \PhpParser\Node\Param || $node instanceof \PhpParser\Node\Expr\New_ || $node instanceof \PhpParser\Node\Stmt\Return_) {
|
||||
return $this->getType($node);
|
||||
}
|
||||
if (!$node instanceof \PhpParser\Node\Expr) {
|
||||
return new \PHPStan\Type\MixedType();
|
||||
|
@ -243,7 +234,7 @@ final class NodeTypeResolver
|
|||
return $this->resolveArrayType($node);
|
||||
}
|
||||
if ($node instanceof \PhpParser\Node\Scalar) {
|
||||
return $this->resolve($node);
|
||||
return $this->getType($node);
|
||||
}
|
||||
$scope = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
|
||||
if (!$scope instanceof \PHPStan\Analyser\Scope) {
|
||||
|
@ -260,42 +251,26 @@ final class NodeTypeResolver
|
|||
}
|
||||
public function isNumberType(\PhpParser\Node $node) : bool
|
||||
{
|
||||
if ($this->isStaticType($node, \PHPStan\Type\IntegerType::class)) {
|
||||
$nodeType = $this->getType($node);
|
||||
if ($nodeType instanceof \PHPStan\Type\IntegerType) {
|
||||
return \true;
|
||||
}
|
||||
return $this->isStaticType($node, \PHPStan\Type\FloatType::class);
|
||||
}
|
||||
/**
|
||||
* @param class-string<Type> $staticTypeClass
|
||||
*/
|
||||
public function isStaticType(\PhpParser\Node $node, string $staticTypeClass) : bool
|
||||
{
|
||||
if (!\is_a($staticTypeClass, \PHPStan\Type\Type::class, \true)) {
|
||||
throw new \Rector\Core\Exception\ShouldNotHappenException(\sprintf('"%s" in "%s()" must be type of "%s"', $staticTypeClass, __METHOD__, \PHPStan\Type\Type::class));
|
||||
}
|
||||
return \is_a($this->resolve($node), $staticTypeClass);
|
||||
return $nodeType instanceof \PHPStan\Type\FloatType;
|
||||
}
|
||||
/**
|
||||
* @param class-string<Type> $desiredType
|
||||
*/
|
||||
public function isNullableTypeOfSpecificType(\PhpParser\Node $node, string $desiredType) : bool
|
||||
{
|
||||
$nodeType = $this->resolve($node);
|
||||
$nodeType = $this->getType($node);
|
||||
if (!$nodeType instanceof \PHPStan\Type\UnionType) {
|
||||
return \false;
|
||||
}
|
||||
if (!\PHPStan\Type\TypeCombinator::containsNull($nodeType)) {
|
||||
return \false;
|
||||
}
|
||||
if (\count($nodeType->getTypes()) !== 2) {
|
||||
return \false;
|
||||
}
|
||||
foreach ($nodeType->getTypes() as $type) {
|
||||
if (\is_a($type, $desiredType, \true)) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
$bareType = \PHPStan\Type\TypeCombinator::removeNull($nodeType);
|
||||
return \is_a($bareType, $desiredType, \true);
|
||||
}
|
||||
/**
|
||||
* @return class-string
|
||||
|
@ -307,19 +282,6 @@ final class NodeTypeResolver
|
|||
}
|
||||
return $typeWithClassName->getClassName();
|
||||
}
|
||||
/**
|
||||
* @param Type[] $desiredTypes
|
||||
*/
|
||||
public function isSameObjectTypes(\PHPStan\Type\ObjectType $objectType, array $desiredTypes) : bool
|
||||
{
|
||||
foreach ($desiredTypes as $desiredType) {
|
||||
$desiredTypeEquals = $desiredType->equals($objectType);
|
||||
if ($desiredTypeEquals) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
public function isMethodStaticCallOrClassMethodObjectType(\PhpParser\Node $node, \PHPStan\Type\ObjectType $objectType) : bool
|
||||
{
|
||||
if ($node instanceof \PhpParser\Node\Expr\MethodCall) {
|
||||
|
@ -335,18 +297,6 @@ final class NodeTypeResolver
|
|||
}
|
||||
return $this->isObjectType($classLike, $objectType);
|
||||
}
|
||||
public function resolveObjectTypeFromScope(\PHPStan\Analyser\Scope $scope) : ?\PHPStan\Type\ObjectType
|
||||
{
|
||||
$classReflection = $scope->getClassReflection();
|
||||
if (!$classReflection instanceof \PHPStan\Reflection\ClassReflection) {
|
||||
return null;
|
||||
}
|
||||
$className = $classReflection->getName();
|
||||
if (!$this->reflectionProvider->hasClass($className)) {
|
||||
return null;
|
||||
}
|
||||
return new \PHPStan\Type\ObjectType($className, null, $classReflection);
|
||||
}
|
||||
private function isUnionTypeable(\PHPStan\Type\Type $first, \PHPStan\Type\Type $second) : bool
|
||||
{
|
||||
return !$first instanceof \PHPStan\Type\UnionType && !$second instanceof \PHPStan\Type\UnionType && !$second instanceof \PHPStan\Type\NullType;
|
||||
|
@ -442,4 +392,26 @@ final class NodeTypeResolver
|
|||
}
|
||||
return \true;
|
||||
}
|
||||
/**
|
||||
* @return \PHPStan\Type\MixedType|\PHPStan\Type\UnionType
|
||||
*/
|
||||
private function resolveTernaryType(\PhpParser\Node\Expr\Ternary $ternary)
|
||||
{
|
||||
if ($ternary->if !== null) {
|
||||
$first = $this->getType($ternary->if);
|
||||
$second = $this->getType($ternary->else);
|
||||
if ($this->isUnionTypeable($first, $second)) {
|
||||
return new \PHPStan\Type\UnionType([$first, $second]);
|
||||
}
|
||||
}
|
||||
$condType = $this->getType($ternary->cond);
|
||||
if ($this->isNullableType($ternary->cond) && $condType instanceof \PHPStan\Type\UnionType) {
|
||||
$first = $condType->getTypes()[0];
|
||||
$second = $this->getType($ternary->else);
|
||||
if ($this->isUnionTypeable($first, $second)) {
|
||||
return new \PHPStan\Type\UnionType([$first, $second]);
|
||||
}
|
||||
}
|
||||
return new \PHPStan\Type\MixedType();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,8 @@ final class ExprBoolCaster
|
|||
if ($expr instanceof \PhpParser\Node\Expr\BooleanNot) {
|
||||
return \false;
|
||||
}
|
||||
if ($this->nodeTypeResolver->isStaticType($expr, \PHPStan\Type\BooleanType::class)) {
|
||||
$exprType = $this->nodeTypeResolver->getType($expr);
|
||||
if ($exprType instanceof \PHPStan\Type\BooleanType) {
|
||||
return \false;
|
||||
}
|
||||
return !$expr instanceof \PhpParser\Node\Expr\BinaryOp;
|
||||
|
|
|
@ -54,8 +54,8 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
$leftStaticType = $this->getStaticType($node->left);
|
||||
$rightStaticType = $this->getStaticType($node->right);
|
||||
$leftStaticType = $this->getType($node->left);
|
||||
$rightStaticType = $this->getType($node->right);
|
||||
// objects can be different by content
|
||||
if ($leftStaticType instanceof \PHPStan\Type\ObjectType) {
|
||||
return null;
|
||||
|
|
|
@ -83,7 +83,7 @@ CODE_SAMPLE
|
|||
{
|
||||
/** @var BooleanAnd|BooleanOr $booleanExpr */
|
||||
$booleanExpr = $expression->expr;
|
||||
$leftStaticType = $this->getStaticType($booleanExpr->left);
|
||||
$leftStaticType = $this->getType($booleanExpr->left);
|
||||
if (!$leftStaticType instanceof \PHPStan\Type\BooleanType) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ CODE_SAMPLE
|
|||
if (!$this->valueResolver->isTrueOrFalse($returnExpression)) {
|
||||
return \true;
|
||||
}
|
||||
$foreachValueStaticType = $this->getStaticType($foreach->expr);
|
||||
$foreachValueStaticType = $this->getType($foreach->expr);
|
||||
if ($foreachValueStaticType instanceof \PHPStan\Type\ObjectType) {
|
||||
return \true;
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ CODE_SAMPLE
|
|||
}
|
||||
private function isArrayType(\PhpParser\Node\Expr $expr) : bool
|
||||
{
|
||||
$exprType = $this->getStaticType($expr);
|
||||
$exprType = $this->getType($expr);
|
||||
if ($exprType instanceof \PHPStan\Type\ObjectType) {
|
||||
return \false;
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ CODE_SAMPLE
|
|||
/** @var Arg $firstArg */
|
||||
$firstArg = $node->args[0];
|
||||
$firstValue = $firstArg->value;
|
||||
$firstValueStaticType = $this->getStaticType($firstValue);
|
||||
$firstValueStaticType = $this->getType($firstValue);
|
||||
if (!$firstValueStaticType instanceof \PHPStan\Type\Constant\ConstantArrayType) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ CODE_SAMPLE
|
|||
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
|
||||
return null;
|
||||
}
|
||||
$firstArgumentStaticType = $this->getStaticType($node->args[0]->value);
|
||||
$firstArgumentStaticType = $this->getType($node->args[0]->value);
|
||||
if (!$firstArgumentStaticType instanceof \PHPStan\Type\StringType) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -86,7 +86,8 @@ CODE_SAMPLE
|
|||
/** @var Arg $secondArg */
|
||||
$secondArg = $node->args[1];
|
||||
$valueArgument = $secondArg->value;
|
||||
if (!$this->nodeTypeResolver->isStaticType($valueArgument, \PHPStan\Type\StringType::class)) {
|
||||
$valueType = $this->getType($valueArgument);
|
||||
if (!$valueType instanceof \PHPStan\Type\StringType) {
|
||||
return null;
|
||||
}
|
||||
return $valueArgument;
|
||||
|
|
|
@ -166,7 +166,7 @@ CODE_SAMPLE
|
|||
$resolvedTypes[] = $propertyTypeFromConstructor;
|
||||
$defaultValue = $property->props[0]->default;
|
||||
if ($defaultValue !== null) {
|
||||
$resolvedTypes[] = $this->getStaticType($defaultValue);
|
||||
$resolvedTypes[] = $this->getType($defaultValue);
|
||||
}
|
||||
$resolveAssignedType = $this->resolveAssignedTypeInStmtsByPropertyName($classLike->stmts, $propertyName);
|
||||
if ($resolveAssignedType !== null) {
|
||||
|
@ -203,7 +203,7 @@ CODE_SAMPLE
|
|||
if (!$node instanceof \PhpParser\Node\Expr\Assign) {
|
||||
return null;
|
||||
}
|
||||
$resolvedTypes[] = $this->getStaticType($node->expr);
|
||||
$resolvedTypes[] = $this->getType($node->expr);
|
||||
return null;
|
||||
});
|
||||
if ($resolvedTypes === []) {
|
||||
|
|
|
@ -66,10 +66,12 @@ CODE_SAMPLE
|
|||
}
|
||||
if ($node->expr instanceof \PhpParser\Node\Expr\BinaryOp\Identical) {
|
||||
$identical = $node->expr;
|
||||
if (!$this->nodeTypeResolver->isStaticType($identical->left, \PHPStan\Type\BooleanType::class)) {
|
||||
$leftType = $this->getType($identical->left);
|
||||
if (!$leftType instanceof \PHPStan\Type\BooleanType) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeTypeResolver->isStaticType($identical->right, \PHPStan\Type\BooleanType::class)) {
|
||||
$rightType = $this->getType($identical->right);
|
||||
if (!$rightType instanceof \PHPStan\Type\BooleanType) {
|
||||
return null;
|
||||
}
|
||||
return new \PhpParser\Node\Expr\BinaryOp\NotIdentical($identical->left, $identical->right);
|
||||
|
@ -78,10 +80,12 @@ CODE_SAMPLE
|
|||
}
|
||||
private function processIdentical(\PhpParser\Node\Expr\BinaryOp\Identical $identical) : ?\PhpParser\Node\Expr\BinaryOp\NotIdentical
|
||||
{
|
||||
if (!$this->nodeTypeResolver->isStaticType($identical->left, \PHPStan\Type\BooleanType::class)) {
|
||||
$leftType = $this->getType($identical->left);
|
||||
if (!$leftType instanceof \PHPStan\Type\BooleanType) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeTypeResolver->isStaticType($identical->right, \PHPStan\Type\BooleanType::class)) {
|
||||
$rightType = $this->getType($identical->right);
|
||||
if (!$rightType instanceof \PHPStan\Type\BooleanType) {
|
||||
return null;
|
||||
}
|
||||
if ($identical->left instanceof \PhpParser\Node\Expr\BooleanNot) {
|
||||
|
|
|
@ -92,7 +92,7 @@ CODE_SAMPLE
|
|||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($expression);
|
||||
$type = $phpDocInfo->getVarType();
|
||||
if (!$type instanceof \PHPStan\Type\UnionType) {
|
||||
$type = $this->getObjectType($assign->expr);
|
||||
$type = $this->getType($assign->expr);
|
||||
}
|
||||
if (!$type instanceof \PHPStan\Type\UnionType) {
|
||||
return null;
|
||||
|
|
|
@ -53,10 +53,12 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
if ($this->nodeTypeResolver->isStaticType($node->left, \PHPStan\Type\BooleanType::class) && !$this->valueResolver->isTrueOrFalse($node->left)) {
|
||||
$leftType = $this->getType($node->left);
|
||||
if ($leftType instanceof \PHPStan\Type\BooleanType && !$this->valueResolver->isTrueOrFalse($node->left)) {
|
||||
return $this->processBoolTypeToNotBool($node, $node->left, $node->right);
|
||||
}
|
||||
if (!$this->nodeTypeResolver->isStaticType($node->right, \PHPStan\Type\BooleanType::class)) {
|
||||
$rightType = $this->getType($node->right);
|
||||
if (!$rightType instanceof \PHPStan\Type\BooleanType) {
|
||||
return null;
|
||||
}
|
||||
if ($this->valueResolver->isTrueOrFalse($node->right)) {
|
||||
|
|
|
@ -108,7 +108,7 @@ CODE_SAMPLE
|
|||
if ($conditionNode instanceof \PhpParser\Node\Expr\Cast\Bool_) {
|
||||
return null;
|
||||
}
|
||||
$conditionStaticType = $this->getStaticType($conditionNode);
|
||||
$conditionStaticType = $this->getType($conditionNode);
|
||||
if ($conditionStaticType instanceof \PHPStan\Type\BooleanType || $conditionStaticType instanceof \PHPStan\Type\Constant\ConstantIntegerType) {
|
||||
return null;
|
||||
}
|
||||
|
@ -139,10 +139,11 @@ CODE_SAMPLE
|
|||
if ($this->stringTypeAnalyzer->isStringOrUnionStringOnlyType($expr)) {
|
||||
return $this->resolveString($isNegated, $expr);
|
||||
}
|
||||
if ($this->nodeTypeResolver->isStaticType($expr, \PHPStan\Type\IntegerType::class)) {
|
||||
$exprType = $this->getType($expr);
|
||||
if ($exprType instanceof \PHPStan\Type\IntegerType) {
|
||||
return $this->resolveInteger($isNegated, $expr);
|
||||
}
|
||||
if ($this->nodeTypeResolver->isStaticType($expr, \PHPStan\Type\FloatType::class)) {
|
||||
if ($exprType instanceof \PHPStan\Type\FloatType) {
|
||||
return $this->resolveFloat($isNegated, $expr);
|
||||
}
|
||||
if ($this->nodeTypeResolver->isNullableTypeOfSpecificType($expr, \PHPStan\Type\ObjectType::class)) {
|
||||
|
|
|
@ -90,7 +90,7 @@ CODE_SAMPLE
|
|||
if ($propertyFetchName === null) {
|
||||
continue;
|
||||
}
|
||||
$propertyFetchVarType = $this->getObjectType($issetVar->var);
|
||||
$propertyFetchVarType = $this->getType($issetVar->var);
|
||||
if ($propertyFetchVarType instanceof \PHPStan\Type\TypeWithClassName) {
|
||||
if (!$this->reflectionProvider->hasClass($propertyFetchVarType->getClassName())) {
|
||||
continue;
|
||||
|
|
|
@ -97,7 +97,7 @@ CODE_SAMPLE
|
|||
*/
|
||||
private function refactorPropertyFetch(\PhpParser\Node\Expr\PropertyFetch $propertyFetch)
|
||||
{
|
||||
$callerType = $this->getObjectType($propertyFetch->var);
|
||||
$callerType = $this->getType($propertyFetch->var);
|
||||
if (!$callerType instanceof \PHPStan\Type\TypeWithClassName) {
|
||||
return null;
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ CODE_SAMPLE
|
|||
*/
|
||||
private function refactorMagicSet(\PhpParser\Node\Expr $expr, \PhpParser\Node\Expr\PropertyFetch $propertyFetch)
|
||||
{
|
||||
$propertyCallerType = $this->getObjectType($propertyFetch->var);
|
||||
$propertyCallerType = $this->getType($propertyFetch->var);
|
||||
if (!$propertyCallerType instanceof \PHPStan\Type\ObjectType) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,8 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
if (!$this->nodeTypeResolver->isStaticType($node->cond, \PHPStan\Type\BooleanType::class)) {
|
||||
$condType = $this->getType($node->cond);
|
||||
if (!$condType instanceof \PHPStan\Type\BooleanType) {
|
||||
return null;
|
||||
}
|
||||
if ($node->if === null) {
|
||||
|
|
|
@ -92,7 +92,8 @@ final class UnnecessaryTernaryExpressionRector extends \Rector\Core\Rector\Abstr
|
|||
}
|
||||
private function processTrueIfExpressionWithFalseElseExpression(\PhpParser\Node\Expr $expr) : \PhpParser\Node\Expr
|
||||
{
|
||||
if ($this->nodeTypeResolver->isStaticType($expr, \PHPStan\Type\BooleanType::class)) {
|
||||
$exprType = $this->getType($expr);
|
||||
if ($exprType instanceof \PHPStan\Type\BooleanType) {
|
||||
return $expr;
|
||||
}
|
||||
return new \PhpParser\Node\Expr\Cast\Bool_($expr);
|
||||
|
@ -100,12 +101,14 @@ final class UnnecessaryTernaryExpressionRector extends \Rector\Core\Rector\Abstr
|
|||
private function processFalseIfExpressionWithTrueElseExpression(\PhpParser\Node\Expr $expr) : \PhpParser\Node\Expr
|
||||
{
|
||||
if ($expr instanceof \PhpParser\Node\Expr\BooleanNot) {
|
||||
if ($this->nodeTypeResolver->isStaticType($expr->expr, \PHPStan\Type\BooleanType::class)) {
|
||||
$negatedExprType = $this->getType($expr->expr);
|
||||
if ($negatedExprType instanceof \PHPStan\Type\BooleanType) {
|
||||
return $expr->expr;
|
||||
}
|
||||
return new \PhpParser\Node\Expr\Cast\Bool_($expr->expr);
|
||||
}
|
||||
if ($this->nodeTypeResolver->isStaticType($expr, \PHPStan\Type\BooleanType::class)) {
|
||||
$exprType = $this->getType($expr);
|
||||
if ($exprType instanceof \PHPStan\Type\BooleanType) {
|
||||
return new \PhpParser\Node\Expr\BooleanNot($expr);
|
||||
}
|
||||
return new \PhpParser\Node\Expr\BooleanNot(new \PhpParser\Node\Expr\Cast\Bool_($expr));
|
||||
|
|
|
@ -71,7 +71,7 @@ CODE_SAMPLE
|
|||
if (\count($node->consts) > 1) {
|
||||
return null;
|
||||
}
|
||||
$constType = $this->getStaticType($node->consts[0]->value);
|
||||
$constType = $this->getType($node->consts[0]->value);
|
||||
if ($constType instanceof \PHPStan\Type\MixedType) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ CODE_SAMPLE
|
|||
}
|
||||
private function isNullableNonScalarType(\PhpParser\Node $node) : bool
|
||||
{
|
||||
$staticType = $this->getStaticType($node);
|
||||
$staticType = $this->getType($node);
|
||||
if ($staticType instanceof \PHPStan\Type\MixedType) {
|
||||
return \false;
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ CODE_SAMPLE
|
|||
if (!isset(self::CAST_CLASS_TO_NODE_TYPE[$nodeClass])) {
|
||||
return null;
|
||||
}
|
||||
$nodeType = $this->getStaticType($node->expr);
|
||||
$nodeType = $this->getType($node->expr);
|
||||
if ($nodeType instanceof \PHPStan\Type\MixedType) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ CODE_SAMPLE
|
|||
if ($classMethod->stmts === null) {
|
||||
return null;
|
||||
}
|
||||
if (\count($classMethod->stmts) !== 1) {
|
||||
if (\count((array) $classMethod->stmts) !== 1) {
|
||||
return null;
|
||||
}
|
||||
// recount empty notes
|
||||
|
|
|
@ -61,7 +61,7 @@ CODE_SAMPLE
|
|||
if ($node->elseifs !== []) {
|
||||
return null;
|
||||
}
|
||||
$conditionStaticType = $this->getStaticType($node->cond);
|
||||
$conditionStaticType = $this->getType($node->cond);
|
||||
if (!$conditionStaticType instanceof \PHPStan\Type\Constant\ConstantBooleanType) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ CODE_SAMPLE
|
|||
if ($this->valueResolver->isTrue($node->if)) {
|
||||
return null;
|
||||
}
|
||||
$ifType = $this->getStaticType($node->if);
|
||||
$ifType = $this->getType($node->if);
|
||||
if (!$ifType instanceof \PHPStan\Type\BooleanType) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ CODE_SAMPLE
|
|||
if ($node->stmts === null) {
|
||||
return null;
|
||||
}
|
||||
$classMethodStatementCount = \count($node->stmts);
|
||||
$classMethodStatementCount = \count((array) $node->stmts);
|
||||
// iterate from bottom to up, so we can merge
|
||||
for ($i = $classMethodStatementCount - 1; $i >= 0; --$i) {
|
||||
if (!isset($node->stmts[$i])) {
|
||||
|
|
|
@ -95,7 +95,7 @@ CODE_SAMPLE
|
|||
if (!$this->isActionInjectedParamNode($paramNode)) {
|
||||
continue;
|
||||
}
|
||||
$paramType = $this->getObjectType($paramNode);
|
||||
$paramType = $this->getType($paramNode);
|
||||
/** @var string $paramName */
|
||||
$paramName = $this->getName($paramNode->var);
|
||||
$propertyMetadata = new \Rector\PostRector\ValueObject\PropertyMetadata($paramName, $paramType, \PhpParser\Node\Stmt\Class_::MODIFIER_PRIVATE);
|
||||
|
@ -113,7 +113,7 @@ CODE_SAMPLE
|
|||
if ($typehint === null) {
|
||||
return \false;
|
||||
}
|
||||
$paramStaticType = $this->getObjectType($param);
|
||||
$paramStaticType = $this->getType($param);
|
||||
if (!$paramStaticType instanceof \PHPStan\Type\ObjectType) {
|
||||
return \false;
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ CODE_SAMPLE
|
|||
/** @var string $paramName */
|
||||
$paramName = $this->getName($param->var);
|
||||
$variable = new \PhpParser\Node\Expr\Variable($paramName);
|
||||
$paramType = $this->getStaticType($param);
|
||||
$paramType = $this->getType($param);
|
||||
$recastedVariable = $this->recastVariabletIfScalarType($variable, $paramType);
|
||||
if (!$recastedVariable instanceof \PhpParser\Node\Expr\Cast) {
|
||||
return null;
|
||||
|
|
|
@ -104,7 +104,7 @@ CODE_SAMPLE
|
|||
if (!$methodCall->args[0] instanceof \PhpParser\Node\Arg) {
|
||||
return \true;
|
||||
}
|
||||
return !$this->getStaticType($methodCall->args[0]->value) instanceof \PHPStan\Type\StringType;
|
||||
return !$this->getType($methodCall->args[0]->value) instanceof \PHPStan\Type\StringType;
|
||||
}
|
||||
private function updateNode(\PhpParser\Node\Expr\MethodCall $methodCall) : \PhpParser\Node\Expr\MethodCall
|
||||
{
|
||||
|
|
|
@ -99,7 +99,7 @@ CODE_SAMPLE
|
|||
if ($this->isObjectType($expr, new \PHPStan\Type\ObjectType('mysqli'))) {
|
||||
return \true;
|
||||
}
|
||||
$staticType = $this->getStaticType($expr);
|
||||
$staticType = $this->getType($expr);
|
||||
$resourceType = new \PHPStan\Type\ResourceType();
|
||||
if ($staticType->equals($resourceType)) {
|
||||
return \true;
|
||||
|
|
|
@ -194,7 +194,7 @@ CODE_SAMPLE
|
|||
*/
|
||||
private function isClassTypeWithChildren($expr) : bool
|
||||
{
|
||||
$callStaticType = $this->getStaticType($expr);
|
||||
$callStaticType = $this->getType($expr);
|
||||
$callStaticType = $this->typeUnwrapper->unwrapNullableType($callStaticType);
|
||||
if (!$callStaticType instanceof \PHPStan\Type\ObjectType) {
|
||||
return \false;
|
||||
|
|
|
@ -104,7 +104,7 @@ CODE_SAMPLE
|
|||
private function isNotThisTypePropertyFetch(\PhpParser\Node\Expr $expr) : bool
|
||||
{
|
||||
if ($expr instanceof \PhpParser\Node\Expr\PropertyFetch) {
|
||||
$variableType = $this->getStaticType($expr->var);
|
||||
$variableType = $this->getType($expr->var);
|
||||
return !$variableType instanceof \PHPStan\Type\ThisType;
|
||||
}
|
||||
return \false;
|
||||
|
|
|
@ -101,7 +101,7 @@ CODE_SAMPLE
|
|||
*/
|
||||
private function processVariableNum(\PhpParser\Node\Stmt\Continue_ $continue, \PhpParser\Node\Expr\Variable $numVariable)
|
||||
{
|
||||
$staticType = $this->getStaticType($numVariable);
|
||||
$staticType = $this->getType($numVariable);
|
||||
if (!$staticType instanceof \PHPStan\Type\ConstantType) {
|
||||
return $continue;
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ CODE_SAMPLE
|
|||
*/
|
||||
private function processVariableNum($stmt, \PhpParser\Node\Expr\Variable $numVariable) : ?\PhpParser\Node
|
||||
{
|
||||
$staticType = $this->getStaticType($numVariable);
|
||||
$staticType = $this->getType($numVariable);
|
||||
if ($staticType instanceof \PHPStan\Type\ConstantType) {
|
||||
if ($staticType instanceof \PHPStan\Type\Constant\ConstantIntegerType) {
|
||||
if ($staticType->getValue() === 0) {
|
||||
|
|
|
@ -43,7 +43,8 @@ final class ListSplitStringRector extends \Rector\Core\Rector\AbstractRector imp
|
|||
if (!$node->var instanceof \PhpParser\Node\Expr\List_) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeTypeResolver->isStaticType($node->expr, \PHPStan\Type\StringType::class)) {
|
||||
$exprType = $this->getType($node->expr);
|
||||
if (!$exprType instanceof \PHPStan\Type\StringType) {
|
||||
return null;
|
||||
}
|
||||
$node->expr = $this->nodeFactory->createFuncCall('str_split', [$node->expr]);
|
||||
|
|
|
@ -90,12 +90,13 @@ CODE_SAMPLE
|
|||
if (!$classMethod instanceof \PhpParser\Node\Stmt\ClassMethod) {
|
||||
$node->name = new \PhpParser\Node\Identifier(\Rector\Core\ValueObject\MethodName::CONSTRUCT);
|
||||
}
|
||||
if ($node->stmts === null) {
|
||||
$stmts = $node->stmts;
|
||||
if ($stmts === null) {
|
||||
return null;
|
||||
}
|
||||
if (\count($node->stmts) === 1) {
|
||||
if (\count($stmts) === 1) {
|
||||
/** @var Expression|Expr $stmt */
|
||||
$stmt = $node->stmts[0];
|
||||
$stmt = $stmts[0];
|
||||
if (!$stmt instanceof \PhpParser\Node\Stmt\Expression) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ CODE_SAMPLE
|
|||
private function resolveStaticCallClassName(\PhpParser\Node\Expr\StaticCall $staticCall) : ?string
|
||||
{
|
||||
if ($staticCall->class instanceof \PhpParser\Node\Expr\PropertyFetch) {
|
||||
$objectType = $this->getObjectType($staticCall->class);
|
||||
$objectType = $this->getType($staticCall->class);
|
||||
if ($objectType instanceof \PHPStan\Type\ObjectType) {
|
||||
return $objectType->getClassName();
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ CODE_SAMPLE
|
|||
return \false;
|
||||
}
|
||||
$value = null;
|
||||
$exprStaticType = $this->getStaticType($expr);
|
||||
$exprStaticType = $this->getType($expr);
|
||||
if ($expr instanceof \PhpParser\Node\Scalar\String_) {
|
||||
$value = $expr->value;
|
||||
} elseif ($exprStaticType instanceof \PHPStan\Type\Constant\ConstantStringType) {
|
||||
|
|
|
@ -89,7 +89,7 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
// this can lead to false positive by phpstan, but that's best we can do
|
||||
$onlyValueType = $this->getStaticType($countedNode);
|
||||
$onlyValueType = $this->getType($countedNode);
|
||||
if ($onlyValueType instanceof \PHPStan\Type\ArrayType) {
|
||||
if (!$this->countableAnalyzer->isCastableArrayType($countedNode)) {
|
||||
return null;
|
||||
|
@ -99,7 +99,8 @@ CODE_SAMPLE
|
|||
if ($this->nodeTypeResolver->isNullableTypeOfSpecificType($countedNode, \PHPStan\Type\ArrayType::class)) {
|
||||
return $this->castToArray($countedNode, $node);
|
||||
}
|
||||
if ($this->nodeTypeResolver->isNullableType($countedNode) || $this->nodeTypeResolver->isStaticType($countedNode, \PHPStan\Type\NullType::class)) {
|
||||
$countedType = $this->getType($countedNode);
|
||||
if ($this->nodeTypeResolver->isNullableType($countedNode) || $countedType instanceof \PHPStan\Type\NullType) {
|
||||
$identical = new \PhpParser\Node\Expr\BinaryOp\Identical($countedNode, $this->nodeFactory->createNull());
|
||||
$ternary = new \PhpParser\Node\Expr\Ternary($identical, new \PhpParser\Node\Scalar\LNumber(0), $node);
|
||||
// prevent infinity loop re-resolution
|
||||
|
|
|
@ -87,7 +87,8 @@ CODE_SAMPLE
|
|||
if ($this->shouldSkip($node)) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeTypeResolver->isNullableType($firstArgValue) && !$this->nodeTypeResolver->isStaticType($firstArgValue, \PHPStan\Type\NullType::class)) {
|
||||
$firstArgType = $this->getType($firstArgValue);
|
||||
if (!$this->nodeTypeResolver->isNullableType($firstArgValue) && !$firstArgType instanceof \PHPStan\Type\NullType) {
|
||||
return null;
|
||||
}
|
||||
$notIdentical = new \PhpParser\Node\Expr\BinaryOp\NotIdentical($firstArgValue, $this->nodeFactory->createNull());
|
||||
|
|
|
@ -67,7 +67,7 @@ CODE_SAMPLE
|
|||
if (!$node->args[1] instanceof \PhpParser\Node\Arg) {
|
||||
return null;
|
||||
}
|
||||
$firstArgStaticType = $this->getStaticType($node->args[1]->value);
|
||||
$firstArgStaticType = $this->getType($node->args[1]->value);
|
||||
if (!$firstArgStaticType instanceof \PHPStan\Type\ObjectType) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ CODE_SAMPLE
|
|||
if (!$this->arrayTypeAnalyzer->isArrayType($expr)) {
|
||||
return \true;
|
||||
}
|
||||
$arrayStaticType = $this->getStaticType($expr);
|
||||
$arrayStaticType = $this->getType($expr);
|
||||
if ($this->isConstantArrayTypeWithStringKeyType($arrayStaticType)) {
|
||||
return \true;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ final class MbStrrposEncodingArgumentPositionRector extends \Rector\Core\Rector\
|
|||
if (!$node->args[2] instanceof \PhpParser\Node\Arg) {
|
||||
return null;
|
||||
}
|
||||
$secondArgType = $this->getStaticType($node->args[2]->value);
|
||||
$secondArgType = $this->getType($node->args[2]->value);
|
||||
if ($secondArgType instanceof \PHPStan\Type\IntegerType) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ CODE_SAMPLE
|
|||
private function processNullableType(\PhpParser\Node\Stmt\Property $property, \PhpParser\Node\Param $param) : void
|
||||
{
|
||||
if ($this->nodeTypeResolver->isNullableType($property)) {
|
||||
$objectType = $this->getObjectType($property);
|
||||
$objectType = $this->getType($property);
|
||||
$param->type = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($objectType, \Rector\PHPStanStaticTypeMapper\ValueObject\TypeKind::PARAM());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -205,7 +205,7 @@ CODE_SAMPLE
|
|||
$classConst = new \PhpParser\Node\Stmt\ClassConst([$const]);
|
||||
$classConst->flags = \PhpParser\Node\Stmt\Class_::MODIFIER_PRIVATE;
|
||||
$this->mirrorComments($classConst, $variable);
|
||||
$constantType = $this->getStaticType($classConst->consts[0]->value);
|
||||
$constantType = $this->getType($classConst->consts[0]->value);
|
||||
$this->varAnnotationManipulator->decorateNodeWithType($classConst, $constantType);
|
||||
return $classConst;
|
||||
}
|
||||
|
|
|
@ -1,162 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Restoration\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Restoration\Type\ConstantReturnToParamTypeConverter;
|
||||
use Rector\Restoration\ValueObject\InferParamFromClassMethodReturn;
|
||||
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix20211007\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Tests\Restoration\Rector\ClassMethod\InferParamFromClassMethodReturnRector\InferParamFromClassMethodReturnRectorTest
|
||||
*/
|
||||
final class InferParamFromClassMethodReturnRector extends \Rector\Core\Rector\AbstractRector implements \Rector\Core\Contract\Rector\ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const INFER_PARAMS_FROM_CLASS_METHOD_RETURNS = 'infer_param_from_class_method_returns';
|
||||
/**
|
||||
* @var InferParamFromClassMethodReturn[]
|
||||
*/
|
||||
private $inferParamFromClassMethodReturn = [];
|
||||
/**
|
||||
* @var \Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer
|
||||
*/
|
||||
private $returnTypeInferer;
|
||||
/**
|
||||
* @var \Rector\Restoration\Type\ConstantReturnToParamTypeConverter
|
||||
*/
|
||||
private $constantReturnToParamTypeConverter;
|
||||
/**
|
||||
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger
|
||||
*/
|
||||
private $phpDocTypeChanger;
|
||||
public function __construct(\Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer $returnTypeInferer, \Rector\Restoration\Type\ConstantReturnToParamTypeConverter $constantReturnToParamTypeConverter, \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger $phpDocTypeChanger)
|
||||
{
|
||||
$this->returnTypeInferer = $returnTypeInferer;
|
||||
$this->constantReturnToParamTypeConverter = $constantReturnToParamTypeConverter;
|
||||
$this->phpDocTypeChanger = $phpDocTypeChanger;
|
||||
}
|
||||
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Change @param doc based on another method return type', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [String_::class];
|
||||
}
|
||||
|
||||
public function process(Node $node)
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [String_::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String_ $node
|
||||
*/
|
||||
public function process(Node $node)
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, [self::INFER_PARAMS_FROM_CLASS_METHOD_RETURNS => [new \Rector\Restoration\ValueObject\InferParamFromClassMethodReturn('SomeClass', 'process', 'getNodeTypes')]])]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [\PhpParser\Node\Stmt\ClassMethod::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
// must be exactly 1 param
|
||||
if (\count($node->params) !== 1) {
|
||||
return null;
|
||||
}
|
||||
$firstParam = $node->params[0];
|
||||
$paramName = $this->getName($firstParam);
|
||||
foreach ($this->inferParamFromClassMethodReturn as $singleInferParamFromClassMethodReturn) {
|
||||
$returnClassMethod = $this->matchReturnClassMethod($node, $singleInferParamFromClassMethodReturn);
|
||||
if (!$returnClassMethod instanceof \PhpParser\Node\Stmt\ClassMethod) {
|
||||
continue;
|
||||
}
|
||||
$returnType = $this->returnTypeInferer->inferFunctionLike($returnClassMethod);
|
||||
$currentPhpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
|
||||
$paramType = $this->constantReturnToParamTypeConverter->convert($returnType);
|
||||
if ($paramType instanceof \PHPStan\Type\MixedType) {
|
||||
continue;
|
||||
}
|
||||
if ($this->isParamDocTypeEqualToPhpType($firstParam, $paramType)) {
|
||||
return null;
|
||||
}
|
||||
$this->phpDocTypeChanger->changeParamType($currentPhpDocInfo, $paramType, $firstParam, $paramName);
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param array<string, InferParamFromClassMethodReturn[]> $configuration
|
||||
*/
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
$inferParamsFromClassMethodReturns = $configuration[self::INFER_PARAMS_FROM_CLASS_METHOD_RETURNS] ?? [];
|
||||
\RectorPrefix20211007\Webmozart\Assert\Assert::allIsInstanceOf($inferParamsFromClassMethodReturns, \Rector\Restoration\ValueObject\InferParamFromClassMethodReturn::class);
|
||||
$this->inferParamFromClassMethodReturn = $inferParamsFromClassMethodReturns;
|
||||
}
|
||||
private function matchReturnClassMethod(\PhpParser\Node\Stmt\ClassMethod $classMethod, \Rector\Restoration\ValueObject\InferParamFromClassMethodReturn $inferParamFromClassMethodReturn) : ?\PhpParser\Node\Stmt\ClassMethod
|
||||
{
|
||||
$scope = $classMethod->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
|
||||
if (!$scope instanceof \PHPStan\Analyser\Scope) {
|
||||
return null;
|
||||
}
|
||||
$classReflection = $scope->getClassReflection();
|
||||
if (!$classReflection instanceof \PHPStan\Reflection\ClassReflection) {
|
||||
return null;
|
||||
}
|
||||
if (!$classReflection->isSubclassOf($inferParamFromClassMethodReturn->getClass())) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isName($classMethod->name, $inferParamFromClassMethodReturn->getParamMethod())) {
|
||||
return null;
|
||||
}
|
||||
$classLike = $classMethod->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NODE);
|
||||
if (!$classLike instanceof \PhpParser\Node\Stmt\Class_) {
|
||||
return null;
|
||||
}
|
||||
return $classLike->getMethod($inferParamFromClassMethodReturn->getReturnMethod());
|
||||
}
|
||||
private function isParamDocTypeEqualToPhpType(\PhpParser\Node\Param $param, \PHPStan\Type\Type $paramType) : bool
|
||||
{
|
||||
$currentParamType = $this->nodeTypeResolver->getStaticType($param);
|
||||
return $currentParamType->equals($paramType);
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Restoration\Type;
|
||||
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\Constant\ConstantStringType;
|
||||
use PHPStan\Type\Generic\GenericClassStringType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeUtils;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
|
||||
final class ConstantReturnToParamTypeConverter
|
||||
{
|
||||
/**
|
||||
* @var \Rector\NodeTypeResolver\PHPStan\Type\TypeFactory
|
||||
*/
|
||||
private $typeFactory;
|
||||
public function __construct(\Rector\NodeTypeResolver\PHPStan\Type\TypeFactory $typeFactory)
|
||||
{
|
||||
$this->typeFactory = $typeFactory;
|
||||
}
|
||||
public function convert(\PHPStan\Type\Type $type) : \PHPStan\Type\Type
|
||||
{
|
||||
if ($type instanceof \PHPStan\Type\UnionType) {
|
||||
$flattenReturnTypes = \PHPStan\Type\TypeUtils::flattenTypes($type);
|
||||
$unionedTypes = [];
|
||||
foreach ($flattenReturnTypes as $flattenReturnType) {
|
||||
if ($flattenReturnType instanceof \PHPStan\Type\ArrayType) {
|
||||
$unionedTypes[] = $flattenReturnType->getItemType();
|
||||
}
|
||||
}
|
||||
$resolvedTypes = [];
|
||||
foreach ($unionedTypes as $unionedType) {
|
||||
$resolvedTypes[] = $this->convert($unionedType);
|
||||
}
|
||||
return new \PHPStan\Type\UnionType($resolvedTypes);
|
||||
}
|
||||
if ($type instanceof \PHPStan\Type\Constant\ConstantStringType) {
|
||||
return $this->unwrapConstantTypeToObjectType($type);
|
||||
}
|
||||
if ($type instanceof \PHPStan\Type\ArrayType) {
|
||||
return $this->unwrapConstantTypeToObjectType($type);
|
||||
}
|
||||
return new \PHPStan\Type\MixedType();
|
||||
}
|
||||
private function unwrapConstantTypeToObjectType(\PHPStan\Type\Type $type) : \PHPStan\Type\Type
|
||||
{
|
||||
if ($type instanceof \PHPStan\Type\ArrayType) {
|
||||
return $this->unwrapConstantTypeToObjectType($type->getItemType());
|
||||
}
|
||||
if ($type instanceof \PHPStan\Type\Constant\ConstantStringType) {
|
||||
return new \PHPStan\Type\ObjectType($type->getValue());
|
||||
}
|
||||
if ($type instanceof \PHPStan\Type\Generic\GenericClassStringType && $type->getGenericType() instanceof \PHPStan\Type\ObjectType) {
|
||||
return $type->getGenericType();
|
||||
}
|
||||
if ($type instanceof \PHPStan\Type\UnionType) {
|
||||
return $this->unwrapUnionType($type);
|
||||
}
|
||||
return new \PHPStan\Type\MixedType();
|
||||
}
|
||||
private function unwrapUnionType(\PHPStan\Type\UnionType $unionType) : \PHPStan\Type\Type
|
||||
{
|
||||
$types = [];
|
||||
foreach ($unionType->getTypes() as $unionedType) {
|
||||
$unionType = $this->unwrapConstantTypeToObjectType($unionedType);
|
||||
if ($unionType !== null) {
|
||||
$types[] = $unionType;
|
||||
}
|
||||
}
|
||||
return $this->typeFactory->createMixedPassedOrUnionType($types);
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Restoration\ValueObject;
|
||||
|
||||
final class InferParamFromClassMethodReturn
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $class;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $paramMethod;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $returnMethod;
|
||||
public function __construct(string $class, string $paramMethod, string $returnMethod)
|
||||
{
|
||||
$this->class = $class;
|
||||
$this->paramMethod = $paramMethod;
|
||||
$this->returnMethod = $returnMethod;
|
||||
}
|
||||
public function getClass() : string
|
||||
{
|
||||
return $this->class;
|
||||
}
|
||||
public function getParamMethod() : string
|
||||
{
|
||||
return $this->paramMethod;
|
||||
}
|
||||
public function getReturnMethod() : string
|
||||
{
|
||||
return $this->returnMethod;
|
||||
}
|
||||
}
|
|
@ -89,7 +89,7 @@ CODE_SAMPLE
|
|||
continue;
|
||||
}
|
||||
$arg = $node->args[$position];
|
||||
$argValueType = $this->getStaticType($arg->value);
|
||||
$argValueType = $this->getType($arg->value);
|
||||
if (!$argValueType instanceof \PHPStan\Type\ClosureType) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ CODE_SAMPLE
|
|||
if ($stmt instanceof \PhpParser\Node\Stmt) {
|
||||
continue;
|
||||
}
|
||||
$stmtType = $this->getStaticType($stmt);
|
||||
$stmtType = $this->getType($stmt);
|
||||
if ($stmtType instanceof \PHPStan\Type\NeverType) {
|
||||
$hasNeverType = \true;
|
||||
}
|
||||
|
|
|
@ -74,8 +74,7 @@ final class ReturnTypeInferer
|
|||
{
|
||||
$isSupportedStaticReturnType = $this->phpVersionProvider->isAtLeastPhpVersion(\Rector\Core\ValueObject\PhpVersionFeature::STATIC_RETURN_TYPE);
|
||||
$isAutoImport = $this->parameterProvider->provideBoolParameter(\Rector\Core\Configuration\Option::AUTO_IMPORT_NAMES);
|
||||
$isAutoImportFullyQuafiedReturn = $this->isAutoImportWithFullyQualifiedReturn($isAutoImport, $functionLike);
|
||||
if ($isAutoImportFullyQuafiedReturn) {
|
||||
if ($this->isAutoImportWithFullyQualifiedReturn($isAutoImport, $functionLike)) {
|
||||
return new \PHPStan\Type\MixedType();
|
||||
}
|
||||
foreach ($this->returnTypeInferers as $returnTypeInferer) {
|
||||
|
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '5ba14990349db5141c98b373d3360018f8bd00a0';
|
||||
public const PACKAGE_VERSION = 'f6f7431ce7aa36124efcda10e1b9ed16a5ccc343';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-10-07 23:52:15';
|
||||
public const RELEASE_DATE = '2021-10-07 19:34:41';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20211007\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
|
|
@ -309,17 +309,28 @@ abstract class AbstractRector extends \PhpParser\NodeVisitorAbstract implements
|
|||
{
|
||||
return $this->nodeTypeResolver->isObjectType($node, $objectType);
|
||||
}
|
||||
protected function getStaticType(\PhpParser\Node $node) : \PHPStan\Type\Type
|
||||
/**
|
||||
* Use this method for getting expr|node type
|
||||
*/
|
||||
protected function getType(\PhpParser\Node $node) : \PHPStan\Type\Type
|
||||
{
|
||||
return $this->nodeTypeResolver->getStaticType($node);
|
||||
return $this->nodeTypeResolver->getType($node);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* Use getStaticType() instead, as single method to get types
|
||||
* Use @see AbstractRector::getType() instead, as single method to get types
|
||||
*/
|
||||
protected function getObjectType(\PhpParser\Node $node) : \PHPStan\Type\Type
|
||||
{
|
||||
return $this->nodeTypeResolver->resolve($node);
|
||||
return $this->nodeTypeResolver->getType($node);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* Use @see AbstractRector::getType() instead, as single method to get types
|
||||
*/
|
||||
protected function getStaticType(\PhpParser\Node $node) : \PHPStan\Type\Type
|
||||
{
|
||||
return $this->nodeTypeResolver->getType($node);
|
||||
}
|
||||
/**
|
||||
* @param Node|Node[] $nodes
|
||||
|
@ -335,14 +346,6 @@ abstract class AbstractRector extends \PhpParser\NodeVisitorAbstract implements
|
|||
{
|
||||
return $this->betterStandardPrinter->print($node);
|
||||
}
|
||||
/**
|
||||
* @deprecated Use FQN PhpVersionProvider service directly instead or implements provideMinPhpVersion, this method will be removed soon
|
||||
* Or implement \Rector\VersionBonding\Contract\MinPhpVersionInterface
|
||||
*/
|
||||
protected function isAtLeastPhpVersion(int $version) : bool
|
||||
{
|
||||
return $this->phpVersionProvider->isAtLeastPhpVersion($version);
|
||||
}
|
||||
protected function mirrorComments(\PhpParser\Node $newNode, \PhpParser\Node $oldNode) : void
|
||||
{
|
||||
$newNode->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PHP_DOC_INFO, $oldNode->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PHP_DOC_INFO));
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInite2e70f72a121ecdb6eba21005e4b4e55::getLoader();
|
||||
return ComposerAutoloaderInit3dce88f69e2175ec99fe8e0ec6003c78::getLoader();
|
||||
|
|
|
@ -2927,13 +2927,10 @@ return array(
|
|||
'Rector\\Renaming\\ValueObject\\RenamedNamespace' => $baseDir . '/rules/Renaming/ValueObject/RenamedNamespace.php',
|
||||
'Rector\\Restoration\\Rector\\ClassConstFetch\\MissingClassConstantReferenceToStringRector' => $baseDir . '/rules/Restoration/Rector/ClassConstFetch/MissingClassConstantReferenceToStringRector.php',
|
||||
'Rector\\Restoration\\Rector\\ClassLike\\UpdateFileNameByClassNameFileSystemRector' => $baseDir . '/rules/Restoration/Rector/ClassLike/UpdateFileNameByClassNameFileSystemRector.php',
|
||||
'Rector\\Restoration\\Rector\\ClassMethod\\InferParamFromClassMethodReturnRector' => $baseDir . '/rules/Restoration/Rector/ClassMethod/InferParamFromClassMethodReturnRector.php',
|
||||
'Rector\\Restoration\\Rector\\Class_\\RemoveFinalFromEntityRector' => $baseDir . '/rules/Restoration/Rector/Class_/RemoveFinalFromEntityRector.php',
|
||||
'Rector\\Restoration\\Rector\\Namespace_\\CompleteImportForPartialAnnotationRector' => $baseDir . '/rules/Restoration/Rector/Namespace_/CompleteImportForPartialAnnotationRector.php',
|
||||
'Rector\\Restoration\\Rector\\Property\\MakeTypedPropertyNullableIfCheckedRector' => $baseDir . '/rules/Restoration/Rector/Property/MakeTypedPropertyNullableIfCheckedRector.php',
|
||||
'Rector\\Restoration\\Type\\ConstantReturnToParamTypeConverter' => $baseDir . '/rules/Restoration/Type/ConstantReturnToParamTypeConverter.php',
|
||||
'Rector\\Restoration\\ValueObject\\CompleteImportForPartialAnnotation' => $baseDir . '/rules/Restoration/ValueObject/CompleteImportForPartialAnnotation.php',
|
||||
'Rector\\Restoration\\ValueObject\\InferParamFromClassMethodReturn' => $baseDir . '/rules/Restoration/ValueObject/InferParamFromClassMethodReturn.php',
|
||||
'Rector\\Set\\Contract\\SetListInterface' => $baseDir . '/packages/Set/Contract/SetListInterface.php',
|
||||
'Rector\\Set\\ValueObject\\DowngradeSetList' => $baseDir . '/packages/Set/ValueObject/DowngradeSetList.php',
|
||||
'Rector\\Set\\ValueObject\\SetList' => $baseDir . '/packages/Set/ValueObject/SetList.php',
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInite2e70f72a121ecdb6eba21005e4b4e55
|
||||
class ComposerAutoloaderInit3dce88f69e2175ec99fe8e0ec6003c78
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,15 +22,15 @@ class ComposerAutoloaderInite2e70f72a121ecdb6eba21005e4b4e55
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInite2e70f72a121ecdb6eba21005e4b4e55', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit3dce88f69e2175ec99fe8e0ec6003c78', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInite2e70f72a121ecdb6eba21005e4b4e55', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit3dce88f69e2175ec99fe8e0ec6003c78', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInite2e70f72a121ecdb6eba21005e4b4e55::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit3dce88f69e2175ec99fe8e0ec6003c78::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
|
@ -42,19 +42,19 @@ class ComposerAutoloaderInite2e70f72a121ecdb6eba21005e4b4e55
|
|||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInite2e70f72a121ecdb6eba21005e4b4e55::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit3dce88f69e2175ec99fe8e0ec6003c78::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequiree2e70f72a121ecdb6eba21005e4b4e55($fileIdentifier, $file);
|
||||
composerRequire3dce88f69e2175ec99fe8e0ec6003c78($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequiree2e70f72a121ecdb6eba21005e4b4e55($fileIdentifier, $file)
|
||||
function composerRequire3dce88f69e2175ec99fe8e0ec6003c78($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInite2e70f72a121ecdb6eba21005e4b4e55
|
||||
class ComposerStaticInit3dce88f69e2175ec99fe8e0ec6003c78
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
|
@ -3287,13 +3287,10 @@ class ComposerStaticInite2e70f72a121ecdb6eba21005e4b4e55
|
|||
'Rector\\Renaming\\ValueObject\\RenamedNamespace' => __DIR__ . '/../..' . '/rules/Renaming/ValueObject/RenamedNamespace.php',
|
||||
'Rector\\Restoration\\Rector\\ClassConstFetch\\MissingClassConstantReferenceToStringRector' => __DIR__ . '/../..' . '/rules/Restoration/Rector/ClassConstFetch/MissingClassConstantReferenceToStringRector.php',
|
||||
'Rector\\Restoration\\Rector\\ClassLike\\UpdateFileNameByClassNameFileSystemRector' => __DIR__ . '/../..' . '/rules/Restoration/Rector/ClassLike/UpdateFileNameByClassNameFileSystemRector.php',
|
||||
'Rector\\Restoration\\Rector\\ClassMethod\\InferParamFromClassMethodReturnRector' => __DIR__ . '/../..' . '/rules/Restoration/Rector/ClassMethod/InferParamFromClassMethodReturnRector.php',
|
||||
'Rector\\Restoration\\Rector\\Class_\\RemoveFinalFromEntityRector' => __DIR__ . '/../..' . '/rules/Restoration/Rector/Class_/RemoveFinalFromEntityRector.php',
|
||||
'Rector\\Restoration\\Rector\\Namespace_\\CompleteImportForPartialAnnotationRector' => __DIR__ . '/../..' . '/rules/Restoration/Rector/Namespace_/CompleteImportForPartialAnnotationRector.php',
|
||||
'Rector\\Restoration\\Rector\\Property\\MakeTypedPropertyNullableIfCheckedRector' => __DIR__ . '/../..' . '/rules/Restoration/Rector/Property/MakeTypedPropertyNullableIfCheckedRector.php',
|
||||
'Rector\\Restoration\\Type\\ConstantReturnToParamTypeConverter' => __DIR__ . '/../..' . '/rules/Restoration/Type/ConstantReturnToParamTypeConverter.php',
|
||||
'Rector\\Restoration\\ValueObject\\CompleteImportForPartialAnnotation' => __DIR__ . '/../..' . '/rules/Restoration/ValueObject/CompleteImportForPartialAnnotation.php',
|
||||
'Rector\\Restoration\\ValueObject\\InferParamFromClassMethodReturn' => __DIR__ . '/../..' . '/rules/Restoration/ValueObject/InferParamFromClassMethodReturn.php',
|
||||
'Rector\\Set\\Contract\\SetListInterface' => __DIR__ . '/../..' . '/packages/Set/Contract/SetListInterface.php',
|
||||
'Rector\\Set\\ValueObject\\DowngradeSetList' => __DIR__ . '/../..' . '/packages/Set/ValueObject/DowngradeSetList.php',
|
||||
'Rector\\Set\\ValueObject\\SetList' => __DIR__ . '/../..' . '/packages/Set/ValueObject/SetList.php',
|
||||
|
@ -3894,9 +3891,9 @@ class ComposerStaticInite2e70f72a121ecdb6eba21005e4b4e55
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInite2e70f72a121ecdb6eba21005e4b4e55::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInite2e70f72a121ecdb6eba21005e4b4e55::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInite2e70f72a121ecdb6eba21005e4b4e55::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit3dce88f69e2175ec99fe8e0ec6003c78::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit3dce88f69e2175ec99fe8e0ec6003c78::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit3dce88f69e2175ec99fe8e0ec6003c78::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
|
@ -1478,17 +1478,17 @@
|
|||
},
|
||||
{
|
||||
"name": "rector\/rector-phpunit",
|
||||
"version": "0.11.9",
|
||||
"version_normalized": "0.11.9.0",
|
||||
"version": "0.11.10",
|
||||
"version_normalized": "0.11.10.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
|
||||
"reference": "291bfbcca49938bab95f7fa93ab96227f58bf017"
|
||||
"reference": "8888715ef8c8dc7a138f435a0fe2aa0a777d3cd2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/291bfbcca49938bab95f7fa93ab96227f58bf017",
|
||||
"reference": "291bfbcca49938bab95f7fa93ab96227f58bf017",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/8888715ef8c8dc7a138f435a0fe2aa0a777d3cd2",
|
||||
"reference": "8888715ef8c8dc7a138f435a0fe2aa0a777d3cd2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1507,7 +1507,7 @@
|
|||
"symplify\/phpstan-rules": "^9.2",
|
||||
"symplify\/rule-doc-generator": "^9.4"
|
||||
},
|
||||
"time": "2021-10-04T21:34:56+00:00",
|
||||
"time": "2021-10-07T17:28:00+00:00",
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
|
@ -1532,23 +1532,23 @@
|
|||
"description": "Rector upgrades rules for PHPUnit",
|
||||
"support": {
|
||||
"issues": "https:\/\/github.com\/rectorphp\/rector-phpunit\/issues",
|
||||
"source": "https:\/\/github.com\/rectorphp\/rector-phpunit\/tree\/0.11.9"
|
||||
"source": "https:\/\/github.com\/rectorphp\/rector-phpunit\/tree\/0.11.10"
|
||||
},
|
||||
"install-path": "..\/rector\/rector-phpunit"
|
||||
},
|
||||
{
|
||||
"name": "rector\/rector-symfony",
|
||||
"version": "0.11.21",
|
||||
"version_normalized": "0.11.21.0",
|
||||
"version": "0.11.22",
|
||||
"version_normalized": "0.11.22.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
|
||||
"reference": "db7ca76eaf2e5bfaf03ef6dcd2efb8749cae9880"
|
||||
"reference": "6cd6f87e8202d60682f74e324e5866efb3445830"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/db7ca76eaf2e5bfaf03ef6dcd2efb8749cae9880",
|
||||
"reference": "db7ca76eaf2e5bfaf03ef6dcd2efb8749cae9880",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/6cd6f87e8202d60682f74e324e5866efb3445830",
|
||||
"reference": "6cd6f87e8202d60682f74e324e5866efb3445830",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1571,7 +1571,7 @@
|
|||
"symplify\/phpstan-rules": "^9.4",
|
||||
"symplify\/rule-doc-generator": "^9.4"
|
||||
},
|
||||
"time": "2021-10-04T21:32:23+00:00",
|
||||
"time": "2021-10-07T17:26:16+00:00",
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
|
@ -1596,7 +1596,7 @@
|
|||
"description": "Rector upgrades rules for Symfony Framework",
|
||||
"support": {
|
||||
"issues": "https:\/\/github.com\/rectorphp\/rector-symfony\/issues",
|
||||
"source": "https:\/\/github.com\/rectorphp\/rector-symfony\/tree\/0.11.21"
|
||||
"source": "https:\/\/github.com\/rectorphp\/rector-symfony\/tree\/0.11.22"
|
||||
},
|
||||
"install-path": "..\/rector\/rector-symfony"
|
||||
},
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
|
|||
*/
|
||||
final class GeneratedConfig
|
||||
{
|
||||
public const EXTENSIONS = array('rector/rector-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => '0.11.4'), 'rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => '0.11.20'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => '0.11.7'), 'rector/rector-nette' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-nette', 'relative_install_path' => '../../rector-nette', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => '0.11.26'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => '0.11.3'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => '0.11.9'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => '0.11.21'), 'ssch/typo3-rector' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/ssch/typo3-rector', 'relative_install_path' => '../../../ssch/typo3-rector', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'v0.11.26'));
|
||||
public const EXTENSIONS = array('rector/rector-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => '0.11.4'), 'rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => '0.11.20'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => '0.11.7'), 'rector/rector-nette' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-nette', 'relative_install_path' => '../../rector-nette', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => '0.11.26'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => '0.11.3'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => '0.11.10'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => '0.11.22'), 'ssch/typo3-rector' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/ssch/typo3-rector', 'relative_install_path' => '../../../ssch/typo3-rector', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'v0.11.26'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -71,8 +71,9 @@ CODE_SAMPLE
|
|||
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, ['assertContains', 'assertNotContains'])) {
|
||||
return null;
|
||||
}
|
||||
//when second argument is string: do nothing
|
||||
if ($this->nodeTypeResolver->isStaticType($node->args[1]->value, \PHPStan\Type\StringType::class)) {
|
||||
// when second argument is string: do nothing
|
||||
$secondArgType = $this->getStaticType($node->args[1]->value);
|
||||
if ($secondArgType instanceof \PHPStan\Type\StringType) {
|
||||
return null;
|
||||
}
|
||||
//when less then 5 arguments given: do nothing
|
||||
|
|
|
@ -85,7 +85,8 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
// type analyzer
|
||||
if ($this->nodeTypeResolver->isStaticType($activeArgValue, \PHPStan\Type\StringType::class)) {
|
||||
$activeValueType = $this->getStaticType($activeArgValue);
|
||||
if ($activeValueType instanceof \PHPStan\Type\StringType) {
|
||||
$this->processStringType($node, $argumentPosition, $activeArgValue);
|
||||
}
|
||||
return $node;
|
||||
|
|
|
@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
|
|||
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
|
||||
spl_autoload_call('RectorPrefix20211007\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInite2e70f72a121ecdb6eba21005e4b4e55', false) && !interface_exists('ComposerAutoloaderInite2e70f72a121ecdb6eba21005e4b4e55', false) && !trait_exists('ComposerAutoloaderInite2e70f72a121ecdb6eba21005e4b4e55', false)) {
|
||||
spl_autoload_call('RectorPrefix20211007\ComposerAutoloaderInite2e70f72a121ecdb6eba21005e4b4e55');
|
||||
if (!class_exists('ComposerAutoloaderInit3dce88f69e2175ec99fe8e0ec6003c78', false) && !interface_exists('ComposerAutoloaderInit3dce88f69e2175ec99fe8e0ec6003c78', false) && !trait_exists('ComposerAutoloaderInit3dce88f69e2175ec99fe8e0ec6003c78', false)) {
|
||||
spl_autoload_call('RectorPrefix20211007\ComposerAutoloaderInit3dce88f69e2175ec99fe8e0ec6003c78');
|
||||
}
|
||||
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
|
||||
spl_autoload_call('RectorPrefix20211007\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
|
@ -3306,9 +3306,9 @@ if (!function_exists('print_node')) {
|
|||
return \RectorPrefix20211007\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequiree2e70f72a121ecdb6eba21005e4b4e55')) {
|
||||
function composerRequiree2e70f72a121ecdb6eba21005e4b4e55() {
|
||||
return \RectorPrefix20211007\composerRequiree2e70f72a121ecdb6eba21005e4b4e55(...func_get_args());
|
||||
if (!function_exists('composerRequire3dce88f69e2175ec99fe8e0ec6003c78')) {
|
||||
function composerRequire3dce88f69e2175ec99fe8e0ec6003c78() {
|
||||
return \RectorPrefix20211007\composerRequire3dce88f69e2175ec99fe8e0ec6003c78(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('parseArgs')) {
|
||||
|
|
Loading…
Reference in New Issue