diff --git a/libraries/classes/Font.php b/libraries/classes/Font.php index 047b60f041..a9867410c1 100644 --- a/libraries/classes/Font.php +++ b/libraries/classes/Font.php @@ -20,7 +20,7 @@ class Font * @return array with characters and corresponding width modifier * @access public */ - public function getCharLists() + public function getCharLists(): array { // list of characters and their width modifiers $charLists = array(); @@ -86,9 +86,13 @@ class Font * @return integer width of the text * @access public */ - public function getStringWidth($text, $font, $fontSize, $charLists = null) - { - if (empty($charLists) || !is_array($charLists) + public function getStringWidth( + string $text, + string $font, + int $fontSize, + ?array $charLists = null + ): int { + if (empty($charLists) || !isset($charLists[0]["chars"]) || !is_array($charLists[0]["chars"]) || !isset($charLists[0]["modifier"]) ) { @@ -137,6 +141,6 @@ class Font break; } $textWidth = $count * $fontSize; - return (int)ceil($textWidth * $modifier); + return (int) ceil($textWidth * $modifier); } } diff --git a/test/classes/FontTest.php b/test/classes/FontTest.php index 68837fec71..fb33a4b79e 100644 --- a/test/classes/FontTest.php +++ b/test/classes/FontTest.php @@ -223,12 +223,6 @@ class FontTest extends PmaTestCase */ function testGetStringWidthCharLists() { - // string "a", with invalid charlist (= string) - $this->assertEquals( - 6, - $this->font->getStringWidth("a", "arial", "10", "list") - ); - // string "a", with invalid charlist (= array without proper structure) $this->assertEquals( 6,