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 | private readonly MathRestbaseInterface $restbaseInterface; |
| 23 | |
| 24 | /** |
| 25 | * @param string $tex the TeX input string to be checked |
| 26 | * @param string $type |
| 27 | * @param MathRestbaseInterface|null &$ref |
| 28 | */ |
| 29 | public function __construct( $tex = '', $type = 'tex', &$ref = null ) { |
| 30 | parent::__construct( $tex ); |
| 31 | if ( $ref ) { |
| 32 | $this->restbaseInterface = $ref; |
| 33 | } else { |
| 34 | $this->restbaseInterface = new MathRestbaseInterface( $tex, $type ); |
| 35 | $ref = $this->restbaseInterface; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @return bool |
| 41 | */ |
| 42 | public function isValid() { |
| 43 | return $this->restbaseInterface->getSuccess(); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Some TeX checking programs may return |
| 48 | * a modified tex string after having checked it. |
| 49 | * You can get the altered tex string with this method |
| 50 | * @return ?string A valid Tex string |
| 51 | */ |
| 52 | public function getValidTex(): ?string { |
| 53 | return $this->restbaseInterface->getCheckedTex(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns the string of the last error. |
| 58 | */ |
| 59 | public function getError(): ?Message { |
| 60 | $err = $this->restbaseInterface->getError(); |
| 61 | if ( $err === null ) { |
| 62 | return null; |
| 63 | } |
| 64 | try { |
| 65 | $host = $this->restbaseInterface->getUrl( '' ); |
| 66 | } catch ( Exception ) { |
| 67 | $host = 'invalid'; |
| 68 | } |
| 69 | return $this->errorObjectToMessage( $err, $host ); |
| 70 | } |
| 71 | |
| 72 | public function getRbi(): MathRestbaseInterface { |
| 73 | return $this->restbaseInterface; |
| 74 | } |
| 75 | |
| 76 | } |