Author::transform()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 12
ccs 9
cts 9
cp 1
crap 2
rs 9.9666
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\Author as Entity;
10
11
class Author implements TransformerInterface
12
{
13
    /**
14
     * @param $data
15
     * @return array
16
     * @throws TransformerException
17
     */
18 5
    public function transform($data): array
19
    {
20 5
        if (!($data instanceof Entity)) {
21 1
            throw new TransformerException("Tried to transform not an Author");
22
        }
23
        return [
24 4
            'id'        => $data->id ?? null,
25 4
            'name'      => $data->name ?? null,
26 4
            'birthdate' => $data->birthdate ?? null,
27 4
            'deathdate' => $data->deathdate ?? null,
28 4
            'biography' => $data->biography ?? null,
29 4
            'summary'   => $data->summary ?? null,
30
        ];
31
    }
32
}
33