Add type declarations to Font

Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
This commit is contained in:
Maurício Meneghini Fauth 2018-05-09 22:59:09 -03:00
parent ec3583944b
commit 150888a2d6
2 changed files with 9 additions and 11 deletions

View File

@ -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);
}
}

View File

@ -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,