Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
30.77% |
12 / 39 |
|
70.00% |
7 / 10 |
CRAP | |
0.00% |
0 / 1 |
Lr | |
30.77% |
12 / 39 |
|
70.00% |
7 / 10 |
112.89 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
getLeft | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getRight | |
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 | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
20 | |||
mmlTranslate | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
containsFunc | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
extractIdentifiers | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace MediaWiki\Extension\Math\WikiTexVC\Nodes; |
6 | |
7 | use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\BaseMethods; |
8 | use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\TexConstants\TexClass; |
9 | use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmo; |
10 | use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmrow; |
11 | |
12 | class Lr extends TexNode { |
13 | |
14 | /** @var string */ |
15 | private $left; |
16 | /** @var string */ |
17 | private $right; |
18 | /** @var TexArray */ |
19 | private $arg; |
20 | |
21 | public function __construct( string $left, string $right, TexArray $arg ) { |
22 | parent::__construct( $left, $right, $arg ); |
23 | $this->left = $left; |
24 | $this->right = $right; |
25 | $this->arg = $arg; |
26 | } |
27 | |
28 | /** |
29 | * @return string |
30 | */ |
31 | public function getLeft(): string { |
32 | return $this->left; |
33 | } |
34 | |
35 | /** |
36 | * @return string |
37 | */ |
38 | public function getRight(): string { |
39 | return $this->right; |
40 | } |
41 | |
42 | /** |
43 | * @return TexArray |
44 | */ |
45 | public function getArg(): TexArray { |
46 | return $this->arg; |
47 | } |
48 | |
49 | public function inCurlies() { |
50 | return '{' . $this->render() . '}'; |
51 | } |
52 | |
53 | public function render() { |
54 | return '\\left' . $this->left . $this->arg->render() . '\\right' . $this->right; |
55 | } |
56 | |
57 | public function renderMML( $arguments = [], $state = [] ) { |
58 | // TBD set attributes for right AND left correctly |
59 | $rightAttrs = []; |
60 | if ( $this->right == "." ) { |
61 | $rightAttrs = [ "fence" => "true", "stretchy" => "true", "symmetric" => "true" ]; |
62 | } |
63 | |
64 | $bm = new BaseMethods(); |
65 | $left = $bm->checkAndParseDelimiter( $this->left, $this, [], null, true, |
66 | TexClass::OPEN ); |
67 | if ( !$left ) { |
68 | $moLeft = new MMLmo( TexClass::OPEN, [] ); |
69 | $left = $moLeft->encapsulateRaw( $this->right ); |
70 | } |
71 | $right = $bm->checkAndParseDelimiter( $this->right, $this, $rightAttrs, null, true, |
72 | TexClass::CLOSE ); |
73 | if ( !$right ) { |
74 | $moRight = new MMLmo( TexClass::CLOSE, $rightAttrs ); |
75 | $right = $moRight->encapsulateRaw( $this->right ); |
76 | } |
77 | |
78 | $inner = $this->getArg()->renderMML( [], $state ); |
79 | $mrow = new MMLmrow( TexClass::INNER ); |
80 | return $mrow->encapsulateRaw( |
81 | $left . $inner . |
82 | $right |
83 | ); |
84 | } |
85 | |
86 | private function mmlTranslate( $input ) { |
87 | switch ( trim( $input ) ) { |
88 | case "\\vert": |
89 | return "|"; |
90 | default: |
91 | return $input; |
92 | } |
93 | } |
94 | |
95 | public function containsFunc( $target, $args = null ) { |
96 | if ( $args == null ) { |
97 | $args = [ '\\left', '\\right', $this->arg ]; |
98 | } |
99 | return parent::containsFunc( $target, $args ); |
100 | } |
101 | |
102 | public function extractIdentifiers( $args = null ) { |
103 | if ( $args == null ) { |
104 | $args = [ $this->arg ]; |
105 | } |
106 | return parent::extractIdentifiers( $args ); |
107 | } |
108 | |
109 | } |