Test Failed
Push — master ( 31c635...ef6440 )
by Paul
07:17 queued 01:32
created

HoneypotValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 21
ccs 0
cts 12
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
    /**
10
     * @return bool
11
     */
12
    public function isValid()
13
    {
14
        $hash = glsr(Honeypot::class)->hash($this->request->form_id);
15
        $isValid = isset($this->request[$hash]) && empty($this->request[$hash]);
16
        return glsr()->filterBool('validate/honeypot', $isValid, $this->request);
17
    }
18
19
    /**
20
     * @return void
21
     */
22
    public function performValidation()
23
    {
24
        if (!$this->isValid()) {
25
            $this->setErrors(
26
                __('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'),
27
                'The Honeypot caught a bad submission.'
28
            );
29
        }
30
    }
31
}
32