Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.48% covered (success)
90.48%
19 / 21
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
UQ
90.48% covered (success)
90.48%
19 / 21
80.00% covered (warning)
80.00%
4 / 5
11.10
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getBase
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUp
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 render
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 renderMML
86.67% covered (warning)
86.67%
13 / 15
0.00% covered (danger)
0.00%
0 / 1
7.12
1<?php
2
3declare( strict_types = 1 );
4
5namespace MediaWiki\Extension\Math\WikiTexVC\Nodes;
6
7use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmi;
8use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmover;
9use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmrow;
10use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmsup;
11use MediaWiki\Extension\Math\WikiTexVC\TexUtil;
12
13class UQ extends TexNode {
14
15    /** @var TexNode */
16    private $base;
17    /** @var TexNode */
18    private $up;
19
20    public function __construct( TexNode $base, TexNode $up ) {
21        parent::__construct( $base, $up );
22        $this->base = $base;
23        $this->up = $up;
24    }
25
26    /**
27     * @return TexNode
28     */
29    public function getBase(): TexNode {
30        return $this->base;
31    }
32
33    /**
34     * @return TexNode
35     */
36    public function getUp(): TexNode {
37        return $this->up;
38    }
39
40    /** @inheritDoc */
41    public function render() {
42        return $this->base->render() . '^' . $this->up->inCurlies();
43    }
44
45    /** @inheritDoc */
46    public function renderMML( $arguments = [], &$state = [] ) {
47        $mrow = new MMLmrow();
48        $mmlBase = new MMLmsup();
49        $base = $this->getBase();
50        $up = $this->getUp();
51
52        $tu = TexUtil::getInstance();
53
54        if ( $base instanceof Fun1 && $tu->over_operator( $base->getFname() ) ) {
55            $mmlBase = new MMLmover();
56        }
57
58        // If the superscript has empty elements, render them with empty mi elements to prevent browser issues
59        $mi = new MMLmi();
60        if ( $base instanceof TexArray && $base->getLength() == 0 ) {
61            $baseRendered = $mi->getEmpty();
62        } else {
63            $baseRendered = $base->renderMML( $arguments, $state );
64        }
65        if ( $up instanceof TexArray && $up->getLength() == 0 ) {
66            $upRendered = $mi->getEmpty();
67        } else {
68            // up is inferring a new mrow if it has some content
69            $upRendered = $mrow->encapsulateRaw( $up->renderMML( $arguments, $state ) );
70        }
71
72        return $mmlBase->encapsulateRaw( $baseRendered . $upRendered );
73    }
74
75}