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

JsonApiBookTransformer::includeAuthor()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 12
loc 12
rs 9.4285
cc 3
eloc 6
nc 3
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