Compare commits

..

2 Commits

Author SHA1 Message Date
Tomas Votruba
d5e203a6e9 Updated Rector to commit d5069f0fccf649646eeea05b5291c0ac34e511d6
d5069f0fcc [Php83] Handle default native constant on AddTypeToConstRector (#5843)
2024-04-23 12:10:57 +00:00
Tomas Votruba
a3b725126c Updated Rector to commit 775916c6416e68507e846421f04e2cabbfa2d737
775916c641 [Naming] Skip DateTime as individual in name resolver (#5842)
2024-04-23 09:06:40 +00:00
4 changed files with 27 additions and 9 deletions

View File

@ -3,6 +3,7 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\DeadCode\NodeAnalyzer; namespace Rector\DeadCode\NodeAnalyzer;
use PhpParser\Node\Expr\NullsafeMethodCall;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Arg; use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\Array_;
@ -121,7 +122,7 @@ final class IsClassMethodUsedAnalyzer
{ {
$className = (string) $this->nodeNameResolver->getName($class); $className = (string) $this->nodeNameResolver->getName($class);
/** @var Node\Expr\NullsafeMethodCall[] $methodCalls */ /** @var Node\Expr\NullsafeMethodCall[] $methodCalls */
$methodCalls = $this->betterNodeFinder->findInstanceOf($class, Node\Expr\NullsafeMethodCall::class); $methodCalls = $this->betterNodeFinder->findInstanceOf($class, NullsafeMethodCall::class);
return $this->callCollectionAnalyzer->isExists($methodCalls, $classMethodName, $className); return $this->callCollectionAnalyzer->isExists($methodCalls, $classMethodName, $className);
} }
private function isInArrayMap(Class_ $class, Array_ $array) : bool private function isInArrayMap(Class_ $class, Array_ $array) : bool

View File

@ -3,6 +3,7 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\Naming\Naming; namespace Rector\Naming\Naming;
use DateTimeInterface;
use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\MethodCall;
@ -93,6 +94,9 @@ final class ExpectedNameResolver
} }
$className = $this->nodeNameResolver->getName($new->class); $className = $this->nodeNameResolver->getName($new->class);
$fullyQualifiedObjectType = new FullyQualifiedObjectType($className); $fullyQualifiedObjectType = new FullyQualifiedObjectType($className);
if ($fullyQualifiedObjectType->isInstanceOf(DateTimeInterface::class)->yes()) {
return null;
}
$expectedName = $this->propertyNaming->getExpectedNameFromType($fullyQualifiedObjectType); $expectedName = $this->propertyNaming->getExpectedNameFromType($fullyQualifiedObjectType);
if (!$expectedName instanceof ExpectedName) { if (!$expectedName instanceof ExpectedName) {
return null; return null;

View File

@ -19,7 +19,9 @@ use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassConst; use PhpParser\Node\Stmt\ClassConst;
use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider; use PHPStan\Reflection\ReflectionProvider;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\Rector\AbstractRector; use Rector\Rector\AbstractRector;
use Rector\StaticTypeMapper\StaticTypeMapper;
use Rector\ValueObject\PhpVersionFeature; use Rector\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@ -34,9 +36,15 @@ final class AddTypeToConstRector extends AbstractRector implements MinPhpVersion
* @var \PHPStan\Reflection\ReflectionProvider * @var \PHPStan\Reflection\ReflectionProvider
*/ */
private $reflectionProvider; private $reflectionProvider;
public function __construct(ReflectionProvider $reflectionProvider) /**
* @readonly
* @var \Rector\StaticTypeMapper\StaticTypeMapper
*/
private $staticTypeMapper;
public function __construct(ReflectionProvider $reflectionProvider, StaticTypeMapper $staticTypeMapper)
{ {
$this->reflectionProvider = $reflectionProvider; $this->reflectionProvider = $reflectionProvider;
$this->staticTypeMapper = $staticTypeMapper;
} }
public function getRuleDefinition() : RuleDefinition public function getRuleDefinition() : RuleDefinition
{ {
@ -133,11 +141,16 @@ CODE_SAMPLE
if ($expr instanceof DNumber) { if ($expr instanceof DNumber) {
return new Identifier('float'); return new Identifier('float');
} }
if ($expr instanceof ConstFetch && $expr->name->toLowerString() !== 'null') { if ($expr instanceof ConstFetch) {
return new Identifier('bool'); if ($expr->name->toLowerString() === 'null') {
} return new Identifier('null');
if ($expr instanceof ConstFetch && $expr->name->toLowerString() === 'null') { }
return new Identifier('null'); $type = $this->nodeTypeResolver->getNativeType($expr);
$nodeType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::PROPERTY);
if (!$nodeType instanceof Identifier) {
return null;
}
return $nodeType;
} }
if ($expr instanceof Array_) { if ($expr instanceof Array_) {
return new Identifier('array'); return new Identifier('array');

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api * @api
* @var string * @var string
*/ */
public const PACKAGE_VERSION = '6eac87db32eff9308a037fb32ce973ccf905fc92'; public const PACKAGE_VERSION = 'd5069f0fccf649646eeea05b5291c0ac34e511d6';
/** /**
* @api * @api
* @var string * @var string
*/ */
public const RELEASE_DATE = '2024-04-22 16:33:11'; public const RELEASE_DATE = '2024-04-23 19:08:22';
/** /**
* @var int * @var int
*/ */