Marked Translation
class as implementing Stringable
#307
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
v3.3
This PR adds
Stringable
as phpdoc annotation toeZ\Publish\API\Repository\Values\Translation
.Reasoning
When working with content validation it become apparent for me that this class is lacking
Stringable
interface.Ibexa\Core\FieldType\ValidationError::getTranslatableMessage
returns aTranslation
object that - judging by our implementations:Plural
&Message
- should always have__toString()
method.Of course,
Stringable
did not exist at the moment when this code was written.However, because there is no guarantee that user code that extends it does indeed implement this method, and because
Stringable
interface is available from PHP 8.0, I'm opting to mark the class as implementing it via phpdoc instead. Otherwise we could break user code or require a polyfill (which is in itself an option, due to it's lightweight nature).We cannot simply add this method to
Translation
without hiding the fact that implementation is missing, because as per php docs:I propose that for 3.3:
Translation
denoting the intent of implementingStringable
but for 4.x:
symfony/polyfill-php80
Stringable
inTranslation
__toString()
method, so that user code does not break.Checklist:
Provided automated test coverage.$ composer fix-cs
).@ezsystems/engineering-team
).