11<?php
22namespace PHPJava \Kernel \Mnemonics ;
33
4+ use PHPJava \Exceptions \OperationException ;
5+
46final class Operands implements \ArrayAccess
57{
68 private $ operands = [];
79
8- public function __construct (array $ operands = [] )
10+ public function __construct (... $ operands )
911 {
10- $ this ->operands = $ operands ;
12+ foreach ($ operands as [$ alias , $ value , $ operandNames ]) {
13+ $ this ->operands [$ alias ] = [$ value , $ operandNames ];
14+ }
1115 }
1216
1317 public function count ()
1418 {
15- return count ($ this ->operands );
19+ return count ($ this ->getInfo ());
20+ }
21+
22+ public function getInfo (): array
23+ {
24+ $ operands = [];
25+ foreach ($ this ->operands as [, $ operandParameters ]) {
26+ array_push ($ operands , ...$ operandParameters );
27+ }
28+ return $ operands ;
29+ }
30+
31+ public function getElements (): array
32+ {
33+ return $ this ->operands ;
1634 }
1735
1836 public function offsetExists ($ offset )
@@ -22,17 +40,16 @@ public function offsetExists($offset)
2240
2341 public function offsetGet ($ offset )
2442 {
25- return $ this ->operands [$ offset ];
43+ return $ this ->operands [$ offset ][ 0 ] ;
2644 }
2745
2846 public function offsetSet ($ offset , $ value )
2947 {
30- $ this -> operands [ $ offset ] = $ value ;
48+ throw new OperationException ( ' Operands class is not supported overwrite. ' ) ;
3149 }
3250
3351 public function offsetUnset ($ offset )
3452 {
35- unset($ this ->operands [$ offset ]);
36- $ this ->operands = array_values ($ this ->operands );
53+ throw new OperationException ('Operands class is not supported unset an element. ' );
3754 }
3855}
0 commit comments