Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 19 |
SrConverter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 19 |
loadDefaultTables | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
findVariantLink | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 4 |
|||
guessVariant | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 13 |
<?php | |
declare( strict_types = 1 ); | |
namespace Wikimedia\Parsoid\Language; | |
use Wikimedia\LangConv\FstReplacementMachine; | |
class SrConverter extends LanguageConverter { | |
public function loadDefaultTables() { | |
$this->setMachine( new FstReplacementMachine( 'sr', [ 'sr-ec', 'sr-el' ] ) ); | |
} | |
// phpcs:ignore MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic | |
public function findVariantLink( $link, $nt, $ignoreOtherCond ) { | |
$ns = $nt->getNamespace(); | |
// do not try to find variants for usernames | |
if ( $ns->isUser() || $ns->isUserTalk ) { | |
return [ 'nt' => $nt, 'link' => $link ]; | |
} | |
// FIXME check whether selected language is 'sr' | |
return parent::findVariantLink( $link, $nt, $ignoreOtherCond ); | |
} | |
/** | |
* Variant based on the ReplacementMachine's bracketing abilities | |
* @param string $text | |
* @param string $variant | |
* @return bool | |
*/ | |
public function guessVariant( $text, $variant ) { | |
$r = []; | |
$machine = $this->getMachine(); | |
'@phan-var FstReplacementMachine $machine'; /* @var FstReplacementMachine $machine */ | |
foreach ( $machine->getCodes() as $code => $ignore1 ) { | |
foreach ( $machine->getCodes() as $othercode => $ignore2 ) { | |
if ( $code === $othercode ) { | |
return false; | |
} | |
$r[] = [ | |
'code' => $code, | |
'othercode' => $othercode, | |
'stats' => $machine->countBrackets( $text, $code, $othercode ) | |
]; | |
} | |
} | |
uasort( $r, static function ( $a, $b ) { | |
return $a['stats']->unsafe - $b['stats']->unsafe; | |
} ); | |
return $r[0]['othercode'] === $variant; | |
} | |
} |