Completed
Push — master ( 044641...e61035 )
by
unknown
05:15
created

ParameterBag::setExtra()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace MediaMonks\SonataMediaBundle\Handler;
4
5
use MediaMonks\SonataMediaBundle\Model\MediaInterface;
6
7
class ParameterBag implements ParameterBagInterface
8
{
9
    /**
10
     * @var int
11
     */
12
    protected $width;
13
14
    /**
15
     * @var int
16
     */
17
    protected $height;
18
19
    /**
20
     * @var array
21
     */
22
    protected $extra = [];
23
24
    /**
25
     * @param int $width
26
     * @param int $height
27
     * @param array $extra
28
     */
29 6
    public function __construct($width, $height, array $extra = [])
30
    {
31 6
        $this->width = $width;
32 6
        $this->height = $height;
33 6
        $this->extra = $extra;
34 6
    }
35
36
    /**
37
     * @return int
38
     */
39 4
    public function getWidth()
40
    {
41 4
        return $this->width;
42
    }
43
44
    /**
45
     * @param int $width
46
     */
47
    public function setWidth($width)
48
    {
49
        $this->width = $width;
50
    }
51
52
    /**
53
     * @return int
54
     */
55 4
    public function getHeight()
56
    {
57 4
        return $this->height;
58
    }
59
60
    /**
61
     * @param int $height
62
     */
63
    public function setHeight($height)
64
    {
65
        $this->height = $height;
66
    }
67
68
    /**
69
     * @return array
70
     */
71 4
    public function getExtra()
72
    {
73 4
        return $this->extra;
74
    }
75
76
    /**
77
     * @param array $extra
78
     */
79
    public function setExtra($extra)
80
    {
81
        $this->extra = $extra;
82
    }
83
84
    /**
85
     * @param $key
86
     * @param $value
87
     */
88 1
    public function addExtra($key, $value)
89
    {
90 1
        $this->extra[$key] = $value;
91 1
    }
92
93
    /**
94
     * @param array $defaults
95
     */
96 1
    public function setDefaults(array $defaults)
97
    {
98 1
        $this->extra = array_merge($defaults, $this->extra);
99 1
    }
100
101
    /**
102
     * @param MediaInterface $media
103
     * @return array
104
     */
105 4
    public function toArray(MediaInterface $media)
106
    {
107 4
        return array_merge($this->getExtra(), [
108 4
            'id' => $media->getId(),
109 4
            'width' => $this->getWidth(),
110 4
            'height' => $this->getHeight(),
111 4
        ]);
112
    }
113
}
114