0

I'm using Laravel Job to process some data, passing a device object which has json array in it.

defined private properties, Note there are way more than just 3

private int $width;
private int $depth;
private int $height;

Then initiating it via loop

foreach($this->device->data as $key => $val)
{
        $this->{$key} = $val;
}

Now before using it I want to check if they initiated properly before running my methods.

Currently checking before running each method like

if(ISSET($this->waste) && ISSET($this->height))
            $this->level = $this->getLevelFromDistance($this->waste, $this->height);

Is it the only way to go about this? or is there a better way to do this?

My ultimate object is to check if properties exists then process the object otherwise log an alert for user.

Zee
  • 351
  • 1
  • 15
  • How object is created? Maybe good solution is to not allow create invalid object and alert user in this point. – Styx Sep 08 '22 at 23:48
  • I thought so too, but it's a device Laravel model object and devices has different types and variants and some variant might not have dimensions. – Zee Sep 08 '22 at 23:52
  • I don't know Laravel, but I think you could have own data model. Each device type should be separated class. – Styx Sep 09 '22 at 03:47

0 Answers0