Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
LengthSpec | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
render | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Math\WikiTexVC\Nodes; |
4 | |
5 | use InvalidArgumentException; |
6 | |
7 | class LengthSpec extends TexNode { |
8 | private string $sign; |
9 | private string $unit; |
10 | private string $number; |
11 | |
12 | public function __construct( ?string $sign, array $number, string $unit ) { |
13 | $this->sign = $sign ?? ''; |
14 | $this->unit = $unit; |
15 | if ( count( $number ) === 3 ) { |
16 | |
17 | $this->number = implode( $number[0] ) . ( $number[1] ?? '' ) . implode( $number[2] ); |
18 | } elseif ( count( $number ) === 2 ) { |
19 | $this->number = ( $number[0] ?? '' ) . implode( $number[1] ); |
20 | } else { |
21 | throw new InvalidArgumentException( 'Invalid number in length spec' ); |
22 | } |
23 | parent::__construct(); |
24 | } |
25 | |
26 | public function render() { |
27 | return '[' . $this->sign . $this->number . $this->unit . ']'; |
28 | } |
29 | |
30 | } |