2021-02-28 13:53:28 +01:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2021-02-28 13:53:28 +01:00
|
|
|
namespace Rector\Php80\ValueObjectFactory;
|
|
|
|
|
2021-09-27 15:43:15 +00:00
|
|
|
use PhpParser\Node\Arg;
|
2021-02-28 13:53:28 +01:00
|
|
|
use PhpParser\Node\Expr\FuncCall;
|
2021-09-27 15:43:15 +00:00
|
|
|
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
|
2021-02-28 13:53:28 +01:00
|
|
|
use Rector\Php80\ValueObject\StrStartsWith;
|
|
|
|
final class StrStartsWithFactory
|
|
|
|
{
|
2021-09-27 15:43:15 +00:00
|
|
|
/**
|
|
|
|
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
|
|
|
|
*/
|
|
|
|
private $argsAnalyzer;
|
|
|
|
public function __construct(\Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
|
2021-02-28 13:53:28 +01:00
|
|
|
{
|
2021-09-27 15:43:15 +00:00
|
|
|
$this->argsAnalyzer = $argsAnalyzer;
|
|
|
|
}
|
|
|
|
public function createFromFuncCall(\PhpParser\Node\Expr\FuncCall $funcCall, bool $isPositive) : ?\Rector\Php80\ValueObject\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;
|
2021-05-10 22:23:08 +00:00
|
|
|
return new \Rector\Php80\ValueObject\StrStartsWith($funcCall, $haystack, $needle, $isPositive);
|
2021-02-28 13:53:28 +01:00
|
|
|
}
|
|
|
|
}
|