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

ArrayResources   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 22 6
A countResources() 0 6 1
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