Passed
Push — master ( 2da942...d633d7 )
by Paul
15:03 queued 05:40
created

CreateReviewDefaults::normalize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Defaults;
4
5
use GeminiLabs\SiteReviews\Defaults\DefaultsAbstract as Defaults;
6
use GeminiLabs\SiteReviews\Helpers\Cast;
7
8
class CreateReviewDefaults extends Defaults
9
{
10
    /**
11
     * @return array
12
     */
13
    public $mapped = [
14
        '_post_id' => 'post_id',
15
        '_referer' => 'referer',
16
        'assign_to' => 'assigned_posts', // support custom assign_to fields
17
        'category' => 'assigned_terms', // support custom category fields
18
        'author' => 'name',
19
        'pinned' => 'is_pinned',
20
    ];
21
22
    /**
23
     * @return array
24
     */
25
    public $sanitize = [
26
        'assigned_posts' => 'array-int',
27
        'assigned_terms' => 'array-int',
28
        'assigned_users' => 'array-int',
29
        'avatar' => 'url',
30
        'content' => 'text-multiline',
31
        'custom' => 'array',
32
        'date' => 'date',
33
        'email' => 'user-email',
34
        'form_id' => 'int',
35
        'ip_address' => 'text',
36
        'is_pinned' => 'bool',
37
        'name' => 'user-name',
38
        'post_id' => 'int',
39
        'rating' => 'int',
40
        'referer' => 'text',
41
        'response' => 'text',
42
        'terms' => 'bool',
43
        'terms_exist' => 'bool',
44
        'title' => 'text',
45
        'type' => 'text',
46
        'url' => 'url',
47
    ];
48
49
    /**
50
     * @return array
51
     */
52 15
    protected function defaults()
53
    {
54
        return [
55 15
            'assigned_posts' => [],
56
            'assigned_terms' => [],
57
            'assigned_users' => [],
58
            'avatar' => '',
59
            'content' => '',
60
            'custom' => [],
61
            'date' => '',
62
            'email' => '',
63
            'form_id' => '',
64
            'ip_address' => '',
65
            'is_pinned' => false,
66
            'name' => '',
67
            'post_id' => '',
68
            'rating' => '',
69
            'referer' => '',
70
            'response' => '',
71
            'terms' => true,
72
            'terms_exist' => false,
73
            'title' => '',
74
            'type' => '',
75
            'url' => '',
76
        ];
77
    }
78
79
    /**
80
     * @return array
81
     */
82 15
    protected function normalize(array $values = [])
83
    {
84 15
        if (Cast::toBool(glsr_get($values, 'terms_exist', false))) {
85 1
            $values['terms'] = !empty($values['terms']);
86
        }
87 15
        return $values;
88
    }
89
}
90