-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DowngradePhp54] Add DowngradeThisInClosureRector (#1995)
- Loading branch information
1 parent
e077d7c
commit 9f9b29c
Showing
10 changed files
with
437 additions
and
3 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
33 changes: 33 additions & 0 deletions
33
...adePhp54/Rector/Closure/DowngradeThisInClosureRector/DowngradeThisInClosureRectorTest.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\DowngradePhp54\Rector\Closure\DowngradeThisInClosureRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class DowngradeThisInClosureRectorTest 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'; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...s/DowngradePhp54/Rector/Closure/DowngradeThisInClosureRector/Fixture/deep_closure.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,46 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp54\Rector\Closure\DowngradeThisInClosureRector\Fixture; | ||
|
||
class DeepClosure | ||
{ | ||
public $property = 'test'; | ||
|
||
public function run() | ||
{ | ||
$function = function () { | ||
$f = function () { | ||
echo $this->property; | ||
}; | ||
$f(); | ||
}; | ||
|
||
$function(); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp54\Rector\Closure\DowngradeThisInClosureRector\Fixture; | ||
|
||
class DeepClosure | ||
{ | ||
public $property = 'test'; | ||
|
||
public function run() | ||
{ | ||
$self = $this; | ||
$function = function () use($self) { | ||
$f = function () use($self) { | ||
echo $self->property; | ||
}; | ||
$f(); | ||
}; | ||
|
||
$function(); | ||
} | ||
} | ||
|
||
?> |
40 changes: 40 additions & 0 deletions
40
...-tests/DowngradePhp54/Rector/Closure/DowngradeThisInClosureRector/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,40 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp54\Rector\Closure\DowngradeThisInClosureRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public $property = 'test'; | ||
|
||
public function run() | ||
{ | ||
$function = function () { | ||
echo $this->property; | ||
}; | ||
|
||
$function(); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp54\Rector\Closure\DowngradeThisInClosureRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public $property = 'test'; | ||
|
||
public function run() | ||
{ | ||
$self = $this; | ||
$function = function () use($self) { | ||
echo $self->property; | ||
}; | ||
|
||
$function(); | ||
} | ||
} | ||
|
||
?> |
42 changes: 42 additions & 0 deletions
42
...adePhp54/Rector/Closure/DowngradeThisInClosureRector/Fixture/self_variable_exists.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,42 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp54\Rector\Closure\DowngradeThisInClosureRector\Fixture; | ||
|
||
class SelfVariableExists | ||
{ | ||
public $property = 'test'; | ||
|
||
public function run() | ||
{ | ||
$self = 'test'; | ||
$function = function () { | ||
echo $this->property; | ||
}; | ||
|
||
$function(); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp54\Rector\Closure\DowngradeThisInClosureRector\Fixture; | ||
|
||
class SelfVariableExists | ||
{ | ||
public $property = 'test'; | ||
|
||
public function run() | ||
{ | ||
$self = 'test'; | ||
$self2 = $this; | ||
$function = function () use($self2) { | ||
echo $self2->property; | ||
}; | ||
|
||
$function(); | ||
} | ||
} | ||
|
||
?> |
22 changes: 22 additions & 0 deletions
22
...Php54/Rector/Closure/DowngradeThisInClosureRector/Fixture/skip_in_anonymous_class.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,22 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp54\Rector\Closure\DowngradeThisInClosureRector\Fixture; | ||
|
||
class SkipInAnonymousClass | ||
{ | ||
public $property = 'test'; | ||
|
||
public function run() | ||
{ | ||
$function = function () { | ||
new class { | ||
public function test() | ||
{ | ||
echo $this->property; | ||
} | ||
}; | ||
}; | ||
|
||
$function(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...dePhp54/Rector/Closure/DowngradeThisInClosureRector/Fixture/skip_private_property.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 | ||
|
||
namespace Rector\Tests\DowngradePhp54\Rector\Closure\DowngradeThisInClosureRector\Fixture; | ||
|
||
class SkipPrivateProperty | ||
{ | ||
private $property = 'test'; | ||
|
||
public function run() | ||
{ | ||
$function = function () { | ||
echo $this->property; | ||
}; | ||
|
||
$function(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...sts/DowngradePhp54/Rector/Closure/DowngradeThisInClosureRector/config/configured_rule.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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\DowngradePhp54\Rector\Closure\DowngradeThisInClosureRector; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$services = $containerConfigurator->services(); | ||
$services->set(DowngradeThisInClosureRector::class); | ||
}; |
Oops, something went wrong.