Passed
Push — master ( 6498f8...9717d5 )
by Darko
09:46
created

TurnstileRule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 15
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 10 3
1
<?php
2
3
namespace App\Rules;
4
5
use App\Services\TurnstileService;
6
use Closure;
7
use Illuminate\Contracts\Validation\ValidationRule;
8
9
class TurnstileRule implements ValidationRule
10
{
11
    /**
12
     * Run the validation rule.
13
     */
14
    public function validate(string $attribute, mixed $value, Closure $fail): void
15
    {
16
        if (empty($value)) {
17
            $fail('Please complete the captcha verification.');
18
19
            return;
20
        }
21
22
        if (! TurnstileService::verify($value)) {
23
            $fail('The captcha verification failed. Please try again.');
24
        }
25
    }
26
}
27