Skip to content

Commit

Permalink
Use number_format instead of strval for formatting numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed Aug 16, 2021
1 parent 435eb22 commit 92b9e90
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Writer/SvgWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

final class SvgWriter implements WriterInterface
{
public const DECIMAL_PRECISION = 10;
public const WRITER_OPTION_BLOCK_ID = 'block_id';
public const WRITER_OPTION_EXCLUDE_XML_DECLARATION = 'exclude_xml_declaration';
public const WRITER_OPTION_FORCE_XLINK_HREF = 'force_xlink_href';
Expand All @@ -40,8 +41,8 @@ public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, Label

$blockDefinition = $xml->defs->addChild('rect');
$blockDefinition->addAttribute('id', $options[self::WRITER_OPTION_BLOCK_ID]);
$blockDefinition->addAttribute('width', strval($matrix->getBlockSize()));
$blockDefinition->addAttribute('height', strval($matrix->getBlockSize()));
$blockDefinition->addAttribute('width', number_format($matrix->getBlockSize(), self::DECIMAL_PRECISION, '.', ''));
$blockDefinition->addAttribute('height', number_format($matrix->getBlockSize(), self::DECIMAL_PRECISION, '.', ''));
$blockDefinition->addAttribute('fill', '#'.sprintf('%02x%02x%02x', $qrCode->getForegroundColor()->getRed(), $qrCode->getForegroundColor()->getGreen(), $qrCode->getForegroundColor()->getBlue()));
$blockDefinition->addAttribute('fill-opacity', strval($qrCode->getForegroundColor()->getOpacity()));

Expand All @@ -57,8 +58,8 @@ public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, Label
for ($columnIndex = 0; $columnIndex < $matrix->getBlockCount(); ++$columnIndex) {
if (1 === $matrix->getBlockValue($rowIndex, $columnIndex)) {
$block = $xml->addChild('use');
$block->addAttribute('x', strval($matrix->getMarginLeft() + $matrix->getBlockSize() * $columnIndex));
$block->addAttribute('y', strval($matrix->getMarginLeft() + $matrix->getBlockSize() * $rowIndex));
$block->addAttribute('x', number_format($matrix->getMarginLeft() + $matrix->getBlockSize() * $columnIndex, self::DECIMAL_PRECISION, '.', ''));
$block->addAttribute('y', number_format($matrix->getMarginLeft() + $matrix->getBlockSize() * $rowIndex, self::DECIMAL_PRECISION, '.', ''));
$block->addAttribute('xlink:href', '#'.$options[self::WRITER_OPTION_BLOCK_ID], 'http://www.w3.org/1999/xlink');
}
}
Expand Down

0 comments on commit 92b9e90

Please sign in to comment.