Completed
Pull Request — master (#56)
by Simone
02:57
created

Resource::fromConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 1
eloc 9
nc 1
nop 2
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 $mandatory = [];
24
25
    protected static $defaults = [];
26
27
    public static function mandatory()
28
    {
29
        return static::$mandatory;
30
    }
31
32
    public static function allowed()
33
    {
34
        return static::$allowed;
35
    }
36
37
    public static function allowedValues()
38
    {
39
        return [];
40
    }
41
42
    public static function rules()
43
    {
44
        return [];
45
    }
46
47
    public static function defaults()
48
    {
49
        return static::$defaults;
50
    }
51
52
    public function applyConfiguration(
53
        $resourceName,
54
        Container $config
55
    ) {
56
        static::$allowed   = $config->allowed($resourceName);
57
        static::$mandatory = $config->mandatory($resourceName);
58
        static::$defaults  = $config->defaults($resourceName);
59
    }
60
61
    public static function fromConfiguration(
62
        $resourceName,
63
        Container $container
64
    ) {
65
        $resource = new self(
66
            [],
67
            new ResourcesValidator()
68
        );
69
70
        $resource->applyConfiguration(
71
            $resourceName,
72
            $container
73
        );
74
75
        return $resource;
76
    }
77
}
78