Passed
Push — 1.x ( ff3b18...0a635f )
by Milwad
01:00 queued 13s
created

ValidVatId::message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Milwad\LaravelValidate\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
7
class ValidVatId implements Rule
8
{
9
    /**
10
     * Check VAT ID for validity.
11
     *
12
     * @param  string  $attribute
13
     * @param  mixed  $value
14
     * @return bool
15
     */
16
    public function passes($attribute, $value)
17
    {
18
        // Remove all characters except letters and numbers
19
        $value = preg_replace('/[^a-zA-Z0-9]]/', '', $value);
20
21
        return preg_match('/[a-zA-Z]{2}[0-9]{0,12}$/', $value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return preg_match('/[a-z...[0-9]{0,12}$/', $value) returns the type integer which is incompatible with the documented return type boolean.
Loading history...
22
    }
23
24
    /**
25
     * Get the validation error message.
26
     *
27
     * @return string
28
     */
29
    public function message()
30
    {
31
        return __('validate.vat-id');
32
    }
33
}
34