Book::transform()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LibraryCatalog\Controller\V1\Transformer;
6
7
use LibraryCatalog\Controller\TransformerException;
8
use LibraryCatalog\Controller\TransformerInterface;
9
use LibraryCatalog\Entity\Book as Entity;
10
11
class Book implements TransformerInterface
12
{
13
    /**
14
     * @param $data
15
     * @return array
16
     * @throws TransformerException
17
     */
18 4
    public function transform($data): array
19
    {
20 4
        if (!($data instanceof Entity)) {
21 1
            throw new TransformerException("Tried to transform not a Book");
22
        }
23
        return [
24 3
            'id'      => $data->id ?? null,
25 3
            'title'   => $data->title ?? null,
26 3
            'summary' => $data->summary ?? null,
27
        ];
28
    }
29
}
30