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

HoneypotValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 15
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A performValidation() 0 6 2
A isValid() 0 5 2
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