Completed
Push — master ( f66787...5a886e )
by
unknown
04:51 queued 01:15
created

TopicTransformer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 9
Bugs 0 Features 3
Metric Value
c 9
b 0
f 3
dl 0
loc 55
rs 10
wmc 6
lcom 1
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A includeUser() 0 4 1
A includeLastReplyUser() 0 4 2
A transformData() 0 11 1
A includeReplies() 0 4 1
A includeNode() 0 4 1
1
<?php
2
3
namespace PHPHub\Transformers;
4
5
/**
6
 * Class TopicTransformer.
7
 */
8
class TopicTransformer extends BaseTransformer
9
{
10
    /**
11
     * Resources that can be included if requested.
12
     *
13
     * @var array
14
     */
15
    protected $availableIncludes = ['user', 'last_reply_user', 'replies', 'node'];
16
17
    /**
18
     * Include resources without needing it to be requested.
19
     *
20
     * @var array
21
     */
22
    protected $defaultIncludes = [];
23
24
    /**
25
     * Transform the \Topic entity.
26
     *
27
     * @param Topic $model
28
     *
29
     * @return array
30
     */
31
    public function transformData($model)
32
    {
33
        $data = $model->toArray();
34
        $data['links'] = [
35
            'details_web_view' => route('topic.web_view', $model->id),
36
            'replies_web_view' => route('replies.web_view', $model->id),
37
            'web_url'          => trim(config('app.url'), '/').'/topics/'.$model->id,
38
        ];
39
40
        return $data;
41
    }
42
43
    public function includeUser($model)
44
    {
45
        return $this->item($model->user, new UserTransformer());
0 ignored issues
show
Documentation introduced by
new \PHPHub\Transformers\UserTransformer() is of type object<PHPHub\Transformers\UserTransformer>, 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
    }
47
48
    public function includeLastReplyUser($model)
49
    {
50
        return $this->item($model->lastReplyUser ?: $model->user, new UserTransformer());
0 ignored issues
show
Documentation introduced by
new \PHPHub\Transformers\UserTransformer() is of type object<PHPHub\Transformers\UserTransformer>, 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...
51
    }
52
53
    public function includeReplies($model)
54
    {
55
        return $this->collection($model->replies, new ReplyTransformer());
0 ignored issues
show
Documentation introduced by
new \PHPHub\Transformers\ReplyTransformer() is of type object<PHPHub\Transformers\ReplyTransformer>, 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...
56
    }
57
58
    public function includeNode($model)
59
    {
60
        return $this->item($model->node, new NodeTransformer());
0 ignored issues
show
Documentation introduced by
new \PHPHub\Transformers\NodeTransformer() is of type object<PHPHub\Transformers\NodeTransformer>, 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...
61
    }
62
}
63