Skip to content

Commit

Permalink
Fix phpstan 1.0 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed Nov 3, 2021
1 parent 8ecd0dc commit 1e66213
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
33 changes: 28 additions & 5 deletions src/Builder/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,39 @@

class Builder implements BuilderInterface
{
/** @var array<mixed> */
/**
* @var array<mixed>{
* data: string,
* writer: WriterInterface,
* writerOptions: array,
* qrCodeClass: class-string,
* logoClass: class-string,
* labelClass: class-string,
* validateResult: bool,
* size?: int,
* encoding?: EncodingInterface,
* errorCorrectionLevel?: ErrorCorrectionLevelInterface,
* roundBlockSizeMode?: RoundBlockSizeModeInterface,
* margin?: int,
* backgroundColor?: ColorInterface,
* foregroundColor?: ColorInterface,
* labelText?: string,
* labelFont?: FontInterface,
* labelAlignment?: LabelAlignmentInterface,
* labelMargin?: MarginInterface,
* labelTextColor?: ColorInterface,
* logoPath?: string,
* logoResizeToWidth?: int,
* logoResizeToHeight?: int,
* logoPunchoutBackground?: bool
* }
*/
private array $options;

public function __construct()
{
$this->options = [
'data' => '',
'writer' => new PngWriter(),
'writerOptions' => [],
'qrCodeClass' => QrCode::class,
Expand Down Expand Up @@ -186,10 +213,6 @@ public function validateResult(bool $validateResult): BuilderInterface

public function build(): ResultInterface
{
if (!isset($this->options['writer']) || !$this->options['writer'] instanceof WriterInterface) {
throw new \Exception('Pass a valid writer via $builder->writer()');
}

$writer = $this->options['writer'];

if ($this->options['validateResult'] && !$writer instanceof ValidatingWriterInterface) {
Expand Down
4 changes: 4 additions & 0 deletions src/ImageData/LogoImageData.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public function getData(): string
/** @return mixed */
public function getImage()
{
if (null === $this->image) {
throw new \Exception('SVG Images have no image resource');
}

return $this->image;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Writer/PdfWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ private function addLogo(LogoInterface $logo, \FPDF $fpdf, float $x, float $y, f
$logoWidth = $logo->getResizeToWidth();

if (null === $logoHeight || null === $logoWidth) {
[$logoSourceWidth, $logoSourceHeight] = \getimagesize($logoPath);
$imageSize = \getimagesize($logoPath);
if (!$imageSize) {
throw new \Exception(sprintf('Unable to read image size for logo "%s"', $logoPath));
}
[$logoSourceWidth, $logoSourceHeight] = $imageSize;

if (null === $logoWidth) {
$logoWidth = (int) $logoSourceWidth;
Expand Down
4 changes: 2 additions & 2 deletions src/Writer/SvgWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, Label
$xml->addChild('defs');

$blockDefinition = $xml->defs->addChild('rect');
$blockDefinition->addAttribute('id', $options[self::WRITER_OPTION_BLOCK_ID]);
$blockDefinition->addAttribute('id', strval($options[self::WRITER_OPTION_BLOCK_ID]));
$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()));
Expand All @@ -65,7 +65,7 @@ public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, Label
}
}

$result = new SvgResult($xml, $options[self::WRITER_OPTION_EXCLUDE_XML_DECLARATION]);
$result = new SvgResult($xml, boolval($options[self::WRITER_OPTION_EXCLUDE_XML_DECLARATION]));

if ($logo instanceof LogoInterface) {
$this->addLogo($logo, $result, $options);
Expand Down

0 comments on commit 1e66213

Please sign in to comment.