Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
42.22% covered (danger)
42.22%
19 / 45
50.00% covered (danger)
50.00%
4 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
DQ
42.22% covered (danger)
42.22%
19 / 45
50.00% covered (danger)
50.00%
4 / 8
156.39
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
 getDown
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
81.25% covered (warning)
81.25%
13 / 16
0.00% covered (danger)
0.00%
0 / 1
6.24
 extractIdentifiers
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
72
 extractSubscripts
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 getModIdent
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2
3declare( strict_types = 1 );
4
5namespace MediaWiki\Extension\Math\WikiTexVC\Nodes;
6
7use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\BaseParsing;
8use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmrow;
9use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmsub;
10use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmunder;
11
12class DQ extends TexNode {
13    /** @var TexNode */
14    private $base;
15    /** @var TexNode */
16    private $down;
17
18    public function __construct( TexNode $base, TexNode $down ) {
19        parent::__construct( $base, $down );
20        $this->base = $base;
21        $this->down = $down;
22    }
23
24    /**
25     * @return TexNode
26     */
27    public function getBase(): TexNode {
28        return $this->base;
29    }
30
31    /**
32     * @return TexNode
33     */
34    public function getDown(): TexNode {
35        return $this->down;
36    }
37
38    public function render() {
39        return $this->base->render() . '_' . $this->down->inCurlies();
40    }
41
42    public function renderMML( $arguments = [], $state = [] ) {
43        if ( array_key_exists( "limits", $state ) ) {
44            // A specific DQ case with preceding limits, just invoke the limits parsing manually.
45            return BaseParsing::limits( $this, $arguments, $state, "" );
46        }
47
48        $emptyMrow = "";
49        // In cases with empty curly preceding like: "{}_pF_q"
50        if ( $this->getBase() instanceof Curly && $this->getBase()->isEmpty() ) {
51            $mrow = new MMLmrow();
52            $emptyMrow = $mrow->getEmpty();
53        }
54
55        if ( !$this->isEmpty() ) {
56            if ( $this->getBase()->containsFunc( "\underbrace" ) ) {
57                $outer = new MMLmunder();
58            } else {
59                $outer = new MMLmsub();
60            }
61            // Otherwise use default fallback
62            $mmlMrow = new MMLmrow();
63            return $outer->encapsulateRaw(
64                 $emptyMrow .
65                $this->base->renderMML( $arguments, [ 'styleargs' => $state['styleargs'] ?? [] ] ) .
66                $mmlMrow->encapsulateRaw( $this->down->renderMML( $arguments, $state ) ) );
67        }
68
69        return "";
70    }
71
72    public function extractIdentifiers( $args = null ) {
73        $d = $this->down->extractSubscripts();
74        $b = $this->base->extractIdentifiers();
75        if ( is_array( $b ) && count( $b ) > 1 ) {
76            return parent::extractIdentifiers();
77        }
78
79        if ( isset( $b[0] ) && $b[0] === '\'' ) {
80            return array_merge( $b, $d );
81        }
82
83        if ( isset( $d[0] ) && isset( $b[0] ) ) {
84            if ( $b[0] === '\\int' ) {
85                return array_merge( $b, $d );
86            }
87            return [ $b[0] . '_{' . $d[0] . '}' ];
88        }
89
90        return parent::extractIdentifiers();
91    }
92
93    public function extractSubscripts() {
94        $d = array_merge( [], $this->down->extractSubscripts() );
95        $b = $this->base->extractSubscripts();
96        if ( isset( $b[0] ) && isset( $d[0] ) ) {
97            return [ $b[0] . '_{' . implode( '', $d ) . '}' ];
98        }
99        return parent::extractSubscripts();
100    }
101
102    public function getModIdent() {
103        $d = $this->down->extractSubscripts();
104        $b = $this->base->getModIdent();
105        if ( isset( $b[0] ) && $b[0] === '\'' ) {
106            return [];
107        }
108        if ( isset( $d[0] ) && isset( $b[0] ) ) {
109            return [ $b[0] . '_{' . $d[0] . '}' ];
110        }
111
112        return parent::getModIdent();
113    }
114
115}