Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a null check to label templates, adds return types for validation methods #16040

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
10 changes: 5 additions & 5 deletions app/Models/Labels/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,14 @@ public final function write2DBarcode(TCPDF $pdf, $value, $type, $x, $y, $width,
/**
* Checks the template is internally valid
*/
public final function validate() {
public final function validate() : void {
$this->validateUnits();
$this->validateSize();
$this->validateMargins();
$this->validateSupport();
}

private function validateUnits() {
private function validateUnits() : void {
$validUnits = [ 'pt', 'mm', 'cm', 'in' ];
$unit = $this->getUnit();
if (!in_array(strtolower($unit), $validUnits)) {
Expand All @@ -430,7 +430,7 @@ private function validateUnits() {
}
}

private function validateSize() {
private function validateSize() : void {
$width = $this->getWidth();
if (!is_numeric($width) || is_string($width)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
Expand All @@ -450,7 +450,7 @@ private function validateSize() {
}
}

private function validateMargins() {
private function validateMargins() : void {
$marginTop = $this->getMarginTop();
if (!is_numeric($marginTop) || is_string($marginTop)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
Expand Down Expand Up @@ -488,7 +488,7 @@ private function validateMargins() {
}
}

private function validateSupport() {
private function validateSupport() : void {
$support1D = $this->getSupport1DBarcode();
if (!is_bool($support1D)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
Expand Down
4 changes: 4 additions & 0 deletions app/View/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public function render(callable $callback = null)
->with('count', $this->data->get('count'));
}

if ($template === null) {
throw new \UnexpectedValueException('Template is null.');
Godmartinz marked this conversation as resolved.
Show resolved Hide resolved
}

$template->validate();

$pdf = new TCPDF(
Expand Down
Loading