nodeNameResolver = $nodeNameResolver; $this->valueResolver = $valueResolver; $this->strStartsWithFuncCallFactory = $strStartsWithFuncCallFactory; } /** * @param Identical|NotIdentical $binaryOp */ public function match(\PhpParser\Node\Expr\BinaryOp $binaryOp) : ?\Rector\Php80\ValueObject\StrStartsWith { $isPositive = $binaryOp instanceof \PhpParser\Node\Expr\BinaryOp\Identical; if ($binaryOp->left instanceof \PhpParser\Node\Expr\FuncCall && $this->nodeNameResolver->isName($binaryOp->left, 'strpos')) { if (!$this->valueResolver->isValue($binaryOp->right, 0)) { return null; } /** @var FuncCall $funcCall */ $funcCall = $binaryOp->left; $haystack = $funcCall->args[0]->value; $needle = $funcCall->args[1]->value; return new \Rector\Php80\ValueObject\StrStartsWith($funcCall, $haystack, $needle, $isPositive); } if ($binaryOp->right instanceof \PhpParser\Node\Expr\FuncCall && $this->nodeNameResolver->isName($binaryOp->right, 'strpos')) { if (!$this->valueResolver->isValue($binaryOp->left, 0)) { return null; } /** @var FuncCall $funcCall */ $funcCall = $binaryOp->right; $haystack = $funcCall->args[0]->value; $needle = $funcCall->args[1]->value; return new \Rector\Php80\ValueObject\StrStartsWith($funcCall, $haystack, $needle, $isPositive); } return null; } /** * @return FuncCall|BooleanNot */ public function refactorStrStartsWith(\Rector\Php80\ValueObject\StrStartsWith $strStartsWith) : \PhpParser\Node { $strposFuncCall = $strStartsWith->getFuncCall(); $strposFuncCall->name = new \PhpParser\Node\Name('str_starts_with'); return $this->strStartsWithFuncCallFactory->createStrStartsWith($strStartsWith); } }