Schema   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 79
dl 0
loc 137
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 6 1
A getDataTypes() 0 3 1
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor;
4
5
use Volan\ValidatorResult;
6
use Volan\Volan;
7
8
class Schema
9
{
10
    /**
11
     * Array validation schema.
12
     */
13
    const SCHEMA = [
14
        'root' => [
15
            '_source' => [
16
                '_type' => 'string',
17
            ],
18
            'authors' => [
19
                '_type' => 'nested_array',
20
                'first_name' => [
21
                    '_type' => 'string',
22
                ],
23
                'last_name' => [
24
                    '_type' => 'required_string',
25
                ],
26
                'orcid' => [
27
                    '_type' => 'string',
28
                ],
29
                'email' => [
30
                    '_type' => 'string',
31
                ],
32
                'sequence' => [
33
                    '_type' => 'string',
34
                ],
35
                'affiliation' => [
36
                    '_type' => 'array',
37
                    'name' => [
38
                        '_type' => 'string',
39
                    ],
40
                ],
41
            ],
42
            'identifiers' => [
43
                '_type' => 'nested_array',
44
                'value' => [
45
                    '_type' => 'required_string',
46
                ],
47
                'type' => [
48
                    '_type' => 'required_string',
49
                ],
50
            ],
51
            'journal' => [
52
                '_type' => 'required_array',
53
                'title' => [
54
                    '_type' => 'string',
55
                ],
56
                'issn' => [
57
                    '_type' => 'array',
58
                ],
59
                'publisher' => [
60
                    '_type' => 'string',
61
                ],
62
            ],
63
            'publication' => [
64
                '_type' => 'required_array',
65
                'title' => [
66
                    '_type' => 'required_string',
67
                ],
68
                'abstract' => [
69
                    '_type' => 'string',
70
                ],
71
                'url' => [
72
                    '_type' => 'required_string',
73
                ],
74
                'published_at' => [
75
                    '_type' => 'string',
76
                ],
77
            ],
78
            'types' => [
79
                '_type' => 'nested_array',
80
                'name' => [
81
                    '_type' => 'string',
82
                ],
83
            ],
84
            'tags' => [
85
                '_type' => 'nested_array',
86
                'name' => [
87
                    '_type' => 'string',
88
                ],
89
            ],
90
            'links' => [
91
                '_type' => 'nested_array',
92
                'has_preprint' => [
93
                    '_type' => 'string',
94
                ],
95
                'is_preprint_of' => [
96
                    '_type' => 'string',
97
                ],
98
            ],
99
            'affiliations' => [
100
                '_type' => 'nested_array',
101
                'name' => [
102
                    '_type' => 'string',
103
                ],
104
            ],
105
            'updates' => [
106
                '_type' => 'nested_array',
107
                'timestamp' => [
108
                    '_type' => 'required_number',
109
                ],
110
                'identifier' => [
111
                    '_type' => 'required_array',
112
                    'doi' => [
113
                        '_type' => 'string',
114
                    ],
115
                    'pubmed' => [
116
                        '_type' => 'string',
117
                    ],
118
                ],
119
                'type' => [
120
                    '_type' => 'required_string',
121
                ],
122
            ],
123
        ],
124
    ];
125
126
    /**
127
     * Validate the data against Schema.
128
     *
129
     * @param  $data
130
     */
131
    public static function validate($data): ValidatorResult
132
    {
133
        $validator = new Volan(static::SCHEMA);
134
        $result = $validator->validate($data);
135
136
        return $result;
137
    }
138
139
    /**
140
     * Get the main data types from Schema.
141
     */
142
    public static function getDataTypes(): array
143
    {
144
        return array_slice(array_keys(self::SCHEMA['root']), 1);
145
    }
146
}
147