checks if template is null, adds return types for validation methods

This commit is contained in:
Godfrey M 2025-01-08 09:47:20 -08:00
parent 40b41e646d
commit c17c011488
2 changed files with 9 additions and 5 deletions

View file

@ -411,14 +411,14 @@ abstract class Label
/** /**
* Checks the template is internally valid * Checks the template is internally valid
*/ */
public final function validate() { public final function validate() : void {
$this->validateUnits(); $this->validateUnits();
$this->validateSize(); $this->validateSize();
$this->validateMargins(); $this->validateMargins();
$this->validateSupport(); $this->validateSupport();
} }
private function validateUnits() { private function validateUnits() : void {
$validUnits = [ 'pt', 'mm', 'cm', 'in' ]; $validUnits = [ 'pt', 'mm', 'cm', 'in' ];
$unit = $this->getUnit(); $unit = $this->getUnit();
if (!in_array(strtolower($unit), $validUnits)) { if (!in_array(strtolower($unit), $validUnits)) {
@ -430,7 +430,7 @@ abstract class Label
} }
} }
private function validateSize() { private function validateSize() : void {
$width = $this->getWidth(); $width = $this->getWidth();
if (!is_numeric($width) || is_string($width)) { if (!is_numeric($width) || is_string($width)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [ throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
@ -450,7 +450,7 @@ abstract class Label
} }
} }
private function validateMargins() { private function validateMargins() : void {
$marginTop = $this->getMarginTop(); $marginTop = $this->getMarginTop();
if (!is_numeric($marginTop) || is_string($marginTop)) { if (!is_numeric($marginTop) || is_string($marginTop)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [ throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
@ -488,7 +488,7 @@ abstract class Label
} }
} }
private function validateSupport() { private function validateSupport() : void{
$support1D = $this->getSupport1DBarcode(); $support1D = $this->getSupport1DBarcode();
if (!is_bool($support1D)) { if (!is_bool($support1D)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [ throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [

View file

@ -49,6 +49,10 @@ class Label implements View
->with('count', $this->data->get('count')); ->with('count', $this->data->get('count'));
} }
if ($template === null) {
throw new \UnexpectedValueException('Template is null.');
}
$template->validate(); $template->validate();
$pdf = new TCPDF( $pdf = new TCPDF(