Conditional return: access to class members #10543
-
https://phpstan.org/r/bc57c5fc-38a9-4b2f-9dec-c331951da805 Is it somehow possible to do this? /**
* @template T of Relationship
* @template U of Entity
*/
class RelationshipProxy {
public function __construct(
/** @param U $model */private Entity $model,
/** @param T $relationship */private Relationship $relationship
) {}
/**
* @return ($this->relationship is ManyToMany ? U[] : U|null)
*/
public function resolve(): Entity|array|null {
return $this->relationship->resolve($this->model);
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
ondrejmirtes
Feb 7, 2024
Replies: 1 comment
-
You need to ask about T, not about property: https://phpstan.org/r/4990f201-cc03-4322-9ddf-2f2e2a270c13 You should also verify with |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
mbolli
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to ask about T, not about property: https://phpstan.org/r/4990f201-cc03-4322-9ddf-2f2e2a270c13
You should also verify with
\PHPStan\dumpType()
if the type behaves as expected.