Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Rector\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\Tests\Issues\ScopeNotAvailable\FixtureMatchToSwitchReflection;

final class ServiceValueResolver
{
public function resolve(Request $request, ArgumentMetadata $argument): array
{
try {

} catch (\RuntimeException $e) {

$r = new \ReflectionProperty($e, 'message');
if (PHP_VERSION_ID < 80100) {
$r->setAccessible(true);
}
$r->setValue($e, $message);

throw $e;
}
}
}

?>
28 changes: 28 additions & 0 deletions tests/Issues/ScopeNotAvailable/MatchToSwitchReflectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\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';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DowngradePhp80\Rector\Expression\DowngradeMatchToSwitchRector;
use Rector\DowngradePhp81\Rector\StmtsAwareInterface\DowngradeSetAccessibleReflectionPropertyRector;

return RectorConfig::configure()
->withRules([DowngradeSetAccessibleReflectionPropertyRector::class, DowngradeMatchToSwitchRector::class]);