-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 call, and remove usage of Criteria::ASC and Criteria::DESC where not recommended Relates to: - doctrine/collections#389; - doctrine/orm#11313 (comment) * Add check for first class callable in CriteriaOrderingRector * Refactor condition check in `CriteriaOrderingConstantsDeprecationRector` Simplify the type-checking condition by directly verifying if the criteria object type is a super type and ensuring it returns a positive result. * Replaced `toCodeString` with `toString` to get the class name
- Loading branch information
1 parent
862f2dd
commit a302734
Showing
24 changed files
with
414 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
...derByKeyToClassConstRector/Fixture/replace_order_by_asc_lower_with_class_constant.php.inc
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
...rty/OrderByKeyToClassConstRector/Fixture/replace_order_by_asc_with_class_constant.php.inc
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
...ty/OrderByKeyToClassConstRector/Fixture/replace_order_by_desc_with_class_constant.php.inc
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
...ity/Rector/Property/OrderByKeyToClassConstRector/Fixture/skip_already_using_const.php.inc
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
...-tests/CodeQuality/Rector/Property/OrderByKeyToClassConstRector/config/configured_set.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...eriaOrderingConstantsDeprecations/Fixture/criteria_aliased_to_order_mixed_content.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
use Doctrine\Common\Collections\Criteria as SomeAliasedCriteria; | ||
|
||
$crit = new SomeAliasedCriteria(); | ||
$crit->orderBy(['param1' => \Doctrine\Common\Collections\Order::Ascending, 'param2' => SomeAliasedCriteria::DESC, 'param3' => 'asc']); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
use Doctrine\Common\Collections\Criteria as SomeAliasedCriteria; | ||
|
||
$crit = new SomeAliasedCriteria(); | ||
$crit->orderBy(['param1' => \Doctrine\Common\Collections\Order::Ascending, 'param2' => \Doctrine\Common\Collections\Order::Descending, 'param3' => \Doctrine\Common\Collections\Order::Ascending]); | ||
|
||
?> |
17 changes: 17 additions & 0 deletions
17
...riaOrderingConstantsDeprecations/Fixture/criteria_to_order_from_constant_criteria.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
use Doctrine\Common\Collections\Criteria; | ||
|
||
$criteria = new Criteria(); | ||
$criteria->orderBy(['asc' => Criteria::ASC, 'desc' => Criteria::DESC]); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
use Doctrine\Common\Collections\Criteria; | ||
|
||
$criteria = new Criteria(); | ||
$criteria->orderBy(['asc' => \Doctrine\Common\Collections\Order::Ascending, 'desc' => \Doctrine\Common\Collections\Order::Descending]); | ||
|
||
?> |
17 changes: 17 additions & 0 deletions
17
...CriteriaOrderingConstantsDeprecations/Fixture/criteria_to_order_from_string_lower.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
use Doctrine\Common\Collections\Criteria; | ||
|
||
$criteria = new Criteria(); | ||
$criteria->orderBy(['asc' => 'asc', 'desc' => 'desc']); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
use Doctrine\Common\Collections\Criteria; | ||
|
||
$criteria = new Criteria(); | ||
$criteria->orderBy(['asc' => \Doctrine\Common\Collections\Order::Ascending, 'desc' => \Doctrine\Common\Collections\Order::Descending]); | ||
|
||
?> |
17 changes: 17 additions & 0 deletions
17
...CriteriaOrderingConstantsDeprecations/Fixture/criteria_to_order_from_string_upper.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
use Doctrine\Common\Collections\Criteria; | ||
|
||
$criteria = new Criteria(); | ||
$criteria->orderBy(['asc' => 'ASC', 'desc' => 'DESC']); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
use Doctrine\Common\Collections\Criteria; | ||
|
||
$criteria = new Criteria(); | ||
$criteria->orderBy(['asc' => \Doctrine\Common\Collections\Order::Ascending, 'desc' => \Doctrine\Common\Collections\Order::Descending]); | ||
|
||
?> |
17 changes: 17 additions & 0 deletions
17
...tor/CriteriaOrderingConstantsDeprecations/Fixture/criteria_to_order_mixed_content.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
use Doctrine\Common\Collections\Criteria; | ||
|
||
$criteria = new Criteria(); | ||
$criteria->orderBy(['param1' => \Doctrine\Common\Collections\Order::Ascending, 'param2' => Criteria::DESC, 'param3' => 'asc']); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
use Doctrine\Common\Collections\Criteria; | ||
|
||
$criteria = new Criteria(); | ||
$criteria->orderBy(['param1' => \Doctrine\Common\Collections\Order::Ascending, 'param2' => \Doctrine\Common\Collections\Order::Descending, 'param3' => \Doctrine\Common\Collections\Order::Ascending]); | ||
|
||
?> |
15 changes: 15 additions & 0 deletions
15
...recations/Fixture/replace_class_constant_by_string_where_not_in_criteria_order_by.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
use Doctrine\Common\Collections\Criteria; | ||
|
||
$query->addOrderBy('someParameter', Criteria::ASC); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
use Doctrine\Common\Collections\Criteria; | ||
|
||
$query->addOrderBy('someParameter', 'ASC'); | ||
|
||
?> |
12 changes: 12 additions & 0 deletions
12
...eringConstantsDeprecations/Fixture/replace_order_by_asc_lower_with_class_constant.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\Collection22\Rector\CriteriaOrderingConstantsDeprecations\Fixture; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
class ReplaceOrderByAscWithClassConstant | ||
{ | ||
#[ORM\OrderBy(['createdAt' => 'asc'])] | ||
protected \DateTimeInterface $messages; | ||
} | ||
?> |
12 changes: 12 additions & 0 deletions
12
...riaOrderingConstantsDeprecations/Fixture/replace_order_by_asc_with_class_constant.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\Collection22\Rector\CriteriaOrderingConstantsDeprecations\Fixture; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
class ReplaceOrderByAscWithClassConstant | ||
{ | ||
#[ORM\OrderBy(['createdAt' => 'ASC'])] | ||
protected \DateTimeInterface $messages; | ||
} | ||
?> |
12 changes: 12 additions & 0 deletions
12
...iaOrderingConstantsDeprecations/Fixture/replace_order_by_desc_with_class_constant.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\Collection22\Rector\CriteriaOrderingConstantsDeprecations\Fixture; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
class ReplaceOrderByAscWithClassConstant | ||
{ | ||
#[ORM\OrderBy(['createdAt' => 'desc'])] | ||
protected \DateTimeInterface $messages; | ||
} | ||
?> |
8 changes: 8 additions & 0 deletions
8
...n22/Rector/CriteriaOrderingConstantsDeprecations/Fixture/skip_already_using_const.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
use Doctrine\Common\Collections\Criteria; | ||
|
||
$criteria = new Criteria(); | ||
$criteria->orderBy(['asc' => \Doctrine\Common\Collections\Order::Ascending, 'desc' => \Doctrine\Common\Collections\Order::Descending]); | ||
|
||
?> |
7 changes: 7 additions & 0 deletions
7
...nstantsDeprecations/Fixture/skip_class_constant_ASC_where_not_related_to_criteria.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
use SomeClass; | ||
|
||
$query->addOrderBy('someParameter', SomeClass::ASC); | ||
|
||
?> |
6 changes: 6 additions & 0 deletions
6
...ector/CriteriaOrderingConstantsDeprecations/Fixture/skip_order_by_not_on_criteria.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
$object = new SomeClass(); | ||
$object->orderBy(['someType' => 'ASC']); | ||
|
||
?> |
10 changes: 10 additions & 0 deletions
10
...tests/Collection22/Rector/CriteriaOrderingConstantsDeprecations/config/configured_set.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Doctrine\Collection22\Rector\CriteriaOrderingConstantsDeprecationRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rule(CriteriaOrderingConstantsDeprecationRector::class); | ||
}; |
Oops, something went wrong.