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

PaginationDefaults::sanitize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Defaults;
4
5
class PaginationDefaults extends DefaultsAbstract
6
{
7
    /**
8
     * The values that should be cast before sanitization is run.
9
     * This is done before $sanitize and $enums.
10
     */
11
    public array $casts = [
12
        'add_args' => 'array',
13
        'base' => 'string',
14
        'before_page_number' => 'string',
15
        'format' => 'string',
16
        'next_text' => 'string',
17
        'prev_text' => 'string',
18
        'type' => 'string',
19
    ];
20
21
    /**
22
     * The values that should be sanitized.
23
     * This is done after $casts and before $enums.
24
     */
25
    public array $sanitize = [
26
        'current' => 'min:1',
27
        'end_size' => 'min:1',
28
        'mid_size' => 'min:1',
29
        'total' => 'min:0',
30
    ];
31
32 1
    protected function defaults(): array
33
    {
34 1
        return [
35 1
            'add_args' => [],
36 1
            'base' => '',
37 1
            'before_page_number' => '<span class="meta-nav screen-reader-text">'.__('Page', 'site-reviews').' </span>',
38 1
            'current' => 1,
39 1
            'end_size' => 1,
40 1
            'format' => '?'.glsr()->constant('PAGED_QUERY_VAR').'=%#%',
41 1
            'mid_size' => 1,
42 1
            'next_text' => __('Next', 'site-reviews'),
43 1
            'prev_text' => __('Previous', 'site-reviews'),
44 1
            'total' => 0,
45 1
            'type' => 'ajax',
46 1
        ];
47
    }
48
49 1
    protected function sanitize(array $values = []): array
50
    {
51 1
        $values = parent::sanitize($values);
52 1
        $values['current'] = max(1, min($values['current'], $values['total']));
53 1
        $values['end_size'] = max(0, $values['end_size']);
54 1
        $values['mid_size'] = max(1, $values['mid_size']);
55 1
        return $values;
56
    }
57
}
58