JsonApiBookTransformer::transform()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace League\Fractal\Test\Stub\Transformer;
4
5
use League\Fractal\TransformerAbstract;
6
7
class JsonApiBookTransformer extends TransformerAbstract
8
{
9
    protected $availableIncludes = [
10
        'author',
11
        'co-author',
12
        'author-with-meta',
13
    ];
14
15
    public function transform(array $book)
16
    {
17
        $book['year'] = (int) $book['year'];
18
        unset($book['_author']);
19
        unset($book['_co_author']);
20
21
        return $book;
22
    }
23
24 View Code Duplication
    public function includeAuthor(array $book)
0 ignored issues
show
Duplication introduced by
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...
25
    {
26
        if (!array_key_exists('_author', $book)) {
27
            return;
28
        }
29
30
        if ($book['_author'] === null) {
31
            return $this->null();
32
        }
33
34
        return $this->item($book['_author'], new JsonApiAuthorTransformer(), 'people');
35
    }
36
37 View Code Duplication
    public function includeAuthorWithMeta(array $book)
0 ignored issues
show
Duplication introduced by
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...
38
    {
39
        if (!array_key_exists('_author', $book)) {
40
            return;
41
        }
42
43
        if ($book['_author'] === null) {
44
            return $this->null();
45
        }
46
47
        return $this->item($book['_author'], new JsonApiAuthorTransformer(), 'people')
48
            ->setMeta(['foo' => 'bar']);
49
    }
50
51 View Code Duplication
    public function includeCoAuthor(array $book)
0 ignored issues
show
Duplication introduced by
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...
52
    {
53
        if (!array_key_exists('_co_author', $book)) {
54
            return;
55
        }
56
57
        if ($book['_co_author'] === null) {
58
            return $this->null();
59
        }
60
61
        return $this->item($book['_co_author'], new JsonApiAuthorTransformer(), 'people');
62
    }
63
}
64