Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
InputTextValidator | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
validateText | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Wikispeech; |
4 | |
5 | /** |
6 | * @file |
7 | * @ingroup Extensions |
8 | * @license GPL-2.0-or-later |
9 | */ |
10 | |
11 | use MediaWiki\MediaWikiServices; |
12 | use RuntimeException; |
13 | |
14 | class InputTextValidator { |
15 | |
16 | /** |
17 | * Validate input text. |
18 | * |
19 | * @since 0.1.11 |
20 | * @param string $text |
21 | * @throws RuntimeException |
22 | */ |
23 | public static function validateText( string $text ): void { |
24 | $numberOfCharactersInInput = mb_strlen( $text ); |
25 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
26 | $maximum = $config->get( 'WikispeechListenMaximumInputCharacters' ); |
27 | if ( $numberOfCharactersInInput > $maximum ) { |
28 | throw new RuntimeException( "Too long: $numberOfCharactersInInput > $maximum" ); |
29 | } |
30 | } |
31 | } |