Should the return type not be array|integer|double|boolean?
This check compares the return type specified in the @return annotation of a function
or method doc comment with the types returned by the function and raises an issue if they
mismatch.
The expression $models of type array|integer|double|string|boolean is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
$collection=json_decode($data,true);if(!is_array($collection)){thrownew\RuntimeException('$collection must be an array.');}foreach($collectionas$item){/** ... */}
If you are sure that the expression is traversable, you might want to add a
doc comment cast to improve IDE auto-completion and static analysis:
Should the return type not be SS_HTTPResponse|null|CMSForm?
This check compares the return type specified in the @return annotation of a function
or method doc comment with the types returned by the function and raises an issue if they
mismatch.
It is generally recommended to explicitly declare the visibility for methods.
Adding explicit visibility (private, protected, or public) is generally
recommend to communicate to other developers how, and from where this method
is intended to be used.
The method Fields does only exist in CMSForm, but not in SS_HTTPResponse.
It seems like the method you are trying to call exists only in some of the
possible types.
Let’s take a look at an example:
classA{publicfunctionfoo(){}}classBextendsA{publicfunctionbar(){}}/** * @param A|B $x */functionsomeFunction($x){$x->foo();// This call is fine as the method exists in A and B.$x->bar();// This method only exists in B and might cause an error.}
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.