1515use PhpParser \Node \Name ;
1616use PhpParser \Node \Scalar \String_ ;
1717use PHPStan \Type \ObjectType ;
18+ use Rector \Doctrine \Enum \DoctrineClass ;
1819use Rector \Rector \AbstractRector ;
1920use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
2021use Symplify \RuleDocGenerator \ValueObject \RuleDefinition ;
2122
2223/**
23- * @see
24+ * @see \Rector\Doctrine\Tests\Collection22\Rector\CriteriaOrderingConstantsDeprecations\CriteriaOrderingConstantDeprecationRectorTest
2425 */
2526final class CriteriaOrderingConstantsDeprecationRector extends AbstractRector
2627{
2728 private readonly ObjectType $ criteriaObjectType ;
2829
2930 public function __construct ()
3031 {
31- $ this ->criteriaObjectType = new ObjectType (' Doctrine\Common\Collections\Criteria ' );
32+ $ this ->criteriaObjectType = new ObjectType (DoctrineClass:: COLLECTIONS_CRITERIA );
3233 }
3334
3435 public function getRuleDefinition (): RuleDefinition
@@ -92,11 +93,7 @@ public function refactor(Node $node): ?Node
9293
9394 private function refactorClassConstFetch (ClassConstFetch $ classConstFetch ): ?Node
9495 {
95- if (! $ classConstFetch ->name instanceof Identifier) {
96- return null ;
97- }
98-
99- if (! in_array ($ classConstFetch ->name ->name , ['ASC ' , 'DESC ' ])) {
96+ if (! $ this ->isNames ($ classConstFetch ->name , ['ASC ' , 'DESC ' ])) {
10097 return null ;
10198 }
10299
@@ -110,7 +107,10 @@ private function refactorClassConstFetch(ClassConstFetch $classConstFetch): ?Nod
110107 return null ;
111108 }
112109
113- return match ($ classConstFetch ->name ->name ) {
110+ /** @var "ASC"|"DESC" $constantName */
111+ $ constantName = $ this ->getName ($ classConstFetch ->name );
112+
113+ return match ($ constantName ) {
114114 'ASC ' => new String_ ('ASC ' ),
115115 'DESC ' => new String_ ('DESC ' ),
116116 };
@@ -195,7 +195,7 @@ private function refactorMethodCall(MethodCall $methodCall): ?Node
195195 private function buildArrayItem (string $ direction , Expr |null $ key ): ArrayItem
196196 {
197197 $ classConstFetch = $ this ->nodeFactory ->createClassConstFetch (
198- ' Doctrine\Common\Collections\Order ' ,
198+ DoctrineClass:: ORDER ,
199199 match ($ direction ) {
200200 'ASC ' => 'Ascending ' ,
201201 'DESC ' => 'Descending ' ,
0 commit comments