Passed
Push — feature/micro-ref-email ( 2e0a82...a82660 )
by Tristan
04:08 queued 12s
created

GovernmentEmailRule::passes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace App\Services\Validation\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use Illuminate\Support\Facades\Lang;
7
8
class GovernmentEmailRule implements Rule
9
{
10
    /**
11
     * Validation for government email.
12
     *
13
     * @var string
14
     */
15
    const PATTERN = '^[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-_]+\.)+ca$';
16
17
    /**
18
     *
19
     * @param  string  $attribute
20
     * @param  mixed   $value
21
     * @return boolean
22
     */
23
    public function passes($attribute, $value)
24
    {
25
        return preg_match('/' . self::PATTERN . '/', $value);
26
    }
27
28
    /**
29
     * Get the validation error message.
30
     *
31
     * @return string
32
     */
33
    public function message()
34
    {
35
        return Lang::get('validation.email');
36
    }
37
}
38