Completed
Push — master ( e381cf...9deca2 )
by Nate
04:12 queued 02:07
created

UserStateAttributeTrait::setUserState()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/organization/license
6
 * @link       https://www.flipboxfactory.com/software/organization/
7
 */
8
9
namespace flipbox\organizations\queries;
10
11
/**
12
 * @author Flipbox Factory <[email protected]>
13
 * @since 1.0.0
14
 */
15
trait UserStateAttributeTrait
16
{
17
    /**
18
     * The user state(s) that the resulting organizations’ users must be in.
19
     *
20
     * @var string|string[]|null
21
     */
22
    public $userState;
23
24
    /**
25
     * @param string|string[]|int|int[]|null $value
26
     * @return static The query object
27
     */
28
    public function setUserState($value)
29
    {
30
        $this->userState = $value;
0 ignored issues
show
Documentation Bug introduced by
It seems like $value can also be of type integer or array<integer,integer>. However, the property $userState is declared as type string|array<integer,string>|null. 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...
31
        return $this;
32
    }
33
34
    /**
35
     * @param string|string[]|int|int[]|null $value
36
     * @return static The query object
37
     */
38
    public function userState($value)
39
    {
40
        return $this->setUserState($value);
41
    }
42
}
43