Passed
Pull Request — master (#5)
by Steven
02:13
created

AllowedRecipientsValidatorStrict   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 41
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 22 4
1
<?php
2
3
namespace Digitonic\Validation\Validators;
4
5
use Digitonic\Validation\Services\AllowedRecipientsSanitiser;
6
use Illuminate\Validation\Concerns\ValidatesAttributes;
7
8
class AllowedRecipientsValidatorStrict
9
{
10
    use ValidatesAttributes;
11
12
    protected $sanitiser;
13
14 1
    public function __construct()
15
    {
16 1
        $this->sanitiser = new AllowedRecipientsSanitiser();
17 1
    }
18
19
    /**
20
     * @param $attribute
21
     * @param $value
22
     * @param $parameters
23
     * @param $validator
24
     * @return bool
25
     */
26 1
    public function validate($attribute, $value, $parameters, $validator): bool
0 ignored issues
show
Unused Code introduced by
The parameter $attribute is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
27
    {
28 1
        $phoneNumbers = collect(explode(',', $value));
29
30 1
        $invalidNumbers = [];
31
32 1
        foreach ($phoneNumbers as $phoneNumber) {
33 1
            $proto = $this->sanitiser->getPhoneNumberObject($phoneNumber);
34
35 1
            if (!$proto ||
36 1
                !in_array(
37 1
                    $this->sanitiser->getRegionCodeForNumber($proto),
38 1
                    config('digitonic.validation.allowed_mobile_origins')
39
                )
40
            ) {
41 1
                $invalidNumbers[] = $phoneNumber;
42
            }
43
44
        }
45
46 1
        return count($invalidNumbers) === 0;
47
    }
48
}
49