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

Resource::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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