You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Return annotations for some methods in the Model class say that the method returns T|ModelInterface<T>, where T is defined as @template T of static so the same as @template T of Model. Since Model implements ModelInterface, the return type of ModelInterface<T> is redundant and can cause problems with static analyzers if you were to try to call a method implemented in the child class of Model on the return value from methods that have this redundant type specified - for example findFirst().
To Reproduce
In the base model class of my application:
/** * @return null|T */publicstaticfunctionget(string$id)
{
$ret = static::findFirst([
'id = :id:',
'bind' => [
'id' => $id,
],
]);
if ($ret instanceof Row)
{
thrownew \LogicException("get() found multiple entries for id {$id} on model " . static::class, 500);
}
return$ret;
}
Now I could specify that the get() method returns null|T|ModelInterface<T>, but that causes problems down the line, when I try to call model specific methods on the result of get().
This is just an example for the findFirst() method, but couldn't every method that returns a ModelInterface instance be annotated to return T instead since T in this scope always implements ModelInterface?
I think that the correct annotation for this specific method should be the following:
/** * @return T|\Phalcon\Mvc\Model\Row|null */
Expected behavior
There should be no static analysis error in this code.
Details
Phalcon version: 5.8.0
Phalcon ide stubs: v5.8.0
PHP version: 8.3
PHPStan version: 1.12.6
The text was updated successfully, but these errors were encountered:
Describe the bug
Return annotations for some methods in the Model class say that the method returns
T|ModelInterface<T>
, whereT
is defined as@template T of static
so the same as@template T of Model
. SinceModel
implementsModelInterface
, the return type ofModelInterface<T>
is redundant and can cause problems with static analyzers if you were to try to call a method implemented in the child class ofModel
on the return value from methods that have this redundant type specified - for examplefindFirst()
.To Reproduce
In the base model class of my application:
Now I could specify that the
get()
method returnsnull|T|ModelInterface<T>
, but that causes problems down the line, when I try to call model specific methods on the result ofget()
.This is just an example for the
findFirst()
method, but couldn't every method that returns aModelInterface
instance be annotated to returnT
instead sinceT
in this scope always implementsModelInterface
?I think that the correct annotation for this specific method should be the following:
Expected behavior
There should be no static analysis error in this code.
Details
The text was updated successfully, but these errors were encountered: