Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
68.42% |
26 / 38 |
|
90.91% |
10 / 11 |
CRAP | |
0.00% |
0 / 1 |
Fun1 | |
68.42% |
26 / 38 |
|
90.91% |
10 / 11 |
26.10 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
4 / 4 |
|
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 | |||
createMover | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
extractIdentifiers | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
5 | |||
extractSubscripts | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getModIdent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getSubs | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace MediaWiki\Extension\Math\WikiTexVC\Nodes; |
6 | |
7 | use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmo; |
8 | use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmover; |
9 | use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmrow; |
10 | use MediaWiki\Extension\Math\WikiTexVC\TexUtil; |
11 | |
12 | class Fun1 extends TexNode { |
13 | |
14 | /** @var string */ |
15 | protected $fname; |
16 | /** @var TexNode */ |
17 | protected $arg; |
18 | /** @var TexUtil */ |
19 | private $tu; |
20 | |
21 | public function __construct( string $fname, TexNode $arg ) { |
22 | parent::__construct( $fname, $arg ); |
23 | $this->fname = $fname; |
24 | $this->arg = $arg; |
25 | $this->tu = TexUtil::getInstance(); |
26 | } |
27 | |
28 | /** |
29 | * @return string |
30 | */ |
31 | public function getFname(): string { |
32 | return $this->fname; |
33 | } |
34 | |
35 | /** |
36 | * @return TexNode |
37 | */ |
38 | public function getArg(): TexNode { |
39 | return $this->arg; |
40 | } |
41 | |
42 | public function inCurlies() { |
43 | return $this->render(); |
44 | } |
45 | |
46 | public function render() { |
47 | return '{' . $this->fname . ' ' . $this->arg->inCurlies() . '}'; |
48 | } |
49 | |
50 | public function renderMML( $arguments = [], $state = [] ) { |
51 | return $this->parseToMML( $this->fname, $arguments, null ); |
52 | } |
53 | |
54 | public function createMover( $inner, $moArgs = [] ): string { |
55 | $mrow = new MMLmrow(); |
56 | $mo = new MMLmo( "", $moArgs ); |
57 | $mover = new MMLmover(); |
58 | $ret = $mrow->encapsulateRaw( |
59 | $mrow->encapsulateRaw( |
60 | $mover->encapsulateRaw( |
61 | $this->args[1]->renderMML() . |
62 | $mo->encapsulateRaw( $inner ) |
63 | ) |
64 | ) |
65 | ); |
66 | return $ret; |
67 | } |
68 | |
69 | public function extractIdentifiers( $args = null ) { |
70 | if ( $args == null ) { |
71 | $args = [ $this->arg ]; |
72 | } |
73 | $letterMods = array_keys( $this->tu->getBaseElements()['is_letter_mod'] ); |
74 | if ( in_array( $this->fname, $letterMods, true ) ) { |
75 | $ident = $this->arg->getModIdent(); |
76 | if ( !isset( $ident[0] ) ) { |
77 | return parent::extractIdentifiers( $args ); |
78 | } |
79 | // in difference to javascript code: taking first element of array here. |
80 | return [ $this->fname . '{' . $ident[0] . '}' ]; |
81 | |
82 | } elseif ( array_key_exists( $this->fname, $this->tu->getBaseElements()['ignore_identifier'] ) ) { |
83 | return []; |
84 | } |
85 | |
86 | return parent::extractIdentifiers( $args ); |
87 | } |
88 | |
89 | public function extractSubscripts() { |
90 | return $this->getSubs( $this->arg->extractSubscripts() ); |
91 | } |
92 | |
93 | public function getModIdent() { |
94 | return $this->getSubs( $this->arg->getModIdent() ); |
95 | } |
96 | |
97 | private function getSubs( $subs ) { |
98 | $letterMods = array_keys( $this->tu->getBaseElements()['is_letter_mod'] ); |
99 | |
100 | if ( isset( $subs[0] ) && in_array( $this->fname, $letterMods, true ) ) { |
101 | // in difference to javascript code: taking first element of array here. |
102 | return [ $this->fname . '{' . $subs[0] . '}' ]; |
103 | } |
104 | return []; |
105 | } |
106 | |
107 | } |