-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Downgradephp81][DowngradePhp80] Handle No scope crash on DowngradeSe…
…tAccessibleReflectionPropertyRector + DowngradeMatchToSwitchRector (#5183) * [Downgradephp81][DowngradePhp80] Handle No scope crash on DowngradeSetAccessibleReflectionPropertyRector + DowngradeMatchToSwitchRector * fix * clean up
- Loading branch information
1 parent
11c66a7
commit 369f16a
Showing
4 changed files
with
91 additions
and
1 deletion.
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
44 changes: 44 additions & 0 deletions
44
tests/Issues/ScopeNotAvailable/FixtureMatchToSwitchReflection/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,44 @@ | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\ScopeNotAvailable\FixtureMatchToSwitchReflection; | ||
|
||
final class ServiceValueResolver | ||
{ | ||
public function resolve(Request $request, ArgumentMetadata $argument): array | ||
{ | ||
try { | ||
|
||
} catch (\RuntimeException $e) { | ||
|
||
$r = new \ReflectionProperty($e, 'message'); | ||
$r->setValue($e, $message); | ||
|
||
throw $e; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\ScopeNotAvailable\FixtureMatchToSwitchReflection; | ||
|
||
final class ServiceValueResolver | ||
{ | ||
public function resolve(Request $request, ArgumentMetadata $argument): array | ||
{ | ||
try { | ||
|
||
} catch (\RuntimeException $e) { | ||
|
||
$r = new \ReflectionProperty($e, 'message'); | ||
$r->setAccessible(true); | ||
$r->setValue($e, $message); | ||
|
||
throw $e; | ||
} | ||
} | ||
} | ||
|
||
?> |
28 changes: 28 additions & 0 deletions
28
tests/Issues/ScopeNotAvailable/MatchToSwitchReflectionTest.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\Core\Tests\Issues\ScopeNotAvailable; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class MatchToSwitchReflectionTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/FixtureMatchToSwitchReflection'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/match_to_switch_reflection.php'; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/Issues/ScopeNotAvailable/config/match_to_switch_reflection.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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\DowngradePhp81\Rector\StmtsAwareInterface\DowngradeSetAccessibleReflectionPropertyRector; | ||
use Rector\DowngradePhp80\Rector\Expression\DowngradeMatchToSwitchRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rules([ | ||
DowngradeSetAccessibleReflectionPropertyRector::class, | ||
DowngradeMatchToSwitchRector::class, | ||
]); | ||
}; |