forked from eatvio/eatvio-infra
make static-analyse code
This commit is contained in:
@@ -6,44 +6,48 @@ use App\Models\Diary;
|
||||
use App\Models\Meal;
|
||||
use App\Models\Portion;
|
||||
use Livewire\Component;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class MealForm extends Component
|
||||
{
|
||||
public $time;
|
||||
public string $time;
|
||||
|
||||
public $type = 0;
|
||||
public int $type = 0;
|
||||
|
||||
public $satiety = 3;
|
||||
public int $satiety = 3;
|
||||
|
||||
public $mood = 3;
|
||||
public int $mood = 3;
|
||||
|
||||
public $product_name;
|
||||
public string $product_name;
|
||||
|
||||
public $portions;
|
||||
public array $portions;
|
||||
|
||||
public $quantity;
|
||||
public string $quantity;
|
||||
|
||||
public $pcs;
|
||||
public string $pcs;
|
||||
|
||||
public $unit;
|
||||
public string $unit;
|
||||
|
||||
public $diaryId;
|
||||
public int $diaryId;
|
||||
|
||||
public Diary $diary;
|
||||
|
||||
public Meal $meal;
|
||||
|
||||
public $portion;
|
||||
public string $portion;
|
||||
|
||||
protected $rules = [
|
||||
protected array $rules = [
|
||||
'product_name' => 'required|min:3',
|
||||
'quantity' => 'required',
|
||||
'portion' => 'required|min:1',
|
||||
];
|
||||
|
||||
protected $listeners = ['food-intake-updated' => '$refresh'];
|
||||
protected function getListeners(): array
|
||||
{
|
||||
return ['food-intake-updated' => '$refresh'];
|
||||
}
|
||||
|
||||
public function mount()
|
||||
public function mount(): void
|
||||
{
|
||||
$this->diary = Diary::find($this->diaryId);
|
||||
$curMeal = $this->diary->meals->where('type', 0)->first();
|
||||
@@ -65,7 +69,7 @@ class MealForm extends Component
|
||||
$this->portions = $curPortions;
|
||||
}
|
||||
|
||||
public function updatingType($value)
|
||||
public function updatingType(int $value): void
|
||||
{
|
||||
$curMeal = $this->diary->meals->where('type', $value)->first();
|
||||
$this->satiety = $curMeal->satiety ?? 3;
|
||||
@@ -73,7 +77,7 @@ class MealForm extends Component
|
||||
$this->time = $curMeal->time ?? now()->setTimezone('3')->format('H:i');
|
||||
}
|
||||
|
||||
public function render()
|
||||
public function render(): View
|
||||
{
|
||||
$types = [0, 1, 2, 3, 4];
|
||||
$typeNames = ['Завтрак', 'Обед', 'Ужин', 'Ланч', 'Перекусы'];
|
||||
@@ -99,7 +103,7 @@ class MealForm extends Component
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function addFoodIntake(Diary $diary, Meal $meal, Portion $portion)
|
||||
public function addFoodIntake(Diary $diary, Meal $meal, Portion $portion): void
|
||||
{
|
||||
$this->addPortionIfItFilled();
|
||||
|
||||
@@ -142,7 +146,7 @@ class MealForm extends Component
|
||||
$this->dispatch('food-intake-updated')->self();
|
||||
}
|
||||
|
||||
public function addPortion()
|
||||
public function addPortion(): void
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
@@ -159,7 +163,7 @@ class MealForm extends Component
|
||||
$this->reset(['product_name', 'quantity', 'portion']);
|
||||
}
|
||||
|
||||
public function editPortion($key, $item)
|
||||
public function editPortion(int $key, array $item): void
|
||||
{
|
||||
$filed = [
|
||||
'product_name' => $item['product_name'],
|
||||
@@ -170,7 +174,7 @@ class MealForm extends Component
|
||||
$this->fill($filed);
|
||||
}
|
||||
|
||||
public function delPortion($key, $item)
|
||||
public function delPortion(int $key, array $item): void
|
||||
{
|
||||
if (isset($item['id'])) {
|
||||
Portion::find($item['id'])->delete();
|
||||
@@ -186,7 +190,7 @@ class MealForm extends Component
|
||||
$this->portions = array_values($filtered);
|
||||
}
|
||||
|
||||
private function addPortionIfItFilled()
|
||||
private function addPortionIfItFilled(): void
|
||||
{
|
||||
if (mb_strlen($this->product_name) && $this->quantity && mb_strlen($this->portion)) {
|
||||
$this->addPortion();
|
||||
|
||||
Reference in New Issue
Block a user