Skip to content

Commit

Permalink
Do not decrement min integer value (#1488)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidz committed Feb 22, 2021
1 parent ea85f1f commit c0ae499
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Mutator/Number/DecrementInteger.php
Expand Up @@ -40,6 +40,7 @@
use Infection\Mutator\GetMutatorName;
use Infection\Mutator\MutatorCategory;
use Infection\PhpParser\Visitor\ParentConnector;
use const PHP_INT_MIN;
use PhpParser\Node;

/**
Expand Down Expand Up @@ -97,6 +98,10 @@ public function canMutate(Node $node): bool
return false;
}

if ($node->value === PHP_INT_MIN) {
return false;
}

if (
$node->value === 1
&& ($this->isPartOfComparison($node) || ParentConnector::getParent($node) instanceof Node\Expr\Assign)
Expand Down
10 changes: 10 additions & 0 deletions tests/phpunit/Mutator/Number/DecrementIntegerTest.php
Expand Up @@ -504,6 +504,16 @@ public function mutationsProvider(): iterable
<?php
preg_split('//', 'string', -2);
PHP
];

yield 'It does not decrement min int' => [
<<<'PHP'
<?php
if ($a === -9223372036854775808) {
echo 'bar';
}
PHP
];
}
Expand Down

0 comments on commit c0ae499

Please sign in to comment.