Completed
Pull Request — master (#56)
by Simone
03:09
created

ArrayResources::countResources()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Sensorario\Resources;
4
5
use \RuntimeException;
6
7
final class ArrayResources
8
{
9
    private $resources;
10
11
    public function __construct(array $resources)
12
    {
13
        if (!isset($resources['resources'])) {
14
            throw new RuntimeException(
15
                ''
16
            );
17
        }
18
19
        foreach ($resources['resources'] as $item) {
20
            if (isset($item['constraints'])) {
21
                foreach ($item['constraints'] as $name => $value) {
22
                    if (!in_array($name, [])) {
23
                        throw new RuntimeException(
24
                            'Invalid constraint'
25
                        );
26
                    }
27
                }
28
            }
29
        }
30
31
        $this->resources = $resources;
32
    }
33
34
    public function countResources()
35
    {
36
        return count(
37
            $this->resources['resources']
38
        );
39
    }
40
}
41