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    public function render() {
41        return $this->base->render() . '^' . $this->up->inCurlies();
42    }
43
44    public function renderMML( $arguments = [], $state = [] ) {
45        $mrow = new MMLmrow();
46        $mmlBase = new MMLmsup();
47        $base = $this->getBase();
48        $up = $this->getUp();
49
50        $tu = TexUtil::getInstance();
51
52        if ( $base instanceof Fun1 && $tu->over_operator( $base->getFname() ) ) {
53            $mmlBase = new MMLmover();
54        }
55
56        // If the superscript has empty elements, render them with empty mi elements to prevent browser issues
57        $mi = new MMLmi();
58        if ( $base instanceof TexArray && $base->getLength() == 0 ) {
59            $baseRendered = $mi->getEmpty();
60        } else {
61            $baseRendered = $base->renderMML( $arguments, $state );
62        }
63        if ( $up instanceof TexArray && $up->getLength() == 0 ) {
64            $upRendered = $mi->getEmpty();
65        } else {
66            // up is inferring a new mrow if it has some content
67            $upRendered = $mrow->encapsulateRaw( $up->renderMML( $arguments, $state ) );
68        }
69
70        return $mmlBase->encapsulateRaw( $baseRendered . $upRendered );
71    }
72
73}