-
-
Notifications
You must be signed in to change notification settings - Fork 698
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DowngradePhp71] Add DowngradeKeysInListRector (#6170)
Co-authored-by: kaizen-ci <info@kaizen-ci.org>
- Loading branch information
1 parent
deafaf9
commit cd3725a
Showing
18 changed files
with
686 additions
and
34 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
33 changes: 33 additions & 0 deletions
33
...s/DowngradePhp71/Rector/List_/DowngradeKeysInListRector/DowngradeKeysInListRectorTest.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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class DowngradeKeysInListRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
/** | ||
* @return Iterator<SmartFileInfo> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...ts/DowngradePhp71/Rector/List_/DowngradeKeysInListRector/Fixture/as_foreach_value.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,39 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class AsForeachValue | ||
{ | ||
public function run(): void | ||
{ | ||
$data = [ | ||
["id" => 1, "name" => 'Tom'], | ||
["id" => 2, "name" => 'Fred'], | ||
]; | ||
foreach ($data as list("id" => $id1, "name" => $name1)) { | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class AsForeachValue | ||
{ | ||
public function run(): void | ||
{ | ||
$data = [ | ||
["id" => 1, "name" => 'Tom'], | ||
["id" => 2, "name" => 'Fred'], | ||
]; | ||
foreach ($data as $singleData) { | ||
$id1 = $singleData["id"]; | ||
$name1 = $singleData["name"]; | ||
} | ||
} | ||
} | ||
|
||
?> |
41 changes: 41 additions & 0 deletions
41
...s/DowngradePhp71/Rector/List_/DowngradeKeysInListRector/Fixture/as_foreach_value2.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,41 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class AsForeachValue2 | ||
{ | ||
public function run(): void | ||
{ | ||
$data = [ | ||
["id" => 1, "name" => 'Tom'], | ||
["id" => 2, "name" => 'Fred'], | ||
]; | ||
foreach ($data as list("id" => $id1, "name" => $name1)) { | ||
echo 'statement'; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class AsForeachValue2 | ||
{ | ||
public function run(): void | ||
{ | ||
$data = [ | ||
["id" => 1, "name" => 'Tom'], | ||
["id" => 2, "name" => 'Fred'], | ||
]; | ||
foreach ($data as $singleData) { | ||
$id1 = $singleData["id"]; | ||
$name1 = $singleData["name"]; | ||
echo 'statement'; | ||
} | ||
} | ||
} | ||
|
||
?> |
39 changes: 39 additions & 0 deletions
39
...Php71/Rector/List_/DowngradeKeysInListRector/Fixture/as_foreach_value_keyed_array.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,39 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class AsForeachValueKeyedArray | ||
{ | ||
public function run(): void | ||
{ | ||
$data = [ | ||
["id" => 1, "name" => 'Tom'], | ||
["id" => 2, "name" => 'Fred'], | ||
]; | ||
foreach ($data as ["id" => $id1, "name" => $name1]) { | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class AsForeachValueKeyedArray | ||
{ | ||
public function run(): void | ||
{ | ||
$data = [ | ||
["id" => 1, "name" => 'Tom'], | ||
["id" => 2, "name" => 'Fred'], | ||
]; | ||
foreach ($data as $singleData) { | ||
$id1 = $singleData["id"]; | ||
$name1 = $singleData["name"]; | ||
} | ||
} | ||
} | ||
|
||
?> |
41 changes: 41 additions & 0 deletions
41
...wngradePhp71/Rector/List_/DowngradeKeysInListRector/Fixture/as_foreach_value_used.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,41 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class AsForeachValueUsed | ||
{ | ||
public function run($singleData): void | ||
{ | ||
$data = [ | ||
["id" => 1, "name" => 'Tom'], | ||
["id" => 2, "name" => 'Fred'], | ||
]; | ||
foreach ($data as list("id" => $id1, "name" => $name1)) { | ||
echo $singleData; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class AsForeachValueUsed | ||
{ | ||
public function run($singleData): void | ||
{ | ||
$data = [ | ||
["id" => 1, "name" => 'Tom'], | ||
["id" => 2, "name" => 'Fred'], | ||
]; | ||
foreach ($data as $singleData1) { | ||
$id1 = $singleData1["id"]; | ||
$name1 = $singleData1["name"]; | ||
echo $singleData; | ||
} | ||
} | ||
} | ||
|
||
?> |
36 changes: 36 additions & 0 deletions
36
rules-tests/DowngradePhp71/Rector/List_/DowngradeKeysInListRector/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,36 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public function run(): void | ||
{ | ||
$data = [ | ||
["id" => 1, "name" => 'Tom'], | ||
["id" => 2, "name" => 'Fred'], | ||
]; | ||
list("id" => $id1, "name" => $name1) = $data[0]; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public function run(): void | ||
{ | ||
$data = [ | ||
["id" => 1, "name" => 'Tom'], | ||
["id" => 2, "name" => 'Fred'], | ||
]; | ||
$id1 = $data[0]["id"]; | ||
$name1 = $data[0]["name"]; | ||
} | ||
} | ||
|
||
?> |
38 changes: 38 additions & 0 deletions
38
...sts/DowngradePhp71/Rector/List_/DowngradeKeysInListRector/Fixture/mirror_comments.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,38 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class MirrorComments | ||
{ | ||
public function run(): void | ||
{ | ||
$data = [ | ||
["id" => 1, "name" => 'Tom'], | ||
["id" => 2, "name" => 'Fred'], | ||
]; | ||
// a comment | ||
list("id" => $id1, "name" => $name1) = $data[0]; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class MirrorComments | ||
{ | ||
public function run(): void | ||
{ | ||
$data = [ | ||
["id" => 1, "name" => 'Tom'], | ||
["id" => 2, "name" => 'Fred'], | ||
]; | ||
// a comment | ||
$id1 = $data[0]["id"]; | ||
$name1 = $data[0]["name"]; | ||
} | ||
} | ||
|
||
?> |
15 changes: 15 additions & 0 deletions
15
...wngradePhp71/Rector/List_/DowngradeKeysInListRector/Fixture/skip_not_keys_in_list.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 | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class SkipNotKeysInList | ||
{ | ||
public function run(): void | ||
{ | ||
$data = ['foo', 'bar', 'baz']; | ||
list($foo, $bar, $baz) = $data; | ||
} | ||
} | ||
|
||
?> | ||
|
15 changes: 15 additions & 0 deletions
15
...ngradePhp71/Rector/List_/DowngradeKeysInListRector/Fixture/skip_not_keys_in_list2.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 | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class SkipNotKeysInList2 | ||
{ | ||
public function run(): void | ||
{ | ||
$data = ['foo', 'bar', 'baz']; | ||
list(, $bar, $baz) = $data; | ||
} | ||
} | ||
|
||
?> | ||
|
15 changes: 15 additions & 0 deletions
15
...ngradePhp71/Rector/List_/DowngradeKeysInListRector/Fixture/skip_not_keys_in_list3.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 | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class SkipNotKeysInList3 | ||
{ | ||
public function run(): void | ||
{ | ||
$data = ['foo', 'bar', 'baz']; | ||
list($bar, $baz, ) = $data; | ||
} | ||
} | ||
|
||
?> | ||
|
36 changes: 36 additions & 0 deletions
36
...sts/DowngradePhp71/Rector/List_/DowngradeKeysInListRector/Fixture/use_keyed_array.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,36 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class UseKeyedArray | ||
{ | ||
public function run(): void | ||
{ | ||
$data = [ | ||
["id" => 1, "name" => 'Tom'], | ||
["id" => 2, "name" => 'Fred'], | ||
]; | ||
["id" => $id1, "name" => $name1] = $data[0]; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp71\Rector\List_\DowngradeKeysInListRector\Fixture; | ||
|
||
class UseKeyedArray | ||
{ | ||
public function run(): void | ||
{ | ||
$data = [ | ||
["id" => 1, "name" => 'Tom'], | ||
["id" => 2, "name" => 'Fred'], | ||
]; | ||
$id1 = $data[0]["id"]; | ||
$name1 = $data[0]["name"]; | ||
} | ||
} | ||
|
||
?> |
Oops, something went wrong.