Completed
Push — master ( b82429...99ed55 )
by Xavier
01:40
created

ApiDataChecker   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 91
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 6 1
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor;
4
5
use Volan\Volan;
6
7
class ApiDataChecker
8
{
9
    const SCHEMA = [
10
        'root' => [
11
            'authors' => [
12
                '_type' => 'nested_array',
13
                'first_name' => [
14
                    '_type' => 'string'
15
                ],
16
                'last_name' => [
17
                    '_type' => 'required_string'
18
                ],
19
                'orcid' => [
20
                    '_type' => 'string'
21
                ],
22
                'affiliation' => [
23
                    '_type' => 'array'
24
                ],
25
            ],
26
            'identifiers' => [
27
                '_type' => 'nested_array',
28
                'value' => [
29
                    '_type' => 'required_string'
30
                ],
31
                'type' => [
32
                    '_type' => 'required_string'
33
                ],
34
            ],
35
            'journal' => [
36
                '_type' => 'array',
37
                'title' => [
38
                    '_type' => 'string'
39
                ],
40
                'issn' => [
41
                    '_type' => 'array'
42
                ],
43
                'publisher' => [
44
                    '_type' => 'string'
45
                ],
46
            ],
47
            'publication' => [
48
                '_type' => 'required_array',
49
                'title' => [
50
                    '_type' => 'required_string'
51
                ],
52
                'abstract' => [
53
                    '_type' => 'string'
54
                ],
55
                'url' => [
56
                    '_type' => 'required_string'
57
                ],
58
                'published_at' => [
59
                    '_type' => 'string'
60
                ],
61
            ],
62
            'types' =>  [
63
                '_type' => 'nested_array',
64
                'name' => [
65
                    '_type' => 'string'
66
                ],
67
            ],
68
            'tags' => [
69
                '_type' => 'nested_array',
70
                'name' => [
71
                    '_type' => 'string'
72
                ],
73
            ],
74
            'updates' => [
75
                '_type' => 'array',
76
                'timestamp' => [
77
                    '_type' => 'string'
78
                ],
79
                'identifier' => [
80
                    '_type' => 'array',
81
                    'doi' => [
82
                        '_type' => 'string'
83
                    ]
84
                ],
85
                'type' => [
86
                    '_type' => 'string'
87
                ]
88
            ]
89
        ]
90
    ];
91
92
    public static function check($data)
93
    {
94
        $validator = new Volan(static::SCHEMA);
95
        $result = $validator->validate($data);
96
97
        return $result;
98
    }
99
}
100