Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
1 / 1
MMLbase
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
7 / 7
8
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 name
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 encapsulateRaw
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 encapsulate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStart
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getEmpty
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getEnd
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace MediaWiki\Extension\Math\WikiTexVC\MMLnodes;
3
4use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\TexConstants\Tag;
5use MediaWiki\Html\Html;
6
7class MMLbase {
8    private string $name;
9    private array $attributes;
10
11    public function __construct( string $name, string $texclass = '', array $attributes = [] ) {
12        $this->name = $name;
13        $this->attributes = $attributes;
14        if ( $texclass !== '' ) {
15            $this->attributes[ TAG::CLASSTAG ] = $texclass;
16        }
17    }
18
19    public function name(): string {
20        return $this->name;
21    }
22
23    /**
24     * Encapsulating the input structure with start and end element
25     *
26     * @param string $input The raw HTML contents of the element: *not* escaped!
27     * @return string <tag> input </tag>
28     */
29    public function encapsulateRaw( string $input ): string {
30        return HTML::rawElement( $this->name, $this->attributes, $input );
31    }
32
33    /**
34     * Encapsulating the input with start and end element
35     *
36     * @param string $input
37     * @return string <tag> input </tag>
38     */
39    public function encapsulate( string $input = '' ): string {
40        return HTML::element( $this->name, $this->attributes, $input );
41    }
42
43    /**
44     * Getting the start element
45     * @return string
46     */
47    public function getStart(): string {
48        return HTML::openElement( $this->name, $this->attributes );
49    }
50
51    /**
52     * Gets an empty element with the specified name.
53     * Example: "<mrow/>"
54     * @return string
55     */
56    public function getEmpty(): string {
57        return substr( $this->getStart(), 0, -1 )
58            . '/>';
59    }
60
61    /**
62     * Getting the end element
63     * @return string
64     */
65    public function getEnd(): string {
66        return HTML::closeElement( $this->name );
67    }
68}