Completed
Push — master ( 48f773...027340 )
by
unknown
08:02
created

AbstractMediaParameterBag::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace MediaMonks\SonataMediaBundle\ParameterBag;
4
5
use MediaMonks\SonataMediaBundle\Model\MediaInterface;
6
7
abstract class AbstractMediaParameterBag implements ParameterBagInterface
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $extra = [];
13
14
    /**
15
     * @param array $extra
16
     */
17 18
    public function __construct(array $extra = [])
18
    {
19 18
        $this->extra = $extra;
20 18
    }
21
22
    /**
23
     * @return array
24
     */
25 14
    public function getExtra()
26
    {
27 14
        return $this->extra;
28
    }
29
30
    /**
31
     * @param array $extra
32
     */
33
    public function setExtra($extra)
34
    {
35
        $this->extra = $extra;
36
    }
37
38
    /**
39
     * @param $key
40
     * @param $value
41
     */
42 8
    public function addExtra($key, $value)
43
    {
44 8
        $this->extra[$key] = $value;
45 8
    }
46
47
    /**
48
     * @param $key
49
     * @return bool
50
     */
51 6
    public function hasExtra($key)
52
    {
53 6
        return isset($this->extra[$key]);
54
    }
55
56
    /**
57
     * @param $key
58
     */
59 8
    public function removeExtra($key)
60
    {
61 8
        unset($this->extra[$key]);
62 8
    }
63
64
    /**
65
     * @param array $defaults
66
     */
67 6
    public function setDefaults(array $defaults)
68
    {
69 6
        $this->extra = array_merge($defaults, $this->extra);
70 6
    }
71
72
    /**
73
     * @param MediaInterface $media
74
     * @return array
75
     */
76 14
    public function toArray(MediaInterface $media)
77
    {
78 14
        return array_merge($this->getExtra(), [
79 14
            'id' => $media->getId()
80
        ]);
81
    }
82
}
83