collation: Improve IcuCollation for static code analyzer

phan says that $this->mainCollator is not documented to get null
assigned.
Use a local variable to check for null and than set the class property.

Change-Id: I000c935da8d99184f2ae0382fc5caac81e80c8d7
This commit is contained in:
Umherirrender 2021-11-08 23:11:19 +01:00
parent b1a55d5b62
commit 52631861b1

View file

@ -254,10 +254,11 @@ class IcuCollation extends Collation {
$localeParts = explode( '@', $locale );
$this->digitTransformLanguage = $languageFactory->getLanguage( $locale === 'root' ? 'en' : $localeParts[0] );
$this->mainCollator = Collator::create( $locale );
if ( !$this->mainCollator ) {
$mainCollator = Collator::create( $locale );
if ( !$mainCollator ) {
throw new MWException( "Invalid ICU locale specified for collation: $locale" );
}
$this->mainCollator = $mainCollator;
$this->primaryCollator = Collator::create( $locale );
$this->primaryCollator->setStrength( Collator::PRIMARY );