Skip to content

Commit 2327690

Browse files
committed
🚿
1 parent c0dba8d commit 2327690

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/Data/QRMatrix.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,11 @@ public function setVersionNumber():self{
536536
*/
537537
public function setFormatInfo(MaskPattern $maskPattern = null):self{
538538
$this->maskPattern = $maskPattern;
539+
$bits = 0; // sets all format fields to false (test mode)
539540

540-
$bits = ($this->maskPattern instanceof MaskPattern)
541-
? $this->eccLevel->getformatPattern($this->maskPattern)
542-
: 0; // sets all format fields to false (test mode)
541+
if($this->maskPattern instanceof MaskPattern){
542+
$bits = $this->eccLevel->getformatPattern($this->maskPattern);
543+
}
543544

544545
for($i = 0; $i < 15; $i++){
545546
$v = (($bits >> $i) & 1) === 1;
@@ -578,6 +579,11 @@ public function setFormatInfo(MaskPattern $maskPattern = null):self{
578579
*/
579580
public function setQuietZone(int $quietZoneSize):self{
580581

582+
// early exit if there's nothing to add
583+
if($quietZoneSize < 1){
584+
return $this;
585+
}
586+
581587
if($this->matrix[($this->moduleCount - 1)][($this->moduleCount - 1)] === $this::M_NULL){
582588
throw new QRCodeDataException('use only after writing data');
583589
}
@@ -655,19 +661,18 @@ public function invert():self{
655661
* @throws \chillerlan\QRCode\Data\QRCodeDataException
656662
*/
657663
public function setLogoSpace(int $width, int $height = null, int $startX = null, int $startY = null):self{
658-
659-
// for logos, we operate in ECC H (30%) only
660-
if($this->eccLevel->getLevel() !== EccLevel::H){
661-
throw new QRCodeDataException('ECC level "H" required to add logo space');
662-
}
663-
664664
$height ??= $width;
665665

666666
// if width and height happen to be negative or 0 (default value), just return - nothing to do
667667
if($width <= 0 || $height <= 0){
668668
return $this; // @codeCoverageIgnore
669669
}
670670

671+
// for logos, we operate in ECC H (30%) only
672+
if($this->eccLevel->getLevel() !== EccLevel::H){
673+
throw new QRCodeDataException('ECC level "H" required to add logo space');
674+
}
675+
671676
// $this->moduleCount includes the quiet zone (if created), we need the QR size here
672677
$dimension = $this->version->getDimension();
673678

0 commit comments

Comments
 (0)