Keeping previous type in @psalm-this-out #8093
Answered
by
olleharstedt
olleharstedt
asked this question in
Q&A
-
Consider the following attempt to a type-safe query builder class: <?php
class Nil {}
/**
* @template S
* @template T
*/
class QueryBuilder
{
/**
* @psalm-this-out QueryBuilder<Nil, Nil>
*/
public function __construct()
{
}
/**
* @psalm-this-out QueryBuilder<HasSelect, null>
*/
public function select(): void
{
}
/**
* @psalm-this-out QueryBuilder<null, HasFrom>
*/
public function from(): void
{
}
public function where(): void
{
}
/**
* @psalm-if-this-is QueryBuilder<HasSelect, HasFrom>
*/
public function execute(): void
{
}
}
$qb = new QueryBuilder();
$qb->select();
$qb->from();
$qb->execute(); Now, the problem is, to properly code this, I need both functions select() and from() to know and use the incoming type, that is, what $this is. Any way to do that...? Instead of
it needs to be
|
Beta Was this translation helpful? Give feedback.
Answered by
olleharstedt
Jun 11, 2022
Replies: 1 comment
-
OK, delete this, the solution is simply
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
olleharstedt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OK, delete this, the solution is simply