Postcode::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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