ClientOptions   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 15
dl 0
loc 65
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A connectionOptions() 0 6 1
1
<?php
2
3
namespace Jerodev\PhpIrcClient\Options;
4
5
class ClientOptions
6
{
7
    /**
8
     *  Automaticly connect to the irc server when creating the client.
9
     *
10
     *  @var bool
11
     */
12
    public $autoConnect;
13
14
    /**
15
     *  Automaticly rejoin a channel when kicked.
16
     *
17
     *  @var bool
18
     */
19
    public $autoRejoin;
20
21
    /**
22
     *  The channel names to join when connecting.
23
     *
24
     *  @var string[]
25
     */
26
    public $channels;
27
28
    /**
29
     *  The amount of time in milliseconds to wait between sending messages to the irc server.
30
     *
31
     *  @var int
32
     */
33
    public $floodProtectionDelay;
34
35
    /**
36
     *  The nickname to use on the server.
37
     *
38
     *  @var null|string
39
     */
40
    public $nickname;
41
42
    /**
43
     *  @param string $nickname The nickname used on the irc server.
44
     *  @param string|string[] $channels The channels to join on connection.
45
     */
46
    public function __construct(?string $nickname = null, $channels = [])
47
    {
48
        $this->nickname = $nickname;
49
50
        if (!is_array($channels)) {
51
            $channels = [$channels];
52
        }
53
        $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...
54
55
        $this->autoRejoin = false;
56
        $this->autoConnect = false;
57
    }
58
59
    /**
60
     *  Get the options for the IrcConnection from this collection.
61
     *
62
     *  @return ConnectionOptions
63
     */
64
    public function connectionOptions(): ConnectionOptions
65
    {
66
        $options = new ConnectionOptions();
67
        $options->floodProtectionDelay = $this->floodProtectionDelay;
68
69
        return $options;
70
    }
71
}
72