ResourceAbstract   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 167
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 167
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getData() 0 4 1
A setData() 0 6 1
A getMeta() 0 4 1
A getMetaValue() 0 4 1
A getResourceKey() 0 4 1
A getTransformer() 0 4 1
A setTransformer() 0 6 1
A setMeta() 0 6 1
A setMetaValue() 0 6 1
A setResourceKey() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the League\Fractal package.
5
 *
6
 * (c) Phil Sturgeon <[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 League\Fractal\Resource;
13
14
use League\Fractal\TransformerAbstract;
15
16
abstract class ResourceAbstract implements ResourceInterface
17
{
18
    /**
19
     * Any item to process.
20
     *
21
     * @var mixed
22
     */
23
    protected $data;
24
25
    /**
26
     * Array of meta data.
27
     *
28
     * @var array
29
     */
30
    protected $meta = [];
31
32
    /**
33
     * The resource key.
34
     *
35
     * @var string
36
     */
37
    protected $resourceKey;
38
39
    /**
40
     * A callable to process the data attached to this resource.
41
     *
42
     * @var callable|TransformerAbstract|null
43
     */
44
    protected $transformer;
45
46
    /**
47
     * Create a new resource instance.
48
     *
49
     * @param mixed                             $data
50
     * @param callable|TransformerAbstract|null $transformer
51
     * @param string                            $resourceKey
52
     */
53 76
    public function __construct($data = null, $transformer = null, $resourceKey = null)
54
    {
55 76
        $this->data = $data;
56 76
        $this->transformer = $transformer;
57 76
        $this->resourceKey = $resourceKey;
58 76
    }
59
60
    /**
61
     * Get the data.
62
     *
63
     * @return mixed
64
     */
65 63
    public function getData()
66
    {
67 63
        return $this->data;
68
    }
69
70
    /**
71
     * Set the data.
72
     *
73
     * @param mixed $data
74
     *
75
     * @return $this
76
     */
77 1
    public function setData($data)
78
    {
79 1
         $this->data = $data;
80
81 1
         return $this;
82
    }
83
84
    /**
85
     * Get the meta data.
86
     *
87
     * @return array
88
     */
89 59
    public function getMeta()
90
    {
91 59
        return $this->meta;
92
    }
93
94
    /**
95
     * Get the meta data.
96
     *
97
     * @param string $metaKey
98
     *
99
     * @return array
100
     */
101 1
    public function getMetaValue($metaKey)
102
    {
103 1
        return $this->meta[$metaKey];
104
    }
105
106
    /**
107
     * Get the resource key.
108
     *
109
     * @return string
110
     */
111 63
    public function getResourceKey()
112
    {
113 63
        return $this->resourceKey;
114
    }
115
116
    /**
117
     * Get the transformer.
118
     *
119
     * @return callable|TransformerAbstract
120
     */
121 65
    public function getTransformer()
122
    {
123 65
        return $this->transformer;
124
    }
125
126
    /**
127
     * Set the transformer.
128
     *
129
     * @param callable|TransformerAbstract $transformer
130
     *
131
     * @return $this
132
     */
133 1
    public function setTransformer($transformer)
134
    {
135 1
        $this->transformer = $transformer;
136
137 1
        return $this;
138
    }
139
140
    /**
141
     * Set the meta data.
142
     *
143
     * @param array $meta
144
     *
145
     * @return $this
146
     */
147 1
    public function setMeta(array $meta)
148
    {
149 1
        $this->meta = $meta;
150
151 1
        return $this;
152
    }
153
154
    /**
155
     * Set the meta data.
156
     *
157
     * @param string $metaKey
158
     * @param mixed  $metaValue
159
     *
160
     * @return $this
161
     */
162 16
    public function setMetaValue($metaKey, $metaValue)
163
    {
164 16
        $this->meta[$metaKey] = $metaValue;
165
166 16
        return $this;
167
    }
168
169
    /**
170
     * Set the resource key.
171
     *
172
     * @param string $resourceKey
173
     *
174
     * @return $this
175
     */
176 3
    public function setResourceKey($resourceKey)
177
    {
178 3
        $this->resourceKey = $resourceKey;
179
180 3
        return $this;
181
    }
182
}
183