File tree Expand file tree Collapse file tree 3 files changed +84
-0
lines changed
tests/Issues/ScopeNotAvailable
FixtureMatchToSwitchReflection Expand file tree Collapse file tree 3 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \Issues \ScopeNotAvailable \FixtureMatchToSwitchReflection ;
4+
5+ final class ServiceValueResolver
6+ {
7+ public function resolve (Request $ request , ArgumentMetadata $ argument ): array
8+ {
9+ try {
10+
11+ } catch (\RuntimeException $ e ) {
12+
13+ $ r = new \ReflectionProperty ($ e , 'message ' );
14+ $ r ->setValue ($ e , $ message );
15+
16+ throw $ e ;
17+ }
18+ }
19+ }
20+
21+ ?>
22+ -----
23+ <?php
24+
25+ namespace Rector \Tests \Issues \ScopeNotAvailable \FixtureMatchToSwitchReflection ;
26+
27+ final class ServiceValueResolver
28+ {
29+ public function resolve (Request $ request , ArgumentMetadata $ argument ): array
30+ {
31+ try {
32+
33+ } catch (\RuntimeException $ e ) {
34+
35+ $ r = new \ReflectionProperty ($ e , 'message ' );
36+ if (PHP_VERSION_ID < 80100 ) {
37+ $ r ->setAccessible (true );
38+ }
39+ $ r ->setValue ($ e , $ message );
40+
41+ throw $ e ;
42+ }
43+ }
44+ }
45+
46+ ?>
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \Tests \Issues \ScopeNotAvailable ;
6+
7+ use Iterator ;
8+ use PHPUnit \Framework \Attributes \DataProvider ;
9+ use Rector \Testing \PHPUnit \AbstractRectorTestCase ;
10+
11+ final class MatchToSwitchReflectionTest extends AbstractRectorTestCase
12+ {
13+ #[DataProvider('provideData ' )]
14+ public function test (string $ filePath ): void
15+ {
16+ $ this ->doTestFile ($ filePath );
17+ }
18+
19+ public static function provideData (): Iterator
20+ {
21+ return self ::yieldFilesFromDirectory (__DIR__ . '/FixtureMatchToSwitchReflection ' );
22+ }
23+
24+ public function provideConfigFilePath (): string
25+ {
26+ return __DIR__ . '/config/match_to_switch_reflection.php ' ;
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ use Rector \Config \RectorConfig ;
6+ use Rector \DowngradePhp80 \Rector \Expression \DowngradeMatchToSwitchRector ;
7+ use Rector \DowngradePhp81 \Rector \StmtsAwareInterface \DowngradeSetAccessibleReflectionPropertyRector ;
8+
9+ return RectorConfig::configure ()
10+ ->withRules ([DowngradeSetAccessibleReflectionPropertyRector::class, DowngradeMatchToSwitchRector::class]);
You can’t perform that action at this time.
0 commit comments