Passed
Pull Request — master (#86)
by
unknown
02:21
created

User::setFirstName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace TelegramBot\Api\Types;
4
5
use TelegramBot\Api\BaseType;
6
use TelegramBot\Api\InvalidArgumentException;
7
use TelegramBot\Api\TypeInterface;
8
9
/**
10
 * Class User
11
 * This object represents a Telegram user or bot.
12
 *
13
 * @package TelegramBot\Api\Types
14
 */
15
class User extends BaseType implements TypeInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     *
20
     * @var array
21
     */
22
    static protected $requiredParams = ['id', 'first_name'];
23
24
    /**
25
     * {@inheritdoc}
26
     *
27
     * @var array
28
     */
29
    static protected $map = [
30
        'id' => true,
31
        'first_name' => true,
32
        'last_name' => true,
33
        'username' => true,
34
        'language_code' => true,
35
    ];
36
37
    /**
38
     * Unique identifier for this user or bot
39
     *
40
     * @var int
41
     */
42
    protected $id;
43
44
    /**
45
     * User‘s or bot’s first name
46
     *
47
     * @var string
48
     */
49
    protected $firstName;
50
51
    /**
52
     * Optional. User‘s or bot’s last name
53
     *
54
     * @var string
55
     */
56
    protected $lastName;
57
58
    /**
59
     * Optional. User‘s or bot’s username
60
     *
61
     * @var string
62
     */
63
    protected $username;
64
65
    /**
66
     * Optional. IETF language tag of the user's language
67
     *
68
     * @var string
69
     */
70
    protected $languageCode;
71
72
    /**
73
     * @return string
74
     */
75 2
    public function getFirstName()
76
    {
77 2
        return $this->firstName;
78
    }
79
80
    /**
81
     * @param string $firstName
82
     */
83 32
    public function setFirstName($firstName)
84
    {
85 32
        $this->firstName = $firstName;
86 32
    }
87
88
    /**
89
     * @return int
90
     */
91 2
    public function getId()
92
    {
93 2
        return $this->id;
94
    }
95
96
    /**
97
     * @param int $id
98
     *
99
     * @throws InvalidArgumentException
100
     */
101 34
    public function setId($id)
102
    {
103 34
        if (is_integer($id) || is_float($id)) {
104 33
            $this->id = $id;
0 ignored issues
show
Documentation Bug introduced by
It seems like $id can also be of type double. However, the property $id is declared as type integer. 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...
105 33
        } else {
106 1
            throw new InvalidArgumentException();
107
        }
108 33
    }
109
110
    /**
111
     * @return string
112
     */
113 2
    public function getLastName()
114
    {
115 2
        return $this->lastName;
116
    }
117
118
    /**
119
     * @param string $lastName
120
     */
121 32
    public function setLastName($lastName)
122
    {
123 32
        $this->lastName = $lastName;
124 32
    }
125
126
    /**
127
     * @return string
128
     */
129 2
    public function getUsername()
130
    {
131 2
        return $this->username;
132
    }
133
134
    /**
135
     * @param string $username
136
     */
137 32
    public function setUsername($username)
138
    {
139 32
        $this->username = $username;
140 32
    }
141
142
    /**
143
     * @return string
144
     */
145
    public function getLanguageCode()
146
    {
147
        return $this->languageCode;
148
    }
149
150
    /**
151
     * @param string $languageCode
152
     */
153
    public function setLanguageCode($languageCode)
154
    {
155
        $this->languageCode = $languageCode;
156
    }
157
}
158