Skip to content

Commit

Permalink
add check on VariadicPlaceholder
Browse files Browse the repository at this point in the history
  • Loading branch information
sidz committed Sep 30, 2021
1 parent 2305824 commit e240bca
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/Mutator/Extensions/BCMath.php
Expand Up @@ -217,6 +217,10 @@ private static function makeCastToStringMapper(Closure $converter): Closure
private static function makeBinaryOperatorMapper(string $operator): Closure
{
return static function (Node\Expr\FuncCall $node) use ($operator): iterable {
if ($node->args[0] instanceof Node\VariadicPlaceholder || $node->args[1] instanceof Node\VariadicPlaceholder) {
return [];
}

yield new $operator($node->args[0]->value, $node->args[1]->value);
};
}
Expand All @@ -237,6 +241,10 @@ private static function makeSquareRootsMapper(): Closure
private static function makePowerModuloMapper(): Closure
{
return static function (Node\Expr\FuncCall $node): iterable {
if ($node->args[2] instanceof Node\VariadicPlaceholder) {
return [];
}

yield new Node\Expr\BinaryOp\Mod(
new Node\Expr\FuncCall(
new Node\Name('\pow'),
Expand Down
6 changes: 5 additions & 1 deletion src/Mutator/Extensions/MBString.php
Expand Up @@ -202,6 +202,10 @@ private static function getConvertCaseModeValue(Node\Expr\FuncCall $node): ?int
return null;
}

if ($node->args[1] instanceof Node\VariadicPlaceholder) {
return null;
}

$mode = $node->args[1]->value;

if ($mode instanceof Node\Scalar\LNumber) {
Expand Down Expand Up @@ -244,7 +248,7 @@ private static function isInMbCaseMode(int $mode, string ...$cases): bool
}

/**
* @param Node\Arg[] $args
* @param array<Node\Arg|Node\VariadicPlaceholder> $args
*/
private static function mapFunctionCall(Node\Expr\FuncCall $node, string $newFuncName, array $args): Node\Expr\FuncCall
{
Expand Down
13 changes: 8 additions & 5 deletions src/Mutator/Regex/AbstractPregMatch.php
Expand Up @@ -60,14 +60,16 @@ abstract class AbstractPregMatch implements Mutator
*/
public function mutate(Node $node): iterable
{
$arguments = $node->args;
$firstArgument = $arguments[0];
$originalRegex = $this->pullOutRegex($firstArgument);
if ($node->args[0] instanceof Node\VariadicPlaceholder) {
return [];
}

$originalRegex = $this->pullOutRegex($node->args[0]);

foreach ($this->mutateRegex($originalRegex) as $mutatedRegex) {
$newArgument = $this->getNewRegexArgument($mutatedRegex, $firstArgument);
$newArgument = $this->getNewRegexArgument($mutatedRegex, $node->args[0]);

yield new FuncCall($node->name, [$newArgument] + $arguments, $node->getAttributes());
yield new FuncCall($node->name, [$newArgument] + $node->args, $node->getAttributes());
}
}

Expand All @@ -76,6 +78,7 @@ public function canMutate(Node $node): bool
return $node instanceof FuncCall
&& $node->name instanceof Node\Name
&& strtolower((string) $node->name) === 'preg_match'
&& $node->args[0] instanceof Node\Arg
&& $node->args[0]->value instanceof Node\Scalar\String_
&& $this->isProperRegexToMutate($this->pullOutRegex($node->args[0]));
}
Expand Down
4 changes: 4 additions & 0 deletions src/Mutator/Regex/PregMatchMatches.php
Expand Up @@ -89,6 +89,10 @@ public static function getDefinition(): ?Definition
*/
public function mutate(Node $node): iterable
{
if ($node->args[2] instanceof Node\VariadicPlaceholder) {
return [];
}

yield new Node\Expr\Cast\Int_(new Node\Expr\Assign($node->args[2]->value, new Node\Expr\Array_()));
}

Expand Down
4 changes: 4 additions & 0 deletions src/Mutator/Regex/PregQuote.php
Expand Up @@ -84,6 +84,10 @@ public static function getDefinition(): ?Definition
*/
public function mutate(Node $node): iterable
{
if ($node->args[0] instanceof Node\VariadicPlaceholder) {
return [];
}

yield $node->args[0];
}

Expand Down
4 changes: 4 additions & 0 deletions src/Mutator/Unwrap/AbstractUnwrapMutator.php
Expand Up @@ -58,6 +58,10 @@ abstract class AbstractUnwrapMutator implements Mutator
final public function mutate(Node $node): iterable
{
foreach ($this->getParameterIndexes($node) as $index) {
if ($node->args[$index] instanceof Node\VariadicPlaceholder) {
continue;
}

if ($node->args[$index]->unpack) {
continue;
}
Expand Down

0 comments on commit e240bca

Please sign in to comment.