JsonApiBookTransformer::includeCoAuthor()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
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
        '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)
0 ignored issues
show
Duplication introduced by Felix Kiss
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...
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
Duplication introduced by Rahmat Awaludin
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')
0 ignored issues
show
Documentation introduced by Thijs van den Anker
new \League\Fractal\Test...nApiAuthorTransformer() is of type object<League\Fractal\Te...onApiAuthorTransformer>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
            ->setMeta(['foo' => 'bar']);
47
    }
48
49 View Code Duplication
    public function includeCoAuthor(array $book)
0 ignored issues
show
Duplication introduced by Ryan Tablada
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...
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