Passed
Push — develop ( cd8289...42fd9d )
by Paul
13:52
created

Text::normalizeValue()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
cc 4
nc 4
nop 0
crap 4
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules\Html\FieldElements;
4
5
use GeminiLabs\SiteReviews\Helpers\Cast;
6
use GeminiLabs\SiteReviews\Modules\Sanitizer;
7
8
class Text extends AbstractFieldElement
9
{
10 55
    public function defaults(): array
11
    {
12 55
        $settingInputSizeClass = 1 !== preg_match('/(tiny|small|regular|large)-text/', $this->field->class)
13 50
            ? 'regular-text'
14 5
            : '';
15 55
        $locations = [
16 55
            'setting' => $settingInputSizeClass,
17 55
            'widget' => 'widefat',
18 55
        ];
19 55
        return array_filter([
20 55
            'class' => $locations[$this->field->location()] ?? '',
21 55
        ]);
22
    }
23
24 55
    public function tag(): string
25
    {
26 55
        return 'input';
27
    }
28
29 53
    protected function normalizeValue(): void
30
    {
31 53
        $this->field->value = Cast::toString($this->field->value);
32 53
        if (!empty($this->field->value)) {
33 3
            return;
34
        }
35 53
        if ('review' !== $this->field->location()) {
36 36
            return;
37
        }
38 17
        if (!in_array($this->field->original_name, glsr_get_option('forms.autofill', [], 'array'))) {
39 17
            return;
40
        }
41 12
        $this->field->value = glsr(Sanitizer::class)->sanitizeUserName('', 'current_user');
42
    }
43
}
44