TwitterHandleRule   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 4
c 0
b 0
f 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A passes() 0 3 1
A message() 0 3 1
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 TwitterHandleRule implements Rule
9
{
10
    /**
11
     * Validation for Twitter handlers.
12
     *
13
     * @var string
14
     */
15
    const PATTERN = '^[A-Za-z0-9_]{1,15}$';
16
17
    /**
18
     *
19
     * Twitters Terms of Service only allows ". A username can only contain
20
     * alphanumeric characters (letters A-Z, numbers 0-9) with the exception
21
     * of underscores... A username cannot be longer than 15 characters."
22
     * This regex will allow only alphanumeric characters and the underscore.
23
     * Keep this handy if we need to validate other usernames.
24
     *
25
     * @param  string  $attribute
26
     * @param  mixed   $value
27
     * @return boolean
28
     */
29
    public function passes($attribute, $value)
30
    {
31
        return preg_match('/' . self::PATTERN . '/', $value);
32
    }
33
34
    /**
35
     * Get the validation error message.
36
     *
37
     * @return string
38
     */
39
    public function message()
40
    {
41
        return Lang::get('validation.custom.twitter_handle');
42
    }
43
}
44