meeting the requirements of a static analyzer

This commit is contained in:
Anatoliy Poloz
2024-01-15 17:11:55 +03:00
81 changed files with 1320 additions and 501 deletions

View File

@@ -4,22 +4,23 @@ namespace App\Livewire\ProductNutritional;
use App\Models\ProductGroup;
use App\Models\ProductNutritionalValue;
use Livewire\Component;
use Livewire\WithFileUploads;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\UploadedFile;
use Livewire\Component;
use Livewire\WithFileUploads;
class Edit extends Component
{
use WithFileUploads;
public string $name;
public string $name = '';
public int $product_group;
public int|string $product_group;
public string|null $image;
public UploadedFile|string $image = '';
public string $description;
public string $description = '';
public string $formulations;
@@ -31,7 +32,7 @@ class Edit extends Component
public float $carbohydrates_on_100gr;
public int $portion_mass_gr;
public int $portion_mass_gr = 0;
public float $energy_on_portion;
@@ -70,8 +71,7 @@ class Edit extends Component
public function save(): void
{
if (! is_string($this->image)) {
/** @phpstan-ignore-next-line */
$this->product->image = $this->image->store('product_nutritional', 'public');
$this->product->image = $this->image->store('product_nutritional');
}
$this->product->fill([
@@ -79,15 +79,15 @@ class Edit extends Component
'product_group_id' => $this->product_group,
'description' => $this->description ?? '',
'formulations' => $this->formulations ?? '',
'energy_on_100gr' => (int) $this->energy_on_100gr,
'proteins_on_100gr' => (float) $this->proteins_on_100gr,
'fats_on_100gr' => (float) $this->fats_on_100gr,
'carbohydrates_on_100gr' => (float) $this->carbohydrates_on_100gr,
'portion_mass_gr' => (int) $this->portion_mass_gr,
'energy_on_100gr' => $this->energy_on_100gr,
'proteins_on_100gr' => $this->proteins_on_100gr,
'fats_on_100gr' => $this->fats_on_100gr,
'carbohydrates_on_100gr' => $this->carbohydrates_on_100gr,
'portion_mass_gr' => $this->portion_mass_gr,
'energy_on_portion' => (int) $this->energy_on_portion,
'proteins_on_portion' => (float) $this->proteins_on_portion,
'fats_on_portion' => (float) $this->fats_on_portion,
'carbohydrates_on_portion' => (float) $this->carbohydrates_on_portion,
'proteins_on_portion' => $this->proteins_on_portion,
'fats_on_portion' => $this->fats_on_portion,
'carbohydrates_on_portion' => $this->carbohydrates_on_portion,
]);
$this->product->save();
@@ -133,17 +133,17 @@ class Edit extends Component
}
}
public function updated(string $name, string|int|null $value): void
public function updated(string $name, string $value): void
{
if ($name === 'portion_mass_gr') {
$this->recalulatePortionVals((int) $this->portion_mass_gr);
$this->recalulatePortionVals($this->portion_mass_gr);
}
if (
(int) $this->portion_mass_gr > 0
$this->portion_mass_gr > 0
&& in_array($name, ['energy_on_portion', 'proteins_on_portion', 'fats_on_portion', 'carbohydrates_on_portion'])
) {
$this->recalulateVals((int) $this->portion_mass_gr);
$this->recalulateVals($this->portion_mass_gr);
}
}