Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Type/Php/BcMathNumberOperatorTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
final class BcMathNumberOperatorTypeSpecifyingExtension implements OperatorTypeSpecifyingExtension
{

private ObjectType $mathNumberType;

public function __construct(private PhpVersion $phpVersion)
{
$this->mathNumberType = new ObjectType('BcMath\Number');
}

public function isOperatorSupported(string $operatorSigil, Type $leftSide, Type $rightSide): bool
Expand All @@ -27,19 +30,16 @@
return false;
}

$bcMathNumberType = new ObjectType('BcMath\Number');

return in_array($operatorSigil, ['-', '+', '*', '/', '**', '%', '<', '<=', '>', '>=', '==', '!=', '<=>'], true)
&& (
$bcMathNumberType->isSuperTypeOf($leftSide)->yes()
|| $bcMathNumberType->isSuperTypeOf($rightSide)->yes()
$this->mathNumberType->isSuperTypeOf($leftSide)->yes()
|| $this->mathNumberType->isSuperTypeOf($rightSide)->yes()
);
}

public function specifyType(string $operatorSigil, Type $leftSide, Type $rightSide): Type
{
$bcMathNumberType = new ObjectType('BcMath\Number');
$otherSide = $bcMathNumberType->isSuperTypeOf($leftSide)->yes()
$otherSide = $this->mathNumberType->isSuperTypeOf($leftSide)->yes()

Check warning on line 42 in src/Type/Php/BcMathNumberOperatorTypeSpecifyingExtension.php

View workflow job for this annotation

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

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ public function specifyType(string $operatorSigil, Type $leftSide, Type $rightSide): Type { - $otherSide = $this->mathNumberType->isSuperTypeOf($leftSide)->yes() + $otherSide = !$this->mathNumberType->isSuperTypeOf($leftSide)->no() ? $rightSide : $leftSide;

Check warning on line 42 in src/Type/Php/BcMathNumberOperatorTypeSpecifyingExtension.php

View workflow job for this annotation

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

Escaped Mutant for Mutator "PHPStan\Infection\IsSuperTypeOfCalleeAndArgumentMutator": @@ @@ public function specifyType(string $operatorSigil, Type $leftSide, Type $rightSide): Type { - $otherSide = $this->mathNumberType->isSuperTypeOf($leftSide)->yes() + $otherSide = $leftSide->isSuperTypeOf($this->mathNumberType)->yes() ? $rightSide : $leftSide;
? $rightSide
: $leftSide;

Expand All @@ -58,9 +58,9 @@
if (
$otherSide->isInteger()->yes()
|| $otherSide->isNumericString()->yes()
|| $bcMathNumberType->isSuperTypeOf($otherSide)->yes()
|| $this->mathNumberType->isSuperTypeOf($otherSide)->yes()
) {
return $bcMathNumberType;
return $this->mathNumberType;
}

return new ErrorType();
Expand Down
20 changes: 12 additions & 8 deletions src/Type/Php/GmpOperatorTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,29 @@
final class GmpOperatorTypeSpecifyingExtension implements OperatorTypeSpecifyingExtension
{

private ObjectType $gmpType;

public function __construct()
{
$this->gmpType = new ObjectType('GMP');
}

public function isOperatorSupported(string $operatorSigil, Type $leftSide, Type $rightSide): bool
{
if ($leftSide instanceof NeverType || $rightSide instanceof NeverType) {
return false;
}

$gmpType = new ObjectType('GMP');

return in_array($operatorSigil, ['+', '-', '*', '/', '**', '%', '&', '|', '^', '<<', '>>', '<', '<=', '>', '>=', '==', '!=', '<=>'], true)
&& (
$gmpType->isSuperTypeOf($leftSide)->yes()
|| $gmpType->isSuperTypeOf($rightSide)->yes()
$this->gmpType->isSuperTypeOf($leftSide)->yes()
|| $this->gmpType->isSuperTypeOf($rightSide)->yes()
);
}

public function specifyType(string $operatorSigil, Type $leftSide, Type $rightSide): Type
{
$gmpType = new ObjectType('GMP');
$otherSide = $gmpType->isSuperTypeOf($leftSide)->yes()
$otherSide = $this->gmpType->isSuperTypeOf($leftSide)->yes()
? $rightSide
: $leftSide;

Expand All @@ -51,9 +55,9 @@ public function specifyType(string $operatorSigil, Type $leftSide, Type $rightSi
if (
$otherSide->isInteger()->yes()
|| $otherSide->isNumericString()->yes()
|| $gmpType->isSuperTypeOf($otherSide)->yes()
|| $this->gmpType->isSuperTypeOf($otherSide)->yes()
) {
return $gmpType;
return $this->gmpType;
}

return new ErrorType();
Expand Down
12 changes: 9 additions & 3 deletions src/Type/Php/GmpUnaryOperatorTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
final class GmpUnaryOperatorTypeSpecifyingExtension implements UnaryOperatorTypeSpecifyingExtension
{

private ObjectType $gmpType;

public function __construct()
{
$this->gmpType = new ObjectType('GMP');
}

public function isOperatorSupported(string $operatorSigil, Type $operand): bool
{
if ($operand instanceof NeverType) {
Expand All @@ -23,13 +30,12 @@ public function isOperatorSupported(string $operatorSigil, Type $operand): bool
return false;
}

$gmpType = new ObjectType('GMP');
return $gmpType->isSuperTypeOf($operand)->yes();
return $this->gmpType->isSuperTypeOf($operand)->yes();
}

public function specifyType(string $operatorSigil, Type $operand): Type
{
return new ObjectType('GMP');
return $this->gmpType;
}

}
Loading