-
-
Notifications
You must be signed in to change notification settings - Fork 222
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
!!! TASK: Remove magic __toString methods from Value Objects #4156
Conversation
This changeset was created with a new rector ruleset (see neos/rector#11)
# Conflicts: # Neos.ESCR.AssetUsage/Classes/Projector/AssetUsageRepository.php
…ate of CR` Relates: #4088
As already stated in slack:
|
Fix usage in `Index` fluid template of `Neos\Neos\Controller\Service\NodesController` Relates: #4156
Despite it being merged, I would like to argue with that with strict typing no accidental type casting happens and it's not really magic to implement a language provided method that allows casting in a defined way when needed. This looks like a big PITA in fusion to me (and I don't really see the big pro for PHP either), especially remembering where to do it. I am not a huge fan. |
We're aware that this is a change that will lead to friction and we can always revert if it turns out not to be worth it.
I beg to differ and I actually found quite some bugs by making type conversions explicit. So even if we were to revert it, we would profit from the intermediate change.
Marco Pivetta summarized his reasoning in a Github comment
The
|
Just to make sure we talk about the same thing
Fair I guess I set myself up here, but I am not sure I would call that magic in the way AOP is for example, it's a language feature that allows you to cast something, I think it should and can be used, in fact I would be happy to have more of that magic in the language, comparison operator behavior for example woudl be neat, but yes, it's a magic method, in the way that it has special meaning in the language, it's pretty transparent to every tool though, from IDEs to static analyzers. I agree though that implicit casting is a problem, also that we use it for different things (JSON, collections) I agree is problematic, I mostly see it for "simple" string wrapping DTOs, like identifiers. I can follow ocramius argument only to an extend, I see what he is saying, but the first example was an implementation decision, I am casting a variable that can or cannot be the thing, not specifically an object with a __toString(), if the string cast was on the DTO itself, the problem woudln't exist, and in the second example, well the signature changed, either way the consumers need to check this. and if I need a string in the first method, I have no choice but to convert the incoming null to one either way, so IMHO both are not super convincing. Yet I get it, for PHP I don't see it as a big deal either way and am totally on board with For Fusion I rather meant the inverse direction, not in the helper (although those ifs are annoying), but rather having to remember something like |
I forgot a conclusion... The last paragraph above bothers me, but on the PHP side I am pretty fine with this. Who knows what the right move is, but I like to err on the side of implementers having a good time. |
…CommandController` Relates: #4156
@kitsunet Thanks for your elaborate response!
Yes, it is explicitly converting the type. But it is a little implicit in the meaning. But I'm more concerned about implicit casts like
Unfortunately that's only true if the calling side uses strict mode, too – I had to learn. See #4094 (comment)
Unfortunately that's the one I didn't fully grasp :) But I can phrase my concerns and you can check if they overlap or whether I'm missing something: I hope that we can cater for the remaining cases if we know them better. For example: <f:link.action action="show" arguments="{workspace: workspace.workspaceName}">... is nasty for example, because it leads to a confusing exception message of
But maybe we can improve on that? Apart from that I wonder where we actually need |
For this one I created an issue with a short example: neos/rector#12 |
For the record: I also think that
=>
(or a better name) |
Thx! Ok lets split this apart, I think I muddled the last paragraph a bit together but I think we are in agreement :)
Kinda fugly if you ask me, but I guess no way we can fix that. I think I would prefer in the future (therefore also my comments on the AsssetHelper #4155 )
Still not a perfect example but I guess you get the idea. Then another topic, the decision to shorten Identifier, we have always abstained from using shorts and I think funny enough I was in the meeting when you talked about usign id because the names are already so long and it's obvious what it means and I kinda agreed, and with modern IDEs and tooling I think there is no huge case against abbreviations etc. in names anymore, BUT in fusion if you don't have that perfect auto complete, just knowing the rule is no abbreviations did help (me) a lot. So here that decision is falling on our feet a bit IMHO. I personally would happily write the additional characters in fusion to have Finally the general usage in fusion, I guess what you write is the way to go, I personally used node.identifier quite a bit, so the change is painful to me but presenting users with nice alternatives might actually be an improvement over the status quo, so to look forward instead of backward, I guess I will dedicate myself to try and add these kind of helpers and prototypes to help users in the future as well as look at possible improvements to errors that might occur ❤️ |
IMO EEL helpers are the Anti corruption layer between the highlevel integrator world of fusion and the (hopefully) type safe world of PHP. So IMO it's totally OK to have some glue code there. And for the same reason I would prefer a Fusion code like
over
We always made exceptions to the rule ("HTML", "YAML", "PHP" to name a few) and discussed this quite a while ago. I see your point though. And if it was
We could maybe add a Nevertheless, I would like to collect those cases to see if we can solve them differently in order to stay on a higher level (like with the anchor example) |
Yep, yep, this was mostly a longer explanation of what I meant, and I am fine with this, you are right, it IS an anti corruption layer and thus okay to be not beautiful.
Note that all those examples are acronyms, so doing it for single words is new. And yes, I agree we do for those and such extending it to id can be fine, I still find it not ideal in terms of consistency, and we should make sure that we don't start doing it more IMHO. :)
It's just more consistent I guess? but again, no big deal. WAs again just more clarification.
Yep ,as said, I would look into that and try to find ways to make it easier for users. <3 |
Fix usage in `Index` fluid template of `Neos\Neos\Controller\Service\NodesController` Relates: neos/neos-development-collection#4156
Removes the magic
__toString()
method from Value Objects of theNeos.ContentRepository.Core
package and adjusts the code accordingly.This will hopefully make the code more robust because it prevents accidental type conversions and allows static type analyzers and IDEs to detect bugs more easily.
For the following string based VOs a corresponding public readonly
value
property exists:ContentDimensionId
ContentDimensionValue
ContentRepositoryId
PropertyType
NodeType
NodeTypeName
NodePath
NodeAggregateId
NodeName
PropertyName
ReferenceName
UserId
ContentStreamId
WorkspaceDescription
WorkspaceName
WorkspaceTitle
ContentStreamEventStreamName
(internal)ContentSubgraphVariationWeight
(internal)NodeRelationAnchorPoint
(internal)ContentDimensionValueSpecializationDepth
(internal)For these set-VOs, a
toJson()
method was added:DimensionSpacePoint
OriginDimensionSpacePoint
DimensionSpacePointSet
OriginDimensionSpacePointSet
ParentNodeMoveDestination
SucceedingSiblingNodeMoveDestination
NodeAggregateIds
CoverageByOrigin
(internal)OriginByCoverage
(internal)For
NodeTypeConstraints
andNodeTypeConstraintsWithSubNodeTypes
atoFilterString()
method was added.The value of
SerializedPropertyValue
Breaking Change
This is a breaking change because it requires adjustments to code that implicitly or explicitly casts the affected types to string.
Examples
The following examples have to be replaced...
...with:
Fusion
In Fusion code, the same is true, so the following has to be replaced...
...with:
Fluid
Likewise, in Fluid templates the following has to be replaced...
...with:
Related: #4133