rector/rules/Php80/NodeFactory/StrStartsWithFuncCallFactory.php
Tomas Votruba 281d0518a0 Updated Rector to commit dce60231f7fe8777847a5f845572711999db650f
dce60231f7 [TypeDeclaration][Php 8] Enable ReturnTypeDeclarationRector (#184)
2021-06-18 17:31:16 +00:00

26 lines
869 B
PHP

<?php
declare (strict_types=1);
namespace Rector\Php80\NodeFactory;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use Rector\Php80\ValueObject\StrStartsWith;
final class StrStartsWithFuncCallFactory
{
/**
* @return \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\BooleanNot
*/
public function createStrStartsWith(\Rector\Php80\ValueObject\StrStartsWith $strStartsWith)
{
$args = [new \PhpParser\Node\Arg($strStartsWith->getHaystackExpr()), new \PhpParser\Node\Arg($strStartsWith->getNeedleExpr())];
$funcCall = new \PhpParser\Node\Expr\FuncCall(new \PhpParser\Node\Name('str_starts_with'), $args);
if ($strStartsWith->isPositive()) {
return $funcCall;
}
return new \PhpParser\Node\Expr\BooleanNot($funcCall);
}
}