Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
30 / 30 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
Declh | |
100.00% |
30 / 30 |
|
100.00% |
8 / 8 |
15 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getFname | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getArg | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
inCurlies | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
render | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
renderMML | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
extractIdentifiers | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
extractSubscripts | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
6 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace MediaWiki\Extension\Math\WikiTexVC\Nodes; |
6 | |
7 | class Declh extends TexNode { |
8 | |
9 | /** @var string */ |
10 | private $fname; |
11 | /** @var TexArray */ |
12 | private $arg; |
13 | |
14 | public function __construct( string $fname, TexArray $arg ) { |
15 | parent::__construct( $fname, $arg ); |
16 | $this->fname = $fname; |
17 | $this->arg = $arg; |
18 | } |
19 | |
20 | /** |
21 | * @return string |
22 | */ |
23 | public function getFname(): string { |
24 | return $this->fname; |
25 | } |
26 | |
27 | /** |
28 | * @return TexArray |
29 | */ |
30 | public function getArg(): TexArray { |
31 | return $this->arg; |
32 | } |
33 | |
34 | public function inCurlies() { |
35 | return $this->render(); |
36 | } |
37 | |
38 | public function render() { |
39 | return '{' . $this->fname . ' ' . $this->arg->inCurlies() . '}'; |
40 | } |
41 | |
42 | public function renderMML( $arguments = [], $state = [] ) { |
43 | return $this->parseToMML( $this->fname, $arguments, null ); |
44 | } |
45 | |
46 | public function extractIdentifiers( $args = null ) { |
47 | if ( $args == null ) { |
48 | $args = [ $this->arg ]; |
49 | } |
50 | |
51 | $identifier = parent::extractIdentifiers( $args ); |
52 | if ( isset( $identifier[0] ) ) { |
53 | return [ implode( '', $identifier ) ]; |
54 | } |
55 | return $identifier; |
56 | } |
57 | |
58 | public function extractSubscripts() { |
59 | $f = $this->fname; |
60 | // @see |
61 | // http://tex.stackexchange.com/questions/98406/which-command-should-i-use-for-textual-subscripts-in-math-mode |
62 | // cf https://phabricator.wikimedia.org/T56818 a is always RM |
63 | // for f there are only four cases |
64 | switch ( $f ) { |
65 | case '\\rm': |
66 | $f = '\\mathrm'; |
67 | break; |
68 | case '\\it': |
69 | $f = '\\mathit'; |
70 | break; |
71 | case '\\cal': |
72 | $f = '\\mathcal'; |
73 | break; |
74 | case '\\bf': |
75 | $f = '\\mathbf'; |
76 | } |
77 | |
78 | $x = $this->arg->extractSubscripts(); |
79 | if ( isset( $x[0] ) ) { |
80 | return [ $f . '{' . $x . '}' ]; |
81 | } |
82 | return parent::extractSubscripts(); |
83 | } |
84 | |
85 | } |