Skip to content

Commit

Permalink
do not access typed property before initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Oct 22, 2024
1 parent 6375b48 commit e9fbfa4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions Tests/Transliterator/EmojiTransliteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,18 @@ public function testReverse()
$this->expectException(\IntlException::class);
EmojiTransliterator::create('emoji-en', EmojiTransliterator::REVERSE);
}

public function testGetErrorCodeWithUninitializedTransliterator()
{
$transliterator = EmojiTransliterator::create('emoji-en');

$this->assertSame(0, $transliterator->getErrorCode());
}

public function testGetErrorMessageWithUninitializedTransliterator()
{
$transliterator = EmojiTransliterator::create('emoji-en');

$this->assertFalse($transliterator->getErrorMessage());
}
}
4 changes: 2 additions & 2 deletions Transliterator/EmojiTransliterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ public function createInverse(): self

public function getErrorCode(): int|false
{
return $this->transliterator?->getErrorCode() ?? 0;
return isset($this->transliterator) ? $this->transliterator->getErrorCode() : 0;
}

public function getErrorMessage(): string|false
{
return $this->transliterator?->getErrorMessage() ?? false;
return isset($this->transliterator) ? $this->transliterator->getErrorMessage() : false;
}

public static function listIDs(): array
Expand Down

0 comments on commit e9fbfa4

Please sign in to comment.