Passed
Push — develop ( 9324e6...f3eb57 )
by Septianata
04:31
created

StoreRequest::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 10
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace App\Http\Requests\Denomination;
4
5
use App\Enum\DenominationType;
6
use App\Models\Denomination;
7
8
class StoreRequest extends AbstractRequest
9
{
10
    /**
11
     * {@inheritDoc}
12
     */
13 1
    public function rules()
14
    {
15
        return [
16 1
            'name' => 'required|string|max:255',
17
            'value' => 'required|numeric|min:0|unique:' . Denomination::class,
18
            'type' => 'required|enum:' . DenominationType::class,
19
            'quantity_per_bundle' => 'required|numeric|min:0',
20
            'minimum_order_bundle' => 'required|numeric|min:0',
21
            'maximum_order_bundle' => 'required|numeric|gte:minimum_order_bundle',
22
            'image' => 'sometimes|nullable|image',
23
        ];
24
    }
25
26
    /**
27
     * Store the image file from the incoming request.
28
     *
29
     * @param  string  $key
30
     * @return string|null
31
     */
32 1
    public function storeImage(string $key = 'image'): ?string
33
    {
34 1
        if (!$this->hasFile($key)) {
35
            return null;
36
        }
37
38 1
        $file = $this->file($key);
39
40 1
        $file->storeAs(
41 1
            Denomination::IMAGE_PATH,
42 1
            $filename = ($this->input('value') . '.' . $file->getClientOriginalExtension())
43
        );
44
45 1
        return $filename;
46
    }
47
}
48