Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
73.33% |
11 / 15 |
|
40.00% |
2 / 5 |
CRAP | |
0.00% |
0 / 1 |
RestbaseChecker | |
73.33% |
11 / 15 |
|
40.00% |
2 / 5 |
9.21 | |
0.00% |
0 / 1 |
__construct | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
2.03 | |||
isValid | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getValidTex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getError | |
71.43% |
5 / 7 |
|
0.00% |
0 / 1 |
3.21 | |||
getRbi | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Math\InputCheck; |
4 | |
5 | use Exception; |
6 | use MediaWiki\Extension\Math\MathRestbaseInterface; |
7 | use MediaWiki\Message\Message; |
8 | |
9 | /** |
10 | * MediaWiki math extension |
11 | * |
12 | * @copyright 2002-2015 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz, |
13 | * and other MediaWiki contributors |
14 | * |
15 | * @note The restbase checker does not support purging the cache as it just represents |
16 | * the state of the restbase interface. |
17 | * |
18 | * @license GPL-2.0-or-later |
19 | * @author Moritz Schubotz |
20 | */ |
21 | class RestbaseChecker extends BaseChecker { |
22 | /** @var MathRestbaseInterface */ |
23 | private $restbaseInterface; |
24 | |
25 | /** |
26 | * @param string $tex the TeX input string to be checked |
27 | * @param string $type |
28 | * @param MathRestbaseInterface|null &$ref |
29 | */ |
30 | public function __construct( $tex = '', $type = 'tex', &$ref = null ) { |
31 | parent::__construct( $tex ); |
32 | if ( $ref ) { |
33 | $this->restbaseInterface = $ref; |
34 | } else { |
35 | $this->restbaseInterface = new MathRestbaseInterface( $tex, $type ); |
36 | $ref = $this->restbaseInterface; |
37 | } |
38 | } |
39 | |
40 | /** |
41 | * @return bool |
42 | */ |
43 | public function isValid() { |
44 | return $this->restbaseInterface->getSuccess(); |
45 | } |
46 | |
47 | /** |
48 | * Some TeX checking programs may return |
49 | * a modified tex string after having checked it. |
50 | * You can get the altered tex string with this method |
51 | * @return ?string A valid Tex string |
52 | */ |
53 | public function getValidTex(): ?string { |
54 | return $this->restbaseInterface->getCheckedTex(); |
55 | } |
56 | |
57 | /** |
58 | * Returns the string of the last error. |
59 | * @return ?Message |
60 | */ |
61 | public function getError(): ?Message { |
62 | $err = $this->restbaseInterface->getError(); |
63 | if ( $err === null ) { |
64 | return null; |
65 | } |
66 | try { |
67 | $host = $this->restbaseInterface->getUrl( '' ); |
68 | } catch ( Exception $ignore ) { |
69 | $host = 'invalid'; |
70 | } |
71 | return $this->errorObjectToMessage( $err, $host ); |
72 | } |
73 | |
74 | public function getRbi() { |
75 | return $this->restbaseInterface; |
76 | } |
77 | |
78 | } |