Completed
Pull Request — master (#306)
by Benoît
04:15
created

GenericBookTransformer::includeAuthor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php namespace League\Fractal\Test\Stub\Transformer;
2
3
use League\Fractal\TransformerAbstract;
4
5
class GenericBookTransformer extends TransformerAbstract
6
{
7
    protected $availableIncludes = [
8
        'author',
9
    ];
10
11
    public function transform(array $book)
12
    {
13
        $book['year'] = (int) $book['year'];
14
        unset($book['_author']);
15
16
        return $book;
17
    }
18
19
    public function includeAuthor(array $book)
20
    {
21
        if (! isset($book['_author'])) {
22
            return;
23
        }
24
25
        return $this->item($book['_author'], new GenericAuthorTransformer(), 'author');
26
    }
27
}
28