NotificationTransformer::transformData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 3
b 0
f 1
1
<?php
2
3
namespace PHPHub\Transformers;
4
5
use PHPHub\Notification;
6
7
/**
8
 * Class NotificationTransformer.
9
 */
10
class NotificationTransformer extends BaseTransformer
11
{
12
    /**
13
     * Resources that can be included if requested.
14
     *
15
     * @var array
16
     */
17
    protected $availableIncludes = ['from_user', 'topic', 'reply'];
18
19
    /**
20
     * Transform the \Notification entity.
21
     *
22
     * @param Notification $model
23
     *
24
     * @return array
25
     */
26
    public function transformData($model)
27
    {
28
        $data = $model->toArray();
29
        $data['type_msg'] = $model->typeMessage();
0 ignored issues
show
Documentation Bug introduced by
The method typeMessage does not exist on object<PHPHub\Notification>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
30
        $data['message'] = $model->message();
0 ignored issues
show
Documentation Bug introduced by
The method message does not exist on object<PHPHub\Notification>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
31
32
        return $data;
33
    }
34
35
    public function includeFromUser($model)
36
    {
37
        return $this->item($model->fromUser, 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...
38
    }
39
40
    public function includeReply($model)
41
    {
42
        if ($model->reply === null) {
43
            return;
44
        }
45
46
        return $this->item($model->reply, 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...
47
    }
48
49
    public function includeTopic($model)
50
    {
51
        if ($model->topic === null) {
52
            return;
53
        }
54
55
        return $this->item($model->topic, new TopicTransformer());
0 ignored issues
show
Documentation introduced by
new \PHPHub\Transformers\TopicTransformer() is of type object<PHPHub\Transformers\TopicTransformer>, 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