Passed
Push — master ( 5e2a38...990aad )
by Andrés
03:46
created

PusherApiMessage::socketId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Andreshg112\PusherApiNotifications;
4
5
class PusherApiMessage
6
{
7
    /** @var string $channels */
8
    protected $channels = null;
9
10
    /** @var string $event */
11
    protected $event = null;
12
13
    /** @var array|string $data */
14
    protected $data = null;
15
16
    /** @var string $socketId */
17
    protected $socketId = null;
18
19
    /** @var bool $debug */
20
    protected $debug = false;
21
22
    /** @var bool $alreadyEncoded */
23
    protected $alreadyEncoded = false;
24
25
    /**
26
     * Creates the instance.
27
     *
28
     * @param array|string $channels
29
     * @param string $event
30
     * @param mixed $data
31
     * @param string|null $socketId
32
     * @param bool $debug
33
     * @param bool $alreadyEncoded
34
     */
35
    public function __construct(
36
        $channels = null,
37
        $event = null,
38
        $data = null,
39
        $socketId = null,
40
        $debug = false,
41
        $alreadyEncoded = false
42
    ) {
43
        $this->channels = $channels;
0 ignored issues
show
Documentation Bug introduced by
It seems like $channels can also be of type array. However, the property $channels is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
44
        $this->event = $event;
45
        $this->data = $data;
46
        $this->socketId = $socketId;
47
        $this->debug = $debug;
48
        $this->alreadyEncoded = $alreadyEncoded;
49
    }
50
51
    /**
52
     * A channel name or an array of channel names to publish the event on.
53
     *
54
     * @param array|string $channels
55
     * @return  $this
56
     */
57
    public function channels($channels)
58
    {
59
        $this->channels = $channels;
0 ignored issues
show
Documentation Bug introduced by
It seems like $channels can also be of type array. However, the property $channels is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
60
61
        return $this;
62
    }
63
64
    /**
65
     * Pusher event.
66
     *
67
     * @param string $event
68
     * @return  $this
69
     */
70
    public function event($event)
71
    {
72
        $this->event = $event;
73
74
        return $this;
75
    }
76
77
    /**
78
     * Event data.
79
     *
80
     * @param mixed $data
81
     * @return  $this
82
     */
83
    public function data($data)
84
    {
85
        $this->data = $data;
86
87
        return $this;
88
    }
89
90
    /**
91
     * [optional].
92
     *
93
     * @param string|null $socketId
94
     * @return  $this
95
     */
96
    public function socketId($socketId = null)
97
    {
98
        $this->socketId = $socketId;
99
100
        return $this;
101
    }
102
103
    /**
104
     * [optional].
105
     *
106
     * @param bool $debug
107
     * @return  $this
108
     */
109
    public function debug($debug = false)
110
    {
111
        $this->debug = $debug;
112
113
        return $this;
114
    }
115
116
    /**
117
     * [optional].
118
     *
119
     * @param bool $alreadyEncoded
120
     * @return  $this
121
     */
122
    public function alreadyEncoded($alreadyEncoded = false)
123
    {
124
        $this->alreadyEncoded = $alreadyEncoded;
125
126
        return $this;
127
    }
128
129
    public function toArray()
130
    {
131
        return [
132
            'channels' => $this->channels,
133
            'event' => $this->event,
134
            'data' => $this->data,
135
            'socketId' => $this->socketId,
136
            'debug' => $this->debug,
137
            'alreadyEncoded' => $this->alreadyEncoded,
138
        ];
139
    }
140
}
141