Postcode   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A passes() 0 3 1
A message() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JustSteveKing\LaravelPostcodes\Rules;
6
7
use Illuminate\Contracts\Validation\Rule;
8
use JustSteveKing\LaravelPostcodes\Service\PostcodeService;
9
10
class Postcode implements Rule
11
{
12
    protected $service;
13
14
    /**
15
     * Create a new rule instance.
16
     *
17
     * @return void
18
     */
19 12
    public function __construct(PostcodeService $service)
20
    {
21 12
        $this->service = $service;
22 12
    }
23
24
    /**
25
     * Determine if the validation rule passes.
26
     *
27
     * @param  string  $attribute
28
     * @param  mixed  $value
29
     * @return bool
30
     */
31 6
    public function passes($attribute, $value)
32
    {
33 6
        return $this->service->validate($value);
34
    }
35
36
    /**
37
     * Get the validation error message.
38
     *
39
     * @return string
40
     */
41 3
    public function message()
42
    {
43 3
        return 'The submitted postcode is not a valid UK postcode';
44
    }
45
}
46