Completed
Push — master ( ebc071...9dcd83 )
by Tobias
29:49 queued 29:28
created

test/Stub/Transformer/JsonApiBookTransformer.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
        'author-with-meta',
11
    ];
12
13
    public function transform(array $book)
14
    {
15
        $book['year'] = (int) $book['year'];
16
        unset($book['_author']);
17
        unset($book['_co_author']);
18
19
        return $book;
20
    }
21
22 View Code Duplication
    public function includeAuthor(array $book)
23
    {
24
        if (!array_key_exists('_author', $book)) {
25
            return;
26
        }
27
28
        if ($book['_author'] === null) {
29
            return $this->null();
30
        }
31
32
        return $this->item($book['_author'], new JsonApiAuthorTransformer(), 'people');
33
    }
34
35 View Code Duplication
    public function includeAuthorWithMeta(array $book)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        if (!array_key_exists('_author', $book)) {
38
            return;
39
        }
40
41
        if ($book['_author'] === null) {
42
            return $this->null();
43
        }
44
45
        return $this->item($book['_author'], new JsonApiAuthorTransformer(), 'people')
46
            ->setMeta(['foo' => 'bar']);
47
    }
48
49 View Code Duplication
    public function includeCoAuthor(array $book)
50
    {
51
        if (!array_key_exists('_co_author', $book)) {
52
            return;
53
        }
54
55
        if ($book['_co_author'] === null) {
56
            return $this->null();
57
        }
58
59
        return $this->item($book['_co_author'], new JsonApiAuthorTransformer(), 'people');
60
    }
61
}
62