Passed
Push — master ( 8b9ab0...4071e1 )
by Jeroen
01:41
created

ClientOptions::connectionOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Jerodev\PhpIrcClient\Options;
4
5
class ClientOptions
6
{
7
    /** @var string[] */
8
    public $channels;
9
10
    /** @var int */
11
    public $floodProtectionDelay;
12
13
    /** @var string */
14
    public $nickname;
15
16
    /**
17
     *  @param string $nickname The nickname used on the irc server.
18
     *  @param string|string[] $channels The channels to join on connection.
19
     */
20
    public function __construct(string $nickname = null, $channels = [])
21
    {
22
        $this->nickname = $nickname;
23
24
        if (!is_array($channels)) {
25
            $channels = [$channels];
26
        }
27
        $this->channels = $channels;
0 ignored issues
show
Documentation Bug introduced by
It seems like $channels can also be of type string. 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...
28
    }
29
30
    /**
31
     *  Get the options for the IrcConnection from this collection.
32
     *
33
     *  @return ConnectionOptions
34
     */
35
    public function connectionOptions(): ConnectionOptions
36
    {
37
        $options = new ConnectionOptions();
38
        $options->floodProtectionDelay = $this->floodProtectionDelay;
39
40
        return $options;
41
    }
42
}