-
-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: fix proxy system and introduce psalm extension #704
Conversation
e3a9d51
to
cff5ae5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I'm unfamiliar with psalm plugins, will this be auto-registered in projects using foundry and psalm?
yes, thanks to the change in composer.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great solution, thank you!
7c764ab
to
1576c3b
Compare
828aa05
to
c00bfaf
Compare
@@ -25,17 +25,18 @@ | |||
*/ | |||
abstract class Factory | |||
{ | |||
/** @var Attributes[] */ | |||
/** @phpstan-var Attributes[] */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
everytime we use phpstan pseudo types, we should use @phpstan-
annotations because Psalm seems to not understand it
and moreover, see this comment from stof here, I think it is relevant
I'll make another PR where I fix all of the related docblocks
@@ -58,6 +56,7 @@ public function create(callable|array $attributes = []): object | |||
|
|||
$parameters = $this->normalizeParameters($parameters); | |||
$instantiator = $this->instantiator ?? Configuration::instance()->instantiator; | |||
/** @var T $object */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like PHPStorm does not only interprets methods signature (like PHPStan would do) but it events guesses stuff from the methods' body. I had really hard times to find but it basically fixes 90% of auto-complete problems 🎉
* @return T | ||
* | ||
* @throws \RuntimeException If no objects exist | ||
*/ | ||
public static function first(string $sortBy = 'id'): object | ||
{ | ||
return static::repository()->firstOrFail($sortBy); | ||
/** @var T $object */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, this is here to help auto-complete
fixes #701 #696
I've decided to completely remove all methods in
PersistenceProxyObjectFactory
, so we do not override@final
methods anymore. We still need to figure out a solution forPersistenceObjectFactory::create()
, I'll do this in a further PR.Psalm does not understand the following:
it always consider the template to be
User
and notUser&Proxy<User>
. I think because we're breaking covariance (T&Proxy<T>
is wider thanT
)I've finally decided to introduce a psalm extension, we will be able to fix nearly every typing problem in here.