Skip to content

Commit 8a7e79d

Browse files
committed
Make methods fluent
1 parent b9a2377 commit 8a7e79d

6 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/Barcode.php

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

17+
// Add a bar to the barcode, either a bar or a space, at the right side of the barcode
1718
public function addBar(BarcodeBar $bar): void
1819
{
1920
$this->bars[] = $bar;

src/BarcodeBar.php

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

33
namespace Picqer\Barcode;
44

5+
// Represents a single bar or space in a barcode
56
readonly class BarcodeBar
67
{
78
protected int $width;

src/Renderers/DynamicHtmlRenderer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ public function render(Barcode $barcode): string
3636
return $html;
3737
}
3838

39-
public function setForegroundColor(string $color): void
39+
public function setForegroundColor(string $color): self
4040
{
4141
$this->foregroundColor = $color;
42+
43+
return $this;
4244
}
4345
}

src/Renderers/HtmlRenderer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ public function render(Barcode $barcode, float $width = 200, float $height = 30)
3636
return $html;
3737
}
3838

39-
public function setForegroundColor(string $color): void
39+
public function setForegroundColor(string $color): self
4040
{
4141
$this->foregroundColor = $color;
42+
43+
return $this;
4244
}
4345
}

src/Renderers/PngRenderer.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@ public function __construct()
3232
/**
3333
* Force the use of Imagick image extension
3434
*/
35-
public function useImagick(): void
35+
public function useImagick(): self
3636
{
3737
$this->useImagick = true;
38+
return $this;
3839
}
3940

4041
/**
4142
* Force the use of the GD image library
4243
*/
43-
public function useGd(): void
44+
public function useGd(): self
4445
{
4546
$this->useImagick = false;
47+
return $this;
4648
}
4749

4850
public function render(Barcode $barcode, int $widthFactor = 2, int $height = 30): string
@@ -88,9 +90,11 @@ public function render(Barcode $barcode, int $widthFactor = 2, int $height = 30)
8890
}
8991
}
9092

91-
public function setForegroundColor(array $color): void
93+
public function setForegroundColor(array $color): self
9294
{
9395
$this->foregroundColor = $color;
96+
97+
return $this;
9498
}
9599

96100
protected function createGdImageObject(int $width, int $height)

src/Renderers/SvgRenderer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,19 @@ public function render(Barcode $barcode, float $width = 200, float $height = 30)
4949
return $svg;
5050
}
5151

52-
public function setForegroundColor(string $color): void
52+
public function setForegroundColor(string $color): self
5353
{
5454
$this->foregroundColor = $color;
55+
return $this;
5556
}
5657

57-
public function setSvgType(string $svgType): void
58+
public function setSvgType(string $svgType): self
5859
{
5960
if (! in_array($svgType, [self::TYPE_SVG_INLINE, self::TYPE_SVG_STANDALONE])) {
6061
throw new InvalidOptionException();
6162
}
6263

6364
$this->svgType = $svgType;
65+
return $this;
6466
}
6567
}

0 commit comments

Comments
 (0)