ArraySerializer::item()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace jin2chen\ApiBundle\Response\Serializer;
6
7
use League\Fractal\Serializer\ArraySerializer as BaseArraySerializer;
8
9
/**
10
 * Prevents array data from being assigned to a 'data' element.
11
 */
12
class ArraySerializer extends BaseArraySerializer
13
{
14
    /**
15
     * @inheritDoc
16
     */
17 2
    public function collection($resourceKey, array $data): array
18
    {
19 2
        if (!$resourceKey) {
20 2
            return $data;
21
        }
22
23 1
        return [$resourceKey => $data];
24
    }
25
26
    /**
27
     * @inheritDoc
28
     */
29 2
    public function item($resourceKey, array $data): array
30
    {
31 2
        if (!$resourceKey) {
32 2
            return $data;
33
        }
34
35 1
        return [$resourceKey => $data];
36
    }
37
}
38