Completed
Pull Request — master (#309)
by
unknown
03:02
created

JsonApiBookTransformer::transform()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php namespace League\Fractal\Test\Stub\Transformer;
2
3
use League\Fractal\TransformerAbstract;
4
5
class JsonApiBookTransformer extends TransformerAbstract
6
{
7
    protected $availableIncludes = [
8
        'author',
9
        'co-author',
10
    ];
11
12
    public function transform(array $book)
13
    {
14
        $book['year'] = (int) $book['year'];
15
        unset($book['_author']);
16
        unset($book['_co_author']);
17
18
        return $book;
19
    }
20
21 View Code Duplication
    public function includeAuthor(array $book)
22
    {
23
        if (!array_key_exists('_author', $book)) {
24
            return;
25
        }
26
27
        if ($book['_author'] === null) {
28
            return $this->null();
29
        }
30
31
        return $this->item($book['_author'], new JsonApiAuthorTransformer(), 'people');
32
    }
33
34 View Code Duplication
    public function includeCoAuthor(array $book)
35
    {
36
        if (!array_key_exists('_co_author', $book)) {
37
            return;
38
        }
39
40
        if ($book['_co_author'] === null) {
41
            return $this->null();
42
        }
43
44
        return $this->item($book['_co_author'], new JsonApiAuthorTransformer(), 'people');
45
    }
46
}
47