Completed
Push — master ( e03925...d40975 )
by Matt
17s queued 12s
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)
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
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)
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