rector/rules/Php80/ValueObjectFactory/StrStartsWithFactory.php

35 lines
1.1 KiB
PHP
Raw Normal View History

<?php
declare (strict_types=1);
2022-06-06 16:43:29 +00:00
namespace RectorPrefix20220606\Rector\Php80\ValueObjectFactory;
2022-06-06 16:43:29 +00:00
use RectorPrefix20220606\PhpParser\Node\Arg;
use RectorPrefix20220606\PhpParser\Node\Expr\FuncCall;
use RectorPrefix20220606\Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use RectorPrefix20220606\Rector\Php80\ValueObject\StrStartsWith;
final class StrStartsWithFactory
{
/**
* @readonly
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
2022-06-06 16:43:29 +00:00
public function __construct(ArgsAnalyzer $argsAnalyzer)
{
$this->argsAnalyzer = $argsAnalyzer;
}
2022-06-06 16:43:29 +00:00
public function createFromFuncCall(FuncCall $funcCall, bool $isPositive) : ?StrStartsWith
{
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($funcCall->args, [0, 1])) {
return null;
}
/** @var Arg $firstArg */
$firstArg = $funcCall->args[0];
$haystack = $firstArg->value;
/** @var Arg $secondArg */
$secondArg = $funcCall->args[1];
$needle = $secondArg->value;
2022-06-06 16:43:29 +00:00
return new StrStartsWith($funcCall, $haystack, $needle, $isPositive);
}
}