Completed
Push — master ( 657524...bde6a9 )
by Simone
19s
created

Resource   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 15
Bugs 1 Features 5
Metric Value
wmc 7
c 15
b 1
f 5
lcom 1
cbo 3
dl 0
loc 68
rs 10

7 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 applyConfiguration() 0 10 1
A fromConfiguration() 0 17 1
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 static $allowed = [];
22
23
    protected static $allowedValues = [];
24
25
    protected static $mandatory = [];
26
27
    protected static $defaults = [];
28
29
    protected static $rules = [];
30
31
    public static function mandatory()
32
    {
33
        return static::$mandatory;
34
    }
35
36
    public static function allowed()
37
    {
38
        return static::$allowed;
39
    }
40
41
    public static function allowedValues()
42
    {
43
        return static::$allowedValues;
44
    }
45
46
    public static function rules()
47
    {
48
        return static::$rules;
49
    }
50
51
    public static function defaults()
52
    {
53
        return static::$defaults;
54
    }
55
56
    public function applyConfiguration(
57
        $resourceName,
58
        Container $config
59
    ) {
60
        static::$allowed       = $config->allowed($resourceName);
61
        static::$mandatory     = $config->mandatory($resourceName);
62
        static::$defaults      = $config->defaults($resourceName);
63
        static::$rules         = $config->rules($resourceName);
64
        static::$allowedValues = $config->allowedValues($resourceName);
65
    }
66
67
    public static function fromConfiguration(
68
        $resourceName,
69
        Container $container
70
    ) {
71
        $resource = new self(
72
            [],
73
            new ResourcesValidator(),
74
            $validationRequired = false
75
        );
76
77
        $resource->applyConfiguration(
78
            $resourceName,
79
            $container
80
        );
81
82
        return $resource;
83
    }
84
}
85