-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DowngradePhp74][DowngradePhp81] Handle ArrowFunctionToAnonymousFunct…
…ionRector+DowngradeArrayIsListRector
- Loading branch information
1 parent
4056166
commit 0b70a6a
Showing
5 changed files
with
156 additions
and
0 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
28 changes: 28 additions & 0 deletions
28
tests/Issues/DowngradeArrayIsListArrowFunction/DowngradeArrayIsListArrowFunctionTest.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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Issues\DowngradeArrayIsListArrowFunction; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class DowngradeArrayIsListArrowFunctionTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
tests/Issues/DowngradeArrayIsListArrowFunction/Fixture/fixture.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,51 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Issues\DowngradeArrayIsListArrowFunction\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public function run($items) | ||
{ | ||
return array_map( | ||
fn($item) => is_array($item) && !array_is_list($item)? (object) $this->convertToObject($item) : ($item), | ||
$items | ||
); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Issues\DowngradeArrayIsListArrowFunction\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public function run($items) | ||
{ | ||
$arrayIsListFunction = function (array $array) : bool { | ||
if (function_exists('array_is_list')) { | ||
return array_is_list($array); | ||
} | ||
if ($array === []) { | ||
return true; | ||
} | ||
$current_key = 0; | ||
foreach ($array as $key => $noop) { | ||
if ($key !== $current_key) { | ||
return false; | ||
} | ||
++$current_key; | ||
} | ||
return true; | ||
}; | ||
return array_map( | ||
function ($item) use ($arrayIsListFunction) { | ||
return is_array($item) && !$arrayIsListFunction($item)? (object) $this->convertToObject($item) : ($item); | ||
}, | ||
$items | ||
); | ||
} | ||
} | ||
|
||
?> |
Oops, something went wrong.