Skip to content

Commit e4c8eca

Browse files
committed
Add operand validation
1 parent f2485ee commit e4c8eca

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Compiler/Builder/Generator/Operation/Operand.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,31 @@
22
declare(strict_types=1);
33
namespace PHPJava\Compiler\Builder\Generator\Operation;
44

5+
use PHPJava\Compiler\Builder\Finder\Result\ConstantPoolFinderResult;
6+
use PHPJava\Compiler\Builder\Types\Uint16;
7+
use PHPJava\Compiler\Builder\Types\Uint32;
8+
use PHPJava\Compiler\Builder\Types\Uint8;
9+
use PHPJava\Exceptions\AssembleStructureException;
10+
511
class Operand
612
{
713
protected $type;
814
protected $value;
915

1016
public static function factory(string $type, $value): self
1117
{
18+
if (!in_array($type, [Uint8::class, Uint16::class, Uint32::class], true)) {
19+
throw new AssembleStructureException(
20+
'Invalid class type: ' . $type
21+
);
22+
}
23+
if (!($value instanceof ConstantPoolFinderResult)
24+
&& !is_int($value)
25+
) {
26+
throw new AssembleStructureException(
27+
'Passed parameter is not initiated a ConstantPoolFinderResult'
28+
);
29+
}
1230
$scopedValue = $value;
1331
return new static($type, $scopedValue);
1432
}

0 commit comments

Comments
 (0)