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

TurnstileRule::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 3
nc 3
nop 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