-
Notifications
You must be signed in to change notification settings - Fork 301
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
Add generics annotations for translatable behavior #710
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,20 @@ | |
namespace Knp\DoctrineBehaviors\Model\Translatable; | ||
|
||
use Doctrine\Common\Collections\Collection; | ||
use Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface; | ||
|
||
/** | ||
* @template T of \Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface | ||
*/ | ||
trait TranslatablePropertiesTrait | ||
{ | ||
/** | ||
* @var Collection<string, TranslationInterface> | ||
* @var Collection<string, T> | ||
*/ | ||
protected $translations; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks the PHPStorm autocomplete. Thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, it's a little too early as template with restriction ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is now working since PHPStorm introduced support for generics and this notation. |
||
|
||
/** | ||
* @see mergeNewTranslations | ||
* @var Collection<string, TranslationInterface> | ||
* @var Collection<string, T> | ||
*/ | ||
protected $newTranslations; | ||
|
||
|
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.
PHPStan is complaining here as the class is not ensured to exist.
I see two alternatives (other than ignoring the errors) :
@return class-string<T>
.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.
Which one would you prefer and why?
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.
The
class-string<>
brings value here for static analysis as it can detect when class name is invalid / not existing.I would be in favor to keep it, but it will require to add boilerplate on the default implementation code to check that the class exists before and maybe also check that's it's an implementation of
TranslationInterface
. When overriding the trait method, simply returningclass::name
will allow static analyzer to do its job and ensure the class is valid and an instance of TranslationInterface. WDYT?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.
To be honest... I don't know. The reason is I don't have time to maintain this package and give the propper care it needs.
It step up few years ago, when we used it at work and needed new PHP version support. Yet haven't used it since.
I have other OS project I want to focus on.
Saying that, I'll be stepping down as maintainer and give space someone to take over.