Passed
Push — develop ( c34e50...445d6d )
by Paul
06:42
created

HoneypotValidator::isValid()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules\Validator;
4
5
use GeminiLabs\SiteReviews\Modules\Honeypot;
6
7
class HoneypotValidator extends ValidatorAbstract
8
{
9
    public function isValid(): bool
10
    {
11
        $hash = glsr(Honeypot::class)->hash($this->request->form_id);
12
        $isValid = isset($this->request[$hash]) && empty($this->request[$hash]);
13
        return glsr()->filterBool('validate/honeypot', $isValid, $this->request);
14
    }
15
16
    public function performValidation(): void
17
    {
18
        if (!$this->isValid()) {
19
            $this->fail(
20
                __('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'),
21
                'The Honeypot caught a bad submission.'
22
            );
23
        }
24
    }
25
}
26