Debian Codegraph @

extensions/Math/src/WikiTexVC/Nodes/LengthSpec.php

raw symbols SCIP
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 /** @inheritDoc */
27 public function render() {
28 return '[' . $this->sign . $this->number . $this->unit . ']';
29 }
30
31 }