3434 * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
3535 * @link https://github.com/tecnickcom/tc-lib-barcode
3636 *
37- * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
37+ * @SuppressWarnings(" PHPMD.ExcessiveClassComplexity" )
3838 */
3939abstract class Type extends \Com \Tecnick \Barcode \Type \Convert implements Model
4040{
@@ -85,8 +85,6 @@ protected function setParameters(): void
8585
8686 /**
8787 * Set the bars array
88- *
89- * @throws BarcodeException in case of error
9088 */
9189 protected function setBars (): void
9290 {
@@ -140,7 +138,7 @@ public function setSize(
140138 */
141139 protected function setPadding (array $ padding ): static
142140 {
143- if (! is_array ( $ padding ) || ( count ($ padding ) != 4 ) ) {
141+ if (count ($ padding ) != 4 ) {
144142 throw new BarcodeException (
145143 'Invalid padding, expecting an array of 4 numbers (top, right, bottom, left) '
146144 );
@@ -494,8 +492,8 @@ public function getPngDataImagick(): string
494492 */
495493 public function getGd (): \GdImage
496494 {
497- $ width = ( int ) ceil ($ this ->width + $ this ->padding ['L ' ] + $ this ->padding ['R ' ]);
498- $ height = ( int ) ceil ($ this ->height + $ this ->padding ['T ' ] + $ this ->padding ['B ' ]);
495+ $ width = max ( 1 , ( int ) ceil ($ this ->width + $ this ->padding ['L ' ] + $ this ->padding ['R ' ]) );
496+ $ height = max ( 1 , ( int ) ceil ($ this ->height + $ this ->padding ['T ' ] + $ this ->padding ['B ' ]) );
499497 $ img = imagecreate ($ width , $ height );
500498 if ($ img === false ) {
501499 throw new BarcodeException ('Unable to create GD image ' );
@@ -506,9 +504,9 @@ public function getGd(): \GdImage
506504 $ rgbcolor = $ bgobj ->invertColor ()->getNormalizedArray (255 );
507505 $ background_color = imagecolorallocate (
508506 $ img ,
509- (int ) round ($ rgbcolor ['R ' ]),
510- (int ) round ($ rgbcolor ['G ' ]),
511- (int ) round ($ rgbcolor ['B ' ]),
507+ (int ) round ($ rgbcolor ['R ' ]), // @phpstan-ignore argument.type
508+ (int ) round ($ rgbcolor ['G ' ]), // @phpstan-ignore argument.type
509+ (int ) round ($ rgbcolor ['B ' ]), // @phpstan-ignore argument.type
512510 );
513511 if ($ background_color === false ) {
514512 throw new BarcodeException ('Unable to allocate default GD background color ' );
@@ -518,9 +516,9 @@ public function getGd(): \GdImage
518516 $ rgbcolor = $ this ->bg_color_obj ->getNormalizedArray (255 );
519517 $ bg_color = imagecolorallocate (
520518 $ img ,
521- (int ) round ($ rgbcolor ['R ' ]),
522- (int ) round ($ rgbcolor ['G ' ]),
523- (int ) round ($ rgbcolor ['B ' ]),
519+ (int ) round ($ rgbcolor ['R ' ]), // @phpstan-ignore argument.type
520+ (int ) round ($ rgbcolor ['G ' ]), // @phpstan-ignore argument.type
521+ (int ) round ($ rgbcolor ['B ' ]), // @phpstan-ignore argument.type
524522 );
525523 if ($ bg_color === false ) {
526524 throw new BarcodeException ('Unable to allocate GD background color ' );
@@ -531,9 +529,9 @@ public function getGd(): \GdImage
531529 $ rgbcolor = $ this ->color_obj ->getNormalizedArray (255 );
532530 $ bar_color = imagecolorallocate (
533531 $ img ,
534- (int ) round ($ rgbcolor ['R ' ]),
535- (int ) round ($ rgbcolor ['G ' ]),
536- (int ) round ($ rgbcolor ['B ' ]),
532+ (int ) round ($ rgbcolor ['R ' ]), // @phpstan-ignore argument.type
533+ (int ) round ($ rgbcolor ['G ' ]), // @phpstan-ignore argument.type
534+ (int ) round ($ rgbcolor ['B ' ]), // @phpstan-ignore argument.type
537535 );
538536 if ($ bar_color === false ) {
539537 throw new BarcodeException ('Unable to allocate GD foreground color ' );
0 commit comments