MemberValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A validateItem() 0 16 2
1
<?php
2
3
namespace Siak\Tontine\Validation\Guild;
4
5
use Illuminate\Support\Facades\Validator;
6
use Siak\Tontine\Service\TenantService;
7
use Siak\Tontine\Validation\AbstractValidator;
8
use Siak\Tontine\Validation\ValidationException;
9
10
use function strtoupper;
11
12
class MemberValidator extends AbstractValidator
13
{
14
    /**
15
     * @param TenantService $tenantService
16
     */
17
    public function __construct(private TenantService $tenantService)
18
    {}
19
20
    /**
21
     * @param array $values
22
     *
23
     * @return array
24
     */
25
    public function validateItem(array $values): array
26
    {
27
        $country = strtoupper($this->tenantService->guild()->country_code);
28
        $validator = Validator::make($this->values($values), [
29
            'name' => 'required|string|min:1',
30
            'email' => 'nullable|email',
31
            'phone' => 'nullable|phone:AUTO,' . $country,
32
            'city' => 'nullable|string',
33
            'address' => 'nullable|string',
34
            'registered_at' => 'nullable|date_format:Y-m-d',
35
        ]);
36
        if($validator->fails())
37
        {
38
            throw new ValidationException($validator);
39
        }
40
        return $validator->validated();
41
    }
42
}
43