Completed
Push — master ( 6f7871 )
by Simone
02:56
created

Resource   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 21
Bugs 2 Features 5
Metric Value
wmc 10
c 21
b 2
f 5
lcom 1
cbo 2
dl 0
loc 75
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A mandatory() 0 4 1
A allowed() 0 4 1
A allowedValues() 0 4 1
A rules() 0 4 1
A defaults() 0 4 1
A rewrites() 0 4 1
A ranges() 0 4 1
A applyConfiguration() 0 21 3
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;
13
14
use RuntimeException;
15
use Sensorario\Resources\Validators\ResourcesValidator;
16
17
class Resource
18
    extends MagicResource
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
Coding Style introduced by
Expected 0 spaces between "MagicResource" and comma; 1 found
Loading history...
19
    implements Interfaces\ResourceInterface
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
20
{
21
    protected $allowed = [];
22
23
    protected $allowedValues = [];
24
25
    protected $mandatory = [];
26
27
    protected $defaults = [];
28
29
    protected $rules = [];
30
31
    protected $rewrites = [];
32
33
    protected $ranges = [];
34
35
    public function mandatory()
36
    {
37
        return $this->mandatory;
38
    }
39
40
    public function allowed()
41
    {
42
        return $this->allowed;
43
    }
44
45
    public function allowedValues()
46
    {
47
        return $this->allowedValues;
48
    }
49
50
    public function rules()
51
    {
52
        return $this->rules;
53
    }
54
55
    public function defaults()
56
    {
57
        return $this->defaults;
58
    }
59
60
    public function rewrites()
61
    {
62
        return $this->rewrites;
63
    }
64
65
    public function ranges()
66
    {
67
        return $this->ranges;
68
    }
69
70
    public function applyConfiguration(
71
        Configurator $configurator
72
    ) {
73
        $this->allowed       = $configurator->allowed();
74
        $this->mandatory     = $configurator->mandatory();
75
        $this->defaults      = $configurator->defaults();
76
        $this->rules         = $configurator->rules();
77
        $this->allowedValues = $configurator->allowedValues();
78
        $this->rewrites      = $configurator->rewrites();
79
        $this->ranges        = $configurator->ranges();
80
81
        if ($configurator->globals()) {
82
            $globals = $configurator->globals();
83
            if (isset($globals['allowed'])) {
84
                $this->allowed = array_merge(
85
                    $this->allowed,
86
                    $globals['allowed']
87
                );
88
            }
89
        }
90
    }
91
}
92