Total Complexity | 3 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class WordLimitRule implements Rule |
||
9 | { |
||
10 | /** |
||
11 | * The maximum amount of words the input element can reach. |
||
12 | * |
||
13 | * @var number |
||
14 | */ |
||
15 | protected $max_words; |
||
16 | |||
17 | /** |
||
18 | * Create a new rule instance. |
||
19 | * |
||
20 | * @return void |
||
21 | */ |
||
22 | public function __construct($max_words) |
||
23 | { |
||
24 | $this->max_words = $max_words; |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Determine if the validation rule passes. |
||
29 | * |
||
30 | * @param string $attribute |
||
31 | * @param mixed $value |
||
32 | * @return bool |
||
33 | */ |
||
34 | public function passes($attribute, $value) |
||
35 | { |
||
36 | $words = explode(' ', preg_replace('/\s+/', ' ', $value)); |
||
37 | return count($words) <= $this->max_words; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Get the validation error message. |
||
42 | * |
||
43 | * @return string |
||
44 | */ |
||
45 | public function message() |
||
48 | } |
||
49 | } |
||
50 |