| Total Complexity | 7 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | class Set extends Structure |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Constructor. |
||
| 17 | * |
||
| 18 | * @param Element ...$elements Any number of elements |
||
| 19 | */ |
||
| 20 | 12 | public function __construct(Element ...$elements) |
|
| 24 | 12 | } |
|
| 25 | |||
| 26 | /** |
||
| 27 | * Sort by canonical ascending order. |
||
| 28 | * |
||
| 29 | * Used for DER encoding of *SET* type. |
||
| 30 | */ |
||
| 31 | 3 | public function sortedSet(): self |
|
| 32 | { |
||
| 33 | 3 | $obj = clone $this; |
|
| 34 | 3 | usort($obj->_elements, |
|
| 35 | function (Element $a, Element $b) { |
||
| 36 | 3 | if ($a->typeClass() !== $b->typeClass()) { |
|
| 37 | 1 | return $a->typeClass() < $b->typeClass() ? -1 : 1; |
|
| 38 | } |
||
| 39 | 3 | if ($a->tag() === $b->tag()) { |
|
| 40 | 1 | return 0; |
|
| 41 | } |
||
| 42 | 2 | return $a->tag() < $b->tag() ? -1 : 1; |
|
| 43 | 3 | }); |
|
| 44 | 3 | return $obj; |
|
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Sort by encoding ascending order. |
||
| 49 | * |
||
| 50 | * Used for DER encoding of *SET OF* type. |
||
| 51 | */ |
||
| 52 | 1 | public function sortedSetOf(): self |
|
| 62 | } |
||
| 63 | } |
||
| 64 |