Passed
Push — master ( 6f7c4e...f6c223 )
by Paul
15:42 queued 07:15
created

CustomValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
dl 0
loc 23
ccs 7
cts 9
cp 0.7778
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A performValidation() 0 10 3
A isValid() 0 3 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules\Validator;
4
5
use GeminiLabs\SiteReviews\Helpers\Cast;
6
7
class CustomValidator extends ValidatorAbstract
8
{
9
    /**
10
     * @return bool
11
     */
12
    public function isValid()
13
    {
14
        return Cast::toBool(glsr()->filter('validate/custom', true, $this->request));
15
    }
16
17
    /**
18
     * @return void
19
     */
20 1
    public function performValidation()
21
    {
22 1
        $validated = glsr()->filter('validate/custom', true, $this->request); // value may be a string
23 1
        if (true === Cast::toBool($validated)) {
24 1
            return;
25
        }
26 1
        if (!is_string($validated)) {
27 1
            $validated = __('The review submission failed. Please notify the site administrator.', 'site-reviews');
28
        }
29 1
        $this->setErrors($validated);
30 1
    }
31
}
32