mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 18:00:50 +00:00
Updated Rector to commit 7607b334736d241820f9f307423f6050801b46af
7607b33473
NullableCompareToNullRector: Don't trust phpdocs (#5225)
This commit is contained in:
parent
5990b98c4e
commit
95582bf2b1
|
@ -15,6 +15,7 @@ use PHPStan\Type\IntegerType;
|
|||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\StringType;
|
||||
use PHPStan\Type\TypeCombinator;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
|
@ -68,35 +69,24 @@ CODE_SAMPLE
|
|||
}
|
||||
private function isNullableNonScalarType(Expr $expr) : bool
|
||||
{
|
||||
$staticType = $this->getType($expr);
|
||||
if ($staticType instanceof MixedType) {
|
||||
return \false;
|
||||
}
|
||||
if (!$staticType instanceof UnionType) {
|
||||
return \false;
|
||||
}
|
||||
$nativeType = $this->nodeTypeResolver->getNativeType($expr);
|
||||
// is non-nullable?
|
||||
if ($staticType->isSuperTypeOf(new NullType())->no()) {
|
||||
if (!TypeCombinator::containsNull($nativeType)) {
|
||||
return \false;
|
||||
}
|
||||
if (!$nativeType instanceof UnionType) {
|
||||
return \false;
|
||||
}
|
||||
// is array?
|
||||
foreach ($staticType->getTypes() as $subType) {
|
||||
foreach ($nativeType->getTypes() as $subType) {
|
||||
if ($subType->isArray()->yes()) {
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
// is string?
|
||||
if ($staticType->isSuperTypeOf(new StringType())->yes()) {
|
||||
$nativeType = TypeCombinator::removeNull($nativeType);
|
||||
if ($nativeType->isScalar()->yes()) {
|
||||
return \false;
|
||||
}
|
||||
// is number?
|
||||
if ($staticType->isSuperTypeOf(new IntegerType())->yes()) {
|
||||
return \false;
|
||||
}
|
||||
// is bool?
|
||||
if ($staticType->isSuperTypeOf(new BooleanType())->yes()) {
|
||||
return \false;
|
||||
}
|
||||
return !$staticType->isSuperTypeOf(new FloatType())->yes();
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '8615d40f4c8acb58a000f5bc7e0d0a0cfd353b7f';
|
||||
public const PACKAGE_VERSION = '7607b334736d241820f9f307423f6050801b46af';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-11-05 20:55:04';
|
||||
public const RELEASE_DATE = '2023-11-06 16:09:43';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user