Completed
Pull Request — master (#76)
by Simone
08:04
created

Parser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 31
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setSchema() 0 4 1
A setValidTypes() 0 4 1
A parseSchema() 0 14 4
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
}
45