Skip to content

Builder and hassers or generics #10188

Closed Answered by ondrejmirtes
robotomarvin asked this question in Support
Discussion options

You must be logged in to vote

Hi,

  1. @return above the constructor does not achieve anything.
  2. Your code is mostly fine. PHPStan rightfully complains on line 57 because you don't work with T at all in the method body so T can really be different than Entity.

But if the builder works alright from the outside type-wise I'd just use it like this while ignoring or avoiding the error in create(). PHPStan itself employs a similar pattern here https://github.com/phpstan/phpstan-src/blob/1.11.x/src/Rules/RuleErrorBuilder.php and it works around this problem with /** @var class-string<T> $className */ in the build() method.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@robotomarvin
Comment options

Answer selected by robotomarvin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
2 participants