-
Notifications
You must be signed in to change notification settings - Fork 56
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 the OrderByKeyToClassConstRector to use the new enum only in Criteria::orderBy
method calls
#336
Refactor the OrderByKeyToClassConstRector to use the new enum only in Criteria::orderBy
method calls
#336
Conversation
Still some TODO in this PR:
|
4c9ac77
to
e165ced
Compare
24ef0ce
to
b41f96c
Compare
… Criteria::orderBy method call, and remove usage of Criteria::ASC and Criteria::DESC where not recommended Relates to: - doctrine/collections#389; - doctrine/orm#11313 (comment)
b41f96c
to
f4a0882
Compare
rules/Collection22/Rector/CriteriaOrderingConstantsDeprecationRector.php
Show resolved
Hide resolved
rules/Collection22/Rector/CriteriaOrderingConstantsDeprecationRector.php
Outdated
Show resolved
Hide resolved
rules/Collection22/Rector/CriteriaOrderingConstantsDeprecationRector.php
Show resolved
Hide resolved
* @return ArrayItem | ||
*/ | ||
private function buildArrayItem(string $direction, Node\Expr|null $key): Node\Expr\ArrayItem | ||
{ |
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.
$direction need to be transformed to strtoupper first to ensure it always uppercase to 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.
Simplify the type-checking condition by directly verifying if the criteria object type is a super type and ensuring it returns a positive result.
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.
Ok, let's give it a try 👍
Thank you @julienfastre |
[ | ||
new CodeSample( | ||
<<<'CODE_SAMPLE' | ||
<?php |
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.
php open tag seems cause use statement prefixed in code example, and become:
namespace RectorPrefix202408;
use RectorPrefix202408\Doctrine\Common\Collections\Criteria;
ref rectorphp/rector@b8c4f15#diff-c260cb91d355f253688b74213c5bb7c75414832d6c18ba756b6ba3accf08964f
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.
Thank you @julienfastre 👍 |
OrderByKeyToClassConstRector::class, | ||
]); |
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.
I wonder, why not add the rule here too?
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.
This specifically for doctrine 2.2+
Since version 2.2.0 of
doctrine/collection
, the constantDoctrine\Common\Collections\Criteria
is deprecated in favor of new enum\Doctrine\Common\Collections\Order
.But this enum should only be used in invocations of
Doctrine\Common\Collection\Criteria::orderBy
method call. Other calls (in attributes, or for the same method name on object instantiating another class) should not be changed: the string'ASC'
and'DESC'
should be kept elsewhere.This PR refactor the rule which, previously, replaced all the
'ASC'
and'DESC'
by theCriteria::ASC|DESC
.After this MR:
Criteria::ASC
andCriteria::DESC
are replaced by, respectively, the string"ASC"
ans"DESC"
;Criteria::orderBy
, the usage of the"ASC"
(lowercase or uppercase),"DESC"
(lowercase or uppercase),Criteria::ASC
,Criteria::DESC
is replaced by the new enumOrder::Ascending
,Order::Descending
;The previous rule, which changed the usage of the string
"ASC"
(lowercase or uppercase) or"DESC"
(lowercase or uppercase) by the usage ofCriteria::ASC
andCriteria::DESC
is, obviously, removed.Comments and documentation supporting this change
doctrine/collections
Order enum doctrine/orm#11313 (comment)Closes #325
EDIT list the changes in a more understandable (?) way.