2021-09-27 15:43:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare (strict_types=1);
|
2022-06-06 17:12:56 +00:00
|
|
|
namespace Rector\Core\NodeAnalyzer;
|
2021-09-27 15:43:15 +00:00
|
|
|
|
2022-06-06 17:12:56 +00:00
|
|
|
use PhpParser\Node\Arg;
|
|
|
|
use PhpParser\Node\Identifier;
|
2021-09-27 15:43:15 +00:00
|
|
|
final class ArgsAnalyzer
|
|
|
|
{
|
|
|
|
/**
|
2023-05-13 17:20:02 +00:00
|
|
|
* @api
|
|
|
|
* @deprecated Use $node->getArgs()[x] instead
|
|
|
|
* @param Arg[] $args
|
2021-09-27 15:43:15 +00:00
|
|
|
*/
|
|
|
|
public function isArgInstanceInArgsPosition(array $args, int $position) : bool
|
|
|
|
{
|
2023-05-13 17:20:02 +00:00
|
|
|
return isset($args[$position]);
|
2021-09-27 15:43:15 +00:00
|
|
|
}
|
|
|
|
/**
|
2023-05-13 17:20:02 +00:00
|
|
|
* @api
|
|
|
|
* @param Arg[] $args
|
2021-09-27 15:43:15 +00:00
|
|
|
* @param int[] $positions
|
2023-05-13 17:20:02 +00:00
|
|
|
* @deprecated use count($node->getArgs() < X instead
|
2021-09-27 15:43:15 +00:00
|
|
|
*/
|
|
|
|
public function isArgsInstanceInArgsPositions(array $args, array $positions) : bool
|
|
|
|
{
|
|
|
|
foreach ($positions as $position) {
|
|
|
|
if (!isset($args[$position])) {
|
|
|
|
return \false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return \true;
|
|
|
|
}
|
2022-01-08 17:02:43 +00:00
|
|
|
/**
|
2022-01-09 13:31:36 +00:00
|
|
|
* @param mixed[]|Arg[] $args
|
2022-01-08 17:02:43 +00:00
|
|
|
*/
|
|
|
|
public function hasNamedArg(array $args) : bool
|
|
|
|
{
|
|
|
|
foreach ($args as $arg) {
|
2022-06-07 08:22:29 +00:00
|
|
|
if (!$arg instanceof Arg) {
|
2022-01-09 13:31:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-06-07 08:22:29 +00:00
|
|
|
if ($arg->name instanceof Identifier) {
|
2022-01-08 17:02:43 +00:00
|
|
|
return \true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return \false;
|
|
|
|
}
|
2021-09-27 15:43:15 +00:00
|
|
|
}
|