diff --git a/lib/PHPPdf/Core/PdfUnitConverter.php b/lib/PHPPdf/Core/PdfUnitConverter.php index ea563a02..ef37ac50 100644 --- a/lib/PHPPdf/Core/PdfUnitConverter.php +++ b/lib/PHPPdf/Core/PdfUnitConverter.php @@ -12,33 +12,36 @@ /** * Unit converter - * + * * @author Piotr Śliwa */ class PdfUnitConverter extends AbstractUnitConverter { private $dpi; private $unitsPerPixel; - + public function __construct($dpi = 96) { - if(!is_int($dpi) || $dpi < 1) - { + if (!is_int($dpi) || $dpi < 1) { throw new InvalidArgumentException(sprintf('Dpi must be positive integer, "%s" given.', $dpi)); } $this->dpi = $dpi; - $this->unitsPerPixel = self::UNITS_PER_INCH/$this->dpi; + $this->unitsPerPixel = self::UNITS_PER_INCH / $this->dpi; } - + + /** + * @param string|float|int|null $value + * @param string|null $unit + * @return float|int|string + */ public function convertUnit($value, $unit = null) { - if(is_numeric($value) && $unit === null) - { + if (is_numeric($value) && $unit === null) { return $value; } - - $unit = $unit ? : strtolower(substr($value, -2, 2)); + + $unit = $unit ?: strtolower(substr((string) $value, -2, 2)); return $this->doConvertUnit($value, $unit); } @@ -51,16 +54,16 @@ protected function convertPxUnit($value) protected function convertInUnit($value) { - return ((float) $value)*self::UNITS_PER_INCH; + return ((float) $value) * self::UNITS_PER_INCH; } - + protected function convertPtUnit($value) { return (float) $value; } - + protected function convertMmUnit($value) { - return $this->convertInUnit($value)/self::MM_PER_INCH; + return $this->convertInUnit($value) / self::MM_PER_INCH; } -} \ No newline at end of file +}