Skip to content

Commit eaebe39

Browse files
Firehedclaude
andcommitted
Add GMP unary operator type specifying extension
Implements UnaryOperatorTypeSpecifyingExtension for GMP to handle unary minus (-), unary plus (+), and bitwise NOT (~) operators. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent eb85b95 commit eaebe39

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Type\Php;
4+
5+
use PHPStan\DependencyInjection\AutowiredService;
6+
use PHPStan\Type\NeverType;
7+
use PHPStan\Type\ObjectType;
8+
use PHPStan\Type\Type;
9+
use PHPStan\Type\UnaryOperatorTypeSpecifyingExtension;
10+
use function in_array;
11+
12+
#[AutowiredService]
13+
final class GmpUnaryOperatorTypeSpecifyingExtension implements UnaryOperatorTypeSpecifyingExtension
14+
{
15+
16+
public function isOperatorSupported(string $operatorSigil, Type $operand): bool
17+
{
18+
if ($operand instanceof NeverType) {
19+
return false;
20+
}
21+
22+
if (!in_array($operatorSigil, ['-', '+', '~'], true)) {
23+
return false;
24+
}
25+
26+
$gmpType = new ObjectType('GMP');
27+
return $gmpType->isSuperTypeOf($operand)->yes();
28+
}
29+
30+
public function specifyType(string $operatorSigil, Type $operand): Type
31+
{
32+
return new ObjectType('GMP');
33+
}
34+
35+
}

0 commit comments

Comments
 (0)