Skip to content

Commit

Permalink
Make methods fluent
Browse files Browse the repository at this point in the history
  • Loading branch information
casperbakker committed Sep 21, 2024
1 parent b9a2377 commit 8a7e79d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/Barcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function __construct(string $barcode)
$this->barcode = $barcode;
}

// Add a bar to the barcode, either a bar or a space, at the right side of the barcode
public function addBar(BarcodeBar $bar): void
{
$this->bars[] = $bar;
Expand Down
1 change: 1 addition & 0 deletions src/BarcodeBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Picqer\Barcode;

// Represents a single bar or space in a barcode
readonly class BarcodeBar
{
protected int $width;
Expand Down
4 changes: 3 additions & 1 deletion src/Renderers/DynamicHtmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public function render(Barcode $barcode): string
return $html;
}

public function setForegroundColor(string $color): void
public function setForegroundColor(string $color): self
{
$this->foregroundColor = $color;

return $this;
}
}
4 changes: 3 additions & 1 deletion src/Renderers/HtmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public function render(Barcode $barcode, float $width = 200, float $height = 30)
return $html;
}

public function setForegroundColor(string $color): void
public function setForegroundColor(string $color): self
{
$this->foregroundColor = $color;

return $this;
}
}
10 changes: 7 additions & 3 deletions src/Renderers/PngRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ public function __construct()
/**
* Force the use of Imagick image extension
*/
public function useImagick(): void
public function useImagick(): self
{
$this->useImagick = true;
return $this;
}

/**
* Force the use of the GD image library
*/
public function useGd(): void
public function useGd(): self
{
$this->useImagick = false;
return $this;
}

public function render(Barcode $barcode, int $widthFactor = 2, int $height = 30): string
Expand Down Expand Up @@ -88,9 +90,11 @@ public function render(Barcode $barcode, int $widthFactor = 2, int $height = 30)
}
}

public function setForegroundColor(array $color): void
public function setForegroundColor(array $color): self
{
$this->foregroundColor = $color;

return $this;
}

protected function createGdImageObject(int $width, int $height)
Expand Down
6 changes: 4 additions & 2 deletions src/Renderers/SvgRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,19 @@ public function render(Barcode $barcode, float $width = 200, float $height = 30)
return $svg;
}

public function setForegroundColor(string $color): void
public function setForegroundColor(string $color): self
{
$this->foregroundColor = $color;
return $this;
}

public function setSvgType(string $svgType): void
public function setSvgType(string $svgType): self
{
if (! in_array($svgType, [self::TYPE_SVG_INLINE, self::TYPE_SVG_STANDALONE])) {
throw new InvalidOptionException();
}

$this->svgType = $svgType;
return $this;
}
}

0 comments on commit 8a7e79d

Please sign in to comment.