Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not decrement min integer value #1488

Merged
merged 1 commit into from Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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' => [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the increment case with PHP_INT_MAX?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<<<'PHP'
<?php

if ($a === -9223372036854775808) {
echo 'bar';
}
PHP
];
}
Expand Down