Passed
Push — dev ( 69b6f1...3c5138 )
by Chris
12:29 queued 05:29
created

TwitterHandleRule::message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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 alphamumeric characters and the underscore.
23
     * Keep this handy if we need to validate other usernames.
24
     *
25
     * @param  string  $attribute
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
26
     * @param  mixed   $value
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 3 found
Loading history...
27
     * @return boolean
28
     */
29
    public function passes($attribute, $value)
1 ignored issue
show
introduced by
Method \App\Services\Validation\Rules\TwitterHandleRule::passes() does not have parameter type hint for its parameter $attribute but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \App\Services\Validation\Rules\TwitterHandleRule::passes() does not have return type hint for its return value but it should be possible to add it based on @return annotation "boolean".
Loading history...
Coding Style introduced by
Type hint "string" missing for $attribute
Loading history...
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()
0 ignored issues
show
introduced by
Method \App\Services\Validation\Rules\TwitterHandleRule::message() does not have return type hint for its return value but it should be possible to add it based on @return annotation "string".
Loading history...
40
    {
41
        return Lang::get('validation.custom.twitter_handle');
42
    }
43
}
44