Passed
Push — master ( 68f720...5e727b )
by Paul
10:53
created

Honeypot   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 18.75%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
eloc 14
c 1
b 1
f 0
dl 0
loc 40
ccs 3
cts 16
cp 0.1875
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 13 1
A hash() 0 4 1
A verify() 0 3 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules;
4
5
use GeminiLabs\SiteReviews\Modules\Html\Builder;
6
use GeminiLabs\SiteReviews\Modules\Html\Field;
7
use GeminiLabs\SiteReviews\Modules\Style;
8
9
class Honeypot
10
{
11
    /**
12
     * @param string $formId
13
     * @return string
14
     */
15
    public function build($formId)
16
    {
17
        $honeypot = new Field([
18
            'class' => 'glsr-input glsr-input-text',
19
            'label' => esc_html__('Your review', 'site-reviews'),
0 ignored issues
show
Bug introduced by
The function esc_html__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
            'label' => /** @scrutinizer ignore-call */ esc_html__('Your review', 'site-reviews'),
Loading history...
20
            'name' => $this->hash($formId),
21
            'type' => 'text',
22
        ]);
23
        $honeypot->id = $honeypot->id.'-'.$formId;
24
        return glsr(Builder::class)->div([
25
            'class' => glsr(Style::class)->classes('field'),
26
            'style' => 'display:none;',
27
            'text' => $honeypot->getFieldLabel().$honeypot->getField(),
28
        ]);
29
    }
30
31
    /**
32
     * @param string $formId
33
     * @return string
34
     */
35 14
    public function hash($formId)
36
    {
37 14
        require_once ABSPATH.WPINC.'/pluggable.php';
0 ignored issues
show
Bug introduced by
The constant GeminiLabs\SiteReviews\Modules\WPINC was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
38 14
        return substr(wp_hash($formId, 'nonce'), -12, 8);
0 ignored issues
show
Bug introduced by
The function wp_hash was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
        return substr(/** @scrutinizer ignore-call */ wp_hash($formId, 'nonce'), -12, 8);
Loading history...
39
    }
40
41
    /**
42
     * @param string $hash
43
     * @param string $formId
44
     * @return bool
45
     */
46
    public function verify($hash, $formId)
47
    {
48
        return hash_equals($this->hash($formId), $hash);
49
    }
50
}
51