mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-12 22:22:24 +00:00
0fc42c2559
47fa234379
[CodeQuality] Add Variable support on class arg on InlineIsAInstanceOfRector (#3261)
40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\TypeDeclaration\TypeAnalyzer;
|
|
|
|
use PhpParser\Node\Expr;
|
|
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
|
|
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
|
|
use PhpParser\Node\Expr\BinaryOp\Equal;
|
|
use PhpParser\Node\Expr\BinaryOp\Identical;
|
|
use PhpParser\Node\Expr\BinaryOp\NotEqual;
|
|
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
|
|
use PhpParser\Node\Expr\ConstFetch;
|
|
use PhpParser\Node\Expr\Empty_;
|
|
final class AlwaysStrictBoolExprAnalyzer
|
|
{
|
|
/**
|
|
* @var array<class-string<Expr>>
|
|
*/
|
|
private const BOOL_TYPE_NODES = [
|
|
// detect strict type here :)
|
|
Empty_::class,
|
|
BooleanAnd::class,
|
|
BooleanOr::class,
|
|
Equal::class,
|
|
NotEqual::class,
|
|
Identical::class,
|
|
NotIdentical::class,
|
|
];
|
|
public function isStrictBoolExpr(Expr $expr) : bool
|
|
{
|
|
foreach (self::BOOL_TYPE_NODES as $boolTypeNode) {
|
|
if ($expr instanceof $boolTypeNode) {
|
|
return \true;
|
|
}
|
|
}
|
|
return $expr instanceof ConstFetch && \in_array($expr->name->toLowerString(), ['true', 'false'], \true);
|
|
}
|
|
}
|