Skip to content

Commit 460f3ee

Browse files
committed
More typehints
1 parent ec4502f commit 460f3ee

32 files changed

+70
-53
lines changed

.github/FUNDING.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Barcode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function __construct(string $barcode)
1414
$this->barcode = $barcode;
1515
}
1616

17-
public function addBar(BarcodeBar $bar)
17+
public function addBar(BarcodeBar $bar): void
1818
{
1919
$this->bars[] = $bar;
2020
$this->width += $bar->getWidth();

src/BarcodeBar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Picqer\Barcode;
44

5-
class BarcodeBar
5+
readonly class BarcodeBar
66
{
77
protected int $width;
88
protected int $height;

src/BarcodeGenerator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
use Picqer\Barcode\Types\TypeEan13;
4646
use Picqer\Barcode\Types\TypeEan8;
4747
use Picqer\Barcode\Types\TypeIntelligentMailBarcode;
48+
use Picqer\Barcode\Types\TypeInterface;
4849
use Picqer\Barcode\Types\TypeInterleaved25;
4950
use Picqer\Barcode\Types\TypeInterleaved25Checksum;
5051
use Picqer\Barcode\Types\TypeITF14;
@@ -101,14 +102,17 @@ abstract class BarcodeGenerator
101102
const TYPE_PHARMA_CODE = 'PHARMA';
102103
const TYPE_PHARMA_CODE_TWO_TRACKS = 'PHARMA2T';
103104

105+
/**
106+
* @throws UnknownTypeException
107+
*/
104108
protected function getBarcodeData(string $code, string $type): Barcode
105109
{
106110
$barcodeDataBuilder = $this->createDataBuilderForType($type);
107111

108112
return $barcodeDataBuilder->getBarcode($code);
109113
}
110114

111-
protected function createDataBuilderForType(string $type)
115+
protected function createDataBuilderForType(string $type): TypeInterface
112116
{
113117
switch (strtoupper($type)) {
114118
case self::TYPE_CODE_32:

src/BarcodeGeneratorDynamicHTML.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Picqer\Barcode;
44

5+
use Picqer\Barcode\Exceptions\UnknownTypeException;
6+
57
class BarcodeGeneratorDynamicHTML extends BarcodeGenerator
68
{
79
/**
@@ -12,6 +14,7 @@ class BarcodeGeneratorDynamicHTML extends BarcodeGenerator
1214
* @param BarcodeGenerator::TYPE_* $type (string) type of barcode
1315
* @param string $foregroundColor Foreground color for bar elements as '#333' or 'orange' for example (background is transparent).
1416
* @return string HTML code.
17+
* @throws UnknownTypeException
1518
*/
1619
public function getBarcode(string $barcode, $type, string $foregroundColor = 'black'): string
1720
{

src/BarcodeGeneratorHTML.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Picqer\Barcode;
44

5+
use Picqer\Barcode\Exceptions\UnknownTypeException;
6+
57
class BarcodeGeneratorHTML extends BarcodeGenerator
68
{
79
/**
@@ -14,6 +16,7 @@ class BarcodeGeneratorHTML extends BarcodeGenerator
1416
* @param int $height Height of a single bar element in pixels.
1517
* @param string $foregroundColor Foreground color for bar elements as '#333' or 'orange' for example (background is transparent).
1618
* @return string HTML code.
19+
* @throws UnknownTypeException
1720
*/
1821
public function getBarcode(string $barcode, $type, int $widthFactor = 2, int $height = 30, string $foregroundColor = 'black'): string
1922
{

src/BarcodeGeneratorJPG.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Picqer\Barcode;
44

5+
use Picqer\Barcode\Exceptions\UnknownTypeException;
6+
57
class BarcodeGeneratorJPG extends BarcodeGenerator
68
{
79
protected ?bool $useImagick = null;
@@ -15,6 +17,7 @@ class BarcodeGeneratorJPG extends BarcodeGenerator
1517
* @param int $height Height of a single bar element in pixels.
1618
* @param array $foregroundColor RGB (0-255) foreground color for bar elements (background is transparent).
1719
* @return string image data or false in case of error.
20+
* @throws UnknownTypeException
1821
*/
1922
public function getBarcode(string $barcode, $type, int $widthFactor = 2, int $height = 30, array $foregroundColor = [0, 0, 0]): string
2023
{
@@ -37,15 +40,15 @@ public function getBarcode(string $barcode, $type, int $widthFactor = 2, int $he
3740
/**
3841
* Force the use of Imagick image extension
3942
*/
40-
public function useImagick()
43+
public function useImagick(): void
4144
{
4245
$this->useImagick = true;
4346
}
4447

4548
/**
4649
* Force the use of the GD image library
4750
*/
48-
public function useGd()
51+
public function useGd(): void
4952
{
5053
$this->useImagick = false;
5154
}

src/BarcodeGeneratorPNG.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Picqer\Barcode;
44

5+
use Picqer\Barcode\Exceptions\UnknownTypeException;
6+
57
class BarcodeGeneratorPNG extends BarcodeGenerator
68
{
79
protected ?bool $useImagick = null;
@@ -15,6 +17,7 @@ class BarcodeGeneratorPNG extends BarcodeGenerator
1517
* @param int $height Height of a single bar element in pixels.
1618
* @param array $foregroundColor RGB (0-255) foreground color for bar elements (background is transparent).
1719
* @return string image data or false in case of error.
20+
* @throws UnknownTypeException
1821
*/
1922
public function getBarcode(string $barcode, $type, int $widthFactor = 2, int $height = 30, array $foregroundColor = [0, 0, 0]): string
2023
{
@@ -37,15 +40,15 @@ public function getBarcode(string $barcode, $type, int $widthFactor = 2, int $he
3740
/**
3841
* Force the use of Imagick image extension
3942
*/
40-
public function useImagick()
43+
public function useImagick(): void
4144
{
4245
$this->useImagick = true;
4346
}
4447

4548
/**
4649
* Force the use of the GD image library
4750
*/
48-
public function useGd()
51+
public function useGd(): void
4952
{
5053
$this->useImagick = false;
5154
}

src/BarcodeGeneratorSVG.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Picqer\Barcode;
44

5+
use Picqer\Barcode\Exceptions\UnknownTypeException;
6+
57
class BarcodeGeneratorSVG extends BarcodeGenerator
68
{
79
/**
@@ -14,6 +16,7 @@ class BarcodeGeneratorSVG extends BarcodeGenerator
1416
* @param $foregroundColor (string) Foreground color (in SVG format) for bar elements (background is transparent).
1517
* @return string SVG code.
1618
* @public
19+
* @throws UnknownTypeException
1720
*/
1821
public function getBarcode(string $barcode, $type, float $widthFactor = 2, float $height = 30, string $foregroundColor = 'black'): string
1922
{

src/Types/TypeCodabar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class TypeCodabar implements TypeInterface
1515
{
16-
protected $conversionTable = [
16+
protected array $conversionTable = [
1717
'0' => '11111221',
1818
'1' => '11112211',
1919
'2' => '11121121',

0 commit comments

Comments
 (0)