Completed
Pull Request — master (#90)
by Arnaud
07:12 queued 36s
created

AbstractField::setConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
namespace LAG\AdminBundle\Field;
4
5
use Exception;
6
use JK\Configuration\Configuration;
7
use LAG\AdminBundle\Action\Configuration\ActionConfiguration;
8
9
abstract class AbstractField implements FieldInterface
10
{
11
    const TYPE_STRING = 'string';
12
    const TYPE_LINK = 'link';
13
    const TYPE_ARRAY = 'array';
14
    const TYPE_DATE = 'date';
15
    const TYPE_COUNT = 'count';
16
    const TYPE_ACTION = 'action';
17
    const TYPE_COLLECTION = 'collection';
18
    const TYPE_BOOLEAN = 'boolean';
19
    const TYPE_MAPPED = 'mapped';
20
    const TYPE_ACTION_COLLECTION = 'action_collection';
21
22
    /**
23
     * Field's name
24
     *
25
     * @var string
26
     */
27
    protected $name;
28
    
29
    /**
30
     * @var Configuration
31
     */
32
    protected $configuration;
33
    
34
    /**
35
     * @var ActionConfiguration
36
     */
37
    protected $actionConfiguration;
38
    
39
    /**
40
     * @var array
41
     */
42
    protected $options = [];
43
    
44
    /**
45
     * Field constructor.
46 4
     *
47
     * @param string              $name
48 4
     */
49 4
    public function __construct($name)
50
    {
51
        $this->name = $name;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getName()
58
    {
59
        return $this->name;
60
    }
61
    
62
    /**
63
     * @param string $name
64
     *
65
     * @return mixed
66
     */
67
    public function getConfiguration($name)
68
    {
69
        return $this
70
            ->configuration
71
            ->getParameter($name)
72
        ;
73
    }
74
    
75
    /**
76
     * @param ActionConfiguration $actionConfiguration
77
     */
78
    public function setActionConfiguration(ActionConfiguration $actionConfiguration)
79
    {
80 3
        $this->actionConfiguration = $actionConfiguration;
81
    }
82 3
    
83 3
    /**
84
     * @param Configuration $configuration
85
     *
86
     * @throws Exception
87
     */
88
    public function setConfiguration(Configuration $configuration)
89
    {
90
        if (!$configuration->isResolved()) {
91 2
            throw new Exception('The configuration must be resolved');
92
        }
93 2
        $this->configuration = $configuration;
94 2
        $this->options = $configuration->getParameters();
95
    }
96
}
97