Add type declarations to Font
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
This commit is contained in:
parent
ec3583944b
commit
150888a2d6
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user