It seems like $results can also be of type object<Traversable>. However, the property $results is declared as type array. 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.
classId{public$id;publicfunction__construct($id){$this->id=$id;}}classAccount{/** @var Id $id */public$id;}$account_id=false;if(starsAreRight()){$account_id=newId(42);}$account=newAccount();if($accountinstanceofId){$account->id=$account_id;}
Loading history...
23
13
}
24
25
/**
26
* @inheritdoc
27
*/
28
public function getResults()
29
{
30
return $this->results;
31
}
32
33
/**
34
* @inheritDoc
35
*/
36
7
public function count()
37
{
38
7
return count($this->results);
39
}
40
41
/**
42
* @inheritDoc
43
*/
44
5
public function jsonSerialize()
45
{
46
5
return $this->results;
47
}
48
49
/**
50
* @inheritDoc
51
*/
52
1
public function getIterator()
53
{
54
1
return new \ArrayIterator($this->results);
55
}
56
57
/**
58
* @param \Traversable|array $results
59
* @throws \InvalidArgumentException
60
*/
61
17
private function checkResults($results = [])
62
{
63
17
if (!is_array($results) && !$results instanceof \Traversable) {
64
4
throw new \InvalidArgumentException(sprintf(
65
4
'Argument passed to %s should be array of Traversable object',
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
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. 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.