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

Resource::applyConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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