-
-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Php73] Handle crash on JsonThrowOnErrorRector + SensitiveConstantNam…
…eRector (#5253) * [Php73] Handle crash on JsonThrowOnErrorRector + SensitiveConstantNameRector * Fix * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <actions@github.com>
- Loading branch information
1 parent
52ef7b8
commit 60047ce
Showing
4 changed files
with
97 additions
and
5 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
51 changes: 51 additions & 0 deletions
51
tests/Issues/ScopeNotAvailable/FixtureJsonThrowCaseSensitiveConstFetch/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,51 @@ | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\ScopeNotAvailable\FixtureJsonThrowCaseSensitiveConstFetch; | ||
|
||
class Fixture | ||
{ | ||
public static function run() | ||
{ | ||
$user = $_REQUEST['param']; | ||
|
||
$user = json_decode($user); | ||
|
||
$condition = true; | ||
if ($condition) { | ||
$output = []; | ||
echo(json_encode($output)); | ||
exit; | ||
} | ||
|
||
$output = []; | ||
echo(json_encode($output)); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\ScopeNotAvailable\FixtureJsonThrowCaseSensitiveConstFetch; | ||
|
||
class Fixture | ||
{ | ||
public static function run() | ||
{ | ||
$user = $_REQUEST['param']; | ||
|
||
$user = json_decode($user, null, 512, JSON_THROW_ON_ERROR); | ||
|
||
$condition = true; | ||
if ($condition) { | ||
$output = []; | ||
echo(json_encode($output)); | ||
exit; | ||
} | ||
|
||
$output = []; | ||
echo(json_encode($output, JSON_THROW_ON_ERROR)); | ||
} | ||
} | ||
|
||
?> |
28 changes: 28 additions & 0 deletions
28
tests/Issues/ScopeNotAvailable/JsonThrowCaseSensitiveConstFetchTest.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 JsonThrowCaseSensitiveConstFetchTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/FixtureJsonThrowCaseSensitiveConstFetch'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/json_throw_case_sensitive_const_fetch.php'; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/Issues/ScopeNotAvailable/config/json_throw_case_sensitive_const_fetch.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\Php73\Rector\FuncCall\JsonThrowOnErrorRector; | ||
use Rector\Php73\Rector\ConstFetch\SensitiveConstantNameRector; | ||
use Rector\Config\RectorConfig; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rules([ | ||
JsonThrowOnErrorRector::class, | ||
SensitiveConstantNameRector::class | ||
]); | ||
}; |