Three   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 30
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A message() 0 3 1
A passes() 0 8 2
1
<?php
2
3
namespace LVR\CountryCode;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use League\ISO3166\Exception\DomainException;
7
use League\ISO3166\Exception\InvalidArgumentException;
0 ignored issues
show
Bug introduced by
The type League\ISO3166\Exception\InvalidArgumentException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use League\ISO3166\Exception\OutOfBoundsException;
9
use League\ISO3166\ISO3166;
10
11
class Three implements Rule
12
{
13
14
    /**
15
     * Determine if the validation rule passes.
16
     *
17
     * @param  string $attribute
18
     * @param  mixed  $value
19
     *
20
     * @return bool
21
     */
22 1
    public function passes($attribute, $value)
23
    {
24
        try {
25 1
            (new ISO3166)->alpha3($value);
26
27 1
            return true;
28 1
        } catch (DomainException | InvalidArgumentException | OutOfBoundsException $exception) {
29 1
            return false;
30
        }
31
    }
32
33
    /**
34
     * Get the validation error message.
35
     *
36
     * @return string
37
     */
38 1
    public function message()
39
    {
40 1
        return 'Invalid ISO3166-A3 country code.';
41
    }
42
}
43