Skip to content

Commit e9fbfa4

Browse files
committed
do not access typed property before initialization
1 parent 6375b48 commit e9fbfa4

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Tests/Transliterator/EmojiTransliteratorTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,18 @@ public function testReverse()
177177
$this->expectException(\IntlException::class);
178178
EmojiTransliterator::create('emoji-en', EmojiTransliterator::REVERSE);
179179
}
180+
181+
public function testGetErrorCodeWithUninitializedTransliterator()
182+
{
183+
$transliterator = EmojiTransliterator::create('emoji-en');
184+
185+
$this->assertSame(0, $transliterator->getErrorCode());
186+
}
187+
188+
public function testGetErrorMessageWithUninitializedTransliterator()
189+
{
190+
$transliterator = EmojiTransliterator::create('emoji-en');
191+
192+
$this->assertFalse($transliterator->getErrorMessage());
193+
}
180194
}

Transliterator/EmojiTransliterator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ public function createInverse(): self
7272

7373
public function getErrorCode(): int|false
7474
{
75-
return $this->transliterator?->getErrorCode() ?? 0;
75+
return isset($this->transliterator) ? $this->transliterator->getErrorCode() : 0;
7676
}
7777

7878
public function getErrorMessage(): string|false
7979
{
80-
return $this->transliterator?->getErrorMessage() ?? false;
80+
return isset($this->transliterator) ? $this->transliterator->getErrorMessage() : false;
8181
}
8282

8383
public static function listIDs(): array

0 commit comments

Comments
 (0)