Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.31% |
12 / 13 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| YearRangeRule | |
92.31% |
12 / 13 |
|
50.00% |
1 / 2 |
5.01 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| createAlias | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
4.02 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Wikispeech\Segment\TextFilter\Sv; |
| 4 | |
| 5 | /** |
| 6 | * @file |
| 7 | * @ingroup Extensions |
| 8 | * @license GPL-2.0-or-later |
| 9 | */ |
| 10 | |
| 11 | use MediaWiki\Wikispeech\Segment\TextFilter\RegexFilterRule; |
| 12 | |
| 13 | /** |
| 14 | * @since 0.1.10 |
| 15 | */ |
| 16 | class YearRangeRule extends RegexFilterRule { |
| 17 | |
| 18 | /** |
| 19 | * @since 0.1.10 |
| 20 | */ |
| 21 | public function __construct() { |
| 22 | parent::__construct( |
| 23 | '/(^|\D)(?P<main>(?P<fromYear>\d{3,4})(–|-)(?P<toYear>\d{2,4}))(\D|$)/', |
| 24 | 'main' |
| 25 | ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @since 0.1.10 |
| 30 | * @param array $matches |
| 31 | * @return string|null |
| 32 | */ |
| 33 | public function createAlias( array $matches ): ?string { |
| 34 | // todo allow for years before 100? |
| 35 | // todo assert that from-year is less than to-year? |
| 36 | $fromYear = YearRule::getYearAlias( $matches['fromYear'][0] ); |
| 37 | $toDigits = $matches['toYear'][0]; |
| 38 | if ( strlen( $toDigits ) === 2 ) { |
| 39 | $digitsToWords = new DigitsToSwedishWords(); |
| 40 | $toYear = $digitsToWords->intToWords( intval( $toDigits ) ); |
| 41 | } else { |
| 42 | $toYear = YearRule::getYearAlias( $toDigits ); |
| 43 | } |
| 44 | if ( $fromYear === null || $toYear === null ) { |
| 45 | // @todo log unsupported from- and/or to-year |
| 46 | return null; |
| 47 | } |
| 48 | return $fromYear . ' till ' . $toYear; |
| 49 | } |
| 50 | |
| 51 | } |