@@ -536,10 +536,11 @@ public function setVersionNumber():self{
536
536
*/
537
537
public function setFormatInfo (MaskPattern $ maskPattern = null ):self {
538
538
$ this ->maskPattern = $ maskPattern ;
539
+ $ bits = 0 ; // sets all format fields to false (test mode)
539
540
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
+ }
543
544
544
545
for ($ i = 0 ; $ i < 15 ; $ i ++){
545
546
$ v = (($ bits >> $ i ) & 1 ) === 1 ;
@@ -578,6 +579,11 @@ public function setFormatInfo(MaskPattern $maskPattern = null):self{
578
579
*/
579
580
public function setQuietZone (int $ quietZoneSize ):self {
580
581
582
+ // early exit if there's nothing to add
583
+ if ($ quietZoneSize < 1 ){
584
+ return $ this ;
585
+ }
586
+
581
587
if ($ this ->matrix [($ this ->moduleCount - 1 )][($ this ->moduleCount - 1 )] === $ this ::M_NULL ){
582
588
throw new QRCodeDataException ('use only after writing data ' );
583
589
}
@@ -655,19 +661,18 @@ public function invert():self{
655
661
* @throws \chillerlan\QRCode\Data\QRCodeDataException
656
662
*/
657
663
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
-
664
664
$ height ??= $ width ;
665
665
666
666
// if width and height happen to be negative or 0 (default value), just return - nothing to do
667
667
if ($ width <= 0 || $ height <= 0 ){
668
668
return $ this ; // @codeCoverageIgnore
669
669
}
670
670
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
+
671
676
// $this->moduleCount includes the quiet zone (if created), we need the QR size here
672
677
$ dimension = $ this ->version ->getDimension ();
673
678
0 commit comments