Conditions | 4 |
Paths | 3 |
Total Lines | 24 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
35 | public function validateItem(array $values): array |
||
36 | { |
||
37 | $validator = Validator::make($this->values($values), [ |
||
38 | 'type' => 'required|integer|between:0,1', |
||
39 | 'period' => 'required|integer|between:0,3', |
||
40 | 'name' => 'required|string|min:1', |
||
41 | 'fixed' => [ |
||
42 | Rule::requiredIf((int)$values['type'] === 0 && (int)$values['period'] > 0), |
||
43 | 'in:1', |
||
44 | 'exclude', |
||
45 | ], |
||
46 | 'amount' => $this->amountIfRule('fixed'), |
||
47 | ]); |
||
48 | if($validator->fails()) |
||
49 | { |
||
50 | throw new ValidationException($validator); |
||
51 | } |
||
52 | |||
53 | $validated = $validator->validated(); |
||
54 | $validated['amount'] = empty($values['fixed']) ? 0 : |
||
55 | $this->localeService->convertMoneyToInt((float)$validated['amount']); |
||
56 | $validated['lendable'] = isset($values['lendable']); |
||
57 | |||
58 | return $validated; |
||
59 | } |
||
61 |