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