Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Analyser/TypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,20 @@
)->setRootExpr($rootExpr));
}

if (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. Should the same be done with $context->false() && $constantType->toBoolean()->isFalse()->yes() ?

  2. Why only $exprNode instanceof FuncCall || $exprNode instanceof Expr\MethodCall || $exprNode instanceof Expr\StaticCall ? Shouldn't this be for every $exprNode ? Or at least NullsafeMethodCall (and so) too ?

I wonder if changing the two previous $constantType into $constantType->toBoolean doesnt give the same result...

$context->true()

Check warning on line 1552 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrueTruthyFalseFalseyTypeSpecifierContextMutator": @@ @@ } if ( - $context->true() + $context->truthy() && $constantType->toBoolean()->isTrue()->yes() && ($exprNode instanceof FuncCall || $exprNode instanceof Expr\MethodCall || $exprNode instanceof Expr\StaticCall) ) {

Check warning on line 1552 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrueTruthyFalseFalseyTypeSpecifierContextMutator": @@ @@ } if ( - $context->true() + $context->truthy() && $constantType->toBoolean()->isTrue()->yes() && ($exprNode instanceof FuncCall || $exprNode instanceof Expr\MethodCall || $exprNode instanceof Expr\StaticCall) ) {
&& $constantType->toBoolean()->isTrue()->yes()

Check warning on line 1553 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ( $context->true() - && $constantType->toBoolean()->isTrue()->yes() + && !$constantType->toBoolean()->isTrue()->no() && ($exprNode instanceof FuncCall || $exprNode instanceof Expr\MethodCall || $exprNode instanceof Expr\StaticCall) ) { $types = $this->create($exprNode, $constantType, $context, $scope)->setRootExpr($rootExpr);

Check warning on line 1553 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ( $context->true() - && $constantType->toBoolean()->isTrue()->yes() + && !$constantType->toBoolean()->isTrue()->no() && ($exprNode instanceof FuncCall || $exprNode instanceof Expr\MethodCall || $exprNode instanceof Expr\StaticCall) ) { $types = $this->create($exprNode, $constantType, $context, $scope)->setRootExpr($rootExpr);
&& ($exprNode instanceof FuncCall || $exprNode instanceof Expr\MethodCall || $exprNode instanceof Expr\StaticCall)
) {
$types = $this->create($exprNode, $constantType, $context, $scope)->setRootExpr($rootExpr);

return $types->unionWith($this->specifyTypesInCondition(
$scope,
$exprNode,
TypeSpecifierContext::createTrue(),
)->setRootExpr($rootExpr));
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,72 @@ public function variants(string $s) {

if (strpos($s, ':') !== false) {
assertType('non-falsy-string', $s);
} else {
assertType('string', $s);
}
assertType('string', $s);
if (strpos($s, ':') === false) {
assertType('string', $s);
} else {
assertType('non-falsy-string', $s);
}
assertType('string', $s);

if (strpos($s, ':') === 5) {
if (strpos($s, '0') == 0) { // 0|false
assertType('string', $s);
} else {
assertType('string', $s);
}
assertType('string', $s);

$oneOrZero = rand(0, 1);
if (strpos($s, '0') == $oneOrZero) { // 0|1|false
assertType('string', $s);
} else {
assertType('string', $s);
}
assertType('string', $s);

$oneOrZero = rand(0, 1);
if (strpos($s, '0') === $oneOrZero) {
assertType('string', $s); // could be non-empty-string
} else {
assertType('string', $s);
}
assertType('string', $s);

if (strpos($s, '0') == 1) {
assertType('string', $s); // could be non-empty-string
} else {
assertType('string', $s);
}
assertType('string', $s);

if (strpos($s, '0') === 0) {
assertType('string', $s); // could be non-empty-string
} else {
assertType('string', $s);
}
assertType('string', $s);

if (strpos($s, '0') === 5) {
assertType('non-empty-string', $s); // could be non-falsy-string
} else {
assertType('string', $s);
}
assertType('string', $s);

if (strpos($s, ':') === 5) {
assertType('non-falsy-string', $s);
} else {
assertType('string', $s);
}
assertType('string', $s);

if (strpos($s, ':') !== 5) {
assertType('string', $s);
} else {
assertType('non-falsy-string', $s);
}
assertType('string', $s);

Expand Down Expand Up @@ -152,7 +205,7 @@ public function variants(string $s) {
assertType('string', $s);

if (mb_strpos($s, ':') === 5) {
assertType('string', $s); // could be non-empty-string
assertType('non-falsy-string', $s);
}
assertType('string', $s);
if (mb_strpos($s, ':') !== 5) {
Expand Down
Loading