GuildValidator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateItem() 0 19 2
1
<?php
2
3
namespace Siak\Tontine\Validation\Guild;
4
5
use Illuminate\Support\Facades\Validator;
6
use Siak\Tontine\Validation\AbstractValidator;
7
use Siak\Tontine\Validation\ValidationException;
8
use Spatie\ValidationRules\Rules\CountryCode;
9
use Spatie\ValidationRules\Rules\Currency as CurrencyCode;
10
11
class GuildValidator extends AbstractValidator
12
{
13
    /**
14
     * @param array $values
15
     *
16
     * @return array
17
     */
18
    public function validateItem(array $values): array
19
    {
20
        $validator = Validator::make($this->values($values), [
21
            'name' => 'required|string|min:1',
22
            'shortname' => 'required|string|between:1,25',
23
            'biography' => 'nullable|string',
24
            'email' => 'nullable|email',
25
            'phone' => 'nullable|phone:AUTO',
26
            'city' => 'nullable|string|min:1',
27
            'address' => 'nullable|string',
28
            'website' => 'nullable|string',
29
            'country_code' => ['required', new CountryCode()],
30
            'currency_code' => ['required', new CurrencyCode()],
31
        ]);
32
        if($validator->fails())
33
        {
34
            throw new ValidationException($validator);
35
        }
36
        return $validator->validated();
37
    }
38
}
39