Completed
Pull Request — master (#76)
by Simone
15:19 queued 06:44
created

Parser::parseSchema()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
rs 8.8571
cc 5
eloc 9
nc 5
nop 0
1
<?php
2
3
/**
4
 * This file is part of sensorario/resources repository
5
 *
6
 * (c) Simone Gentili <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sensorario\Resources\Schema;
13
14
class Parser
15
{
16
    private $schema;
17
18
    private $validTypes;
19
20
    public function setSchema(array $schema)
21
    {
22
        $this->schema = $schema;
23
    }
24
25
    public function setValidTypes(array $validTypes)
26
    {
27
        $this->validTypes = $validTypes;
28
    }
29
30
    public function parseSchema()
31
    {
32
        if (!isset($this->schema['type'])) {
33
            throw new Exceptions\NoTypeException();
34
        }
35
36
        if (!in_array($this->schema['type'], $this->validTypes)) {
37
            throw new Exceptions\InvalidTypeException();
38
        }
39
40
        if (!isset($this->schema['properties'])) {
41
            throw new Exceptions\NoPropertiesException();
42
        }
43
44
        if (!isset($this->schema['id'])) {
45
            throw new Exceptions\NoIdException();
46
        }
47
    }
48
}
49