Closed stof closed 5 years ago
It has been doing that since like forever though, and I am also not sure if the output is supposed to be reversible (as in, valid for parsing) or merely just an easier way to visually render it.
Well, there is no way to get a reversible representation. which means that there is no way to get an existing Constraint object and build an argument for the VersionSelector of composer currently (which expects a string representation of the constraint). See https://github.com/composer/satis/pull/392 for such use case.
Understood, I am just saying the purpose of __toString()
is not properly documented. I will happily accept a change, but would prefer to also see consensus on what it should return at the same time, and making sure all other constraints behave in the same way.
Constraint outputs a reversible string. MultiConstraint does not in __toString
. It may do it in getPrettyString
when it was created with a pretty string (but not all of them are, only the top-level constraint of the parsing IIRC).
EmptyConstraint should return *
rather than []
to be reversible (as this is what it represents)
Might be safe to add a new method on the Constraint classes to allow retrieving a stringified but parseable version of the constraint. Not sure what the consequences of modifying __toString would be tbh. It's pretty hard to check for usage of that..
Should we close this, or do we actually want to come to a resolution?
I don't really see a strong need for this so maybe rather close.
The string representation includes additional
[ ]
around the constraint, which means that parsing the string representation as a constraint fails