Find the best Rector rule to solve your problem. Searching through 724 rules.
Found 9 rules:
Remove parentheses on new method call with parentheses
-(new Request())->withMethod('GET')->withUri('/hello-world');
+new Request()->withMethod('GET')->withUri('/hello-world');
Add escape argument on CSV function calls
-str_getcsv($string, separator: ',', enclosure: '"');
+str_getcsv($string, separator: ',', enclosure: '"', escape: '\\');
Replace rounding mode constant to RoundMode enum in round()
-round(1.5, 0, PHP_ROUND_HALF_UP);
+round(1.5, 0, RoundingMode::HalfAwayFromZero);
Make implicit nullable param to explicit
-function foo(string $param = null) {}
+function foo(?string $param = null) {}
Replace foreach with boolean assignment and break with array_any
-$found = false;
-foreach ($animals as $animal) {
- if (str_starts_with($animal, 'c')) {
- $found = true;
- break;
- }
-}
+$found = array_any($animals, fn($animal) => str_starts_with($animal, 'c'));
Replace foreach with assignment and break with array_find_key
$animals = ['dog', 'cat', 'cow', 'duck', 'goose'];
-$found = null;
-foreach ($animals as $idx => $animal) {
- if (str_starts_with($animal, 'c')) {
- $found = $idx;
- break;
- }
-}
+$found = array_find_key($animals, fn($animal) => str_starts_with($animal, 'c'));
Replace foreach with boolean assignment and break with array_all
-$found = true;
-foreach ($animals as $animal) {
- if (!str_starts_with($animal, 'c')) {
- $found = false;
- break;
- }
-}
+$found = array_all($animals, fn($animal) => str_starts_with($animal, 'c'));
Replace foreach with assignment and break with array_find
-$found = null;
-foreach ($animals as $animal) {
- if (str_starts_with($animal, 'c')) {
- $found = $animal;
- break;
- }
-}
+$found = array_find($animals, fn($animal) => str_starts_with($animal, 'c'));
Change @deprecated annotation to Deprecated attribute
-/**
- * @deprecated 1.0.0 Use SomeOtherClass instead
- */
+#[\Deprecated(message: 'Use SomeOtherClass instead', since: '1.0.0')]
class SomeClass
{
}