Passed
Push — master ( f510e9...9822a2 )
by Paul
10:29
created

SiteReviewsDefaults   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 4
eloc 42
dl 0
loc 79
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A defaults() 0 21 1
A normalize() 0 8 3
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Defaults;
4
5
use GeminiLabs\SiteReviews\Defaults\DefaultsAbstract as Defaults;
6
use GeminiLabs\SiteReviews\Helper;
7
use GeminiLabs\SiteReviews\Helpers\Arr;
8
9
class SiteReviewsDefaults extends Defaults
10
{
11
    /**
12
     * @var array
13
     */
14
    public $casts = [
15
        'debug' => 'bool',
16
        'display' => 'int',
17
        'hide' => 'array',
18
        'page' => 'int',
19
        'rating' => 'int',
20
        'schema' => 'bool',
21
    ];
22
23
    /**
24
     * @var string[]
25
     */
26
    public $guarded = [
27
        'fallback',
28
        'title',
29
    ];
30
31
    /**
32
     * @var array
33
     */
34
    public $mapped = [
35
        'assigned_to' => 'assigned_posts',
36
        'category' => 'assigned_terms',
37
        'count' => 'display', // @deprecated in v4.1.0
38
        'per_page' => 'display',
39
        'user' => 'assigned_users',
40
    ];
41
42
    /**
43
     * @var array
44
     */
45
    public $sanitize = [
46
        'id' => 'id',
47
    ];
48
49
    /**
50
     * @return array
51
     */
52 8
    protected function defaults()
53
    {
54
        return [
55 8
            'assigned_posts' => '',
56
            'assigned_terms' => '',
57
            'assigned_users' => '',
58
            'class' => '',
59
            'display' => 5,
60
            'debug' => false,
61
            'fallback' => '',
62
            'hide' => [],
63
            'id' => '',
64
            'offset' => '',
65
            'page' => 1,
66
            'pagination' => false,
67
            'rating' => 0,
68
            'rating_field' => 'rating', // used for custom rating fields
69
            'schema' => false,
70
            'terms' => '',
71
            'title' => '',
72
            'type' => 'local',
73
        ];
74
    }
75
76
    /**
77
     * Normalize provided values, this always runs first.
78
     * @return array
79
     */
80 8
    protected function normalize(array $values = [])
81
    {
82 8
        foreach ($this->mapped as $old => $new) {
83 8
            if ('custom' === Arr::get($values, $old)) {
84
                $values[$old] = Arr::get($values, $new);
85
            }
86
        }
87 8
        return $values;
88
    }
89
}
90