-
-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DowngradePhp72] Add DowngradeJsonDecodeNullAssociativeArgRector #1723
Conversation
371574a
to
6e9bd0b
Compare
b560130
to
9e83eb7
Compare
a070a64
to
140a0ba
Compare
It seems make unnecessary cast when already a ➜ rector-src git:(downgrade-json-decode-null) bin/rector process vendor/nette/utils/src/Utils/Json.php --config build/config/config-downgrade.php --dry-run --clear-cache
1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
1 file with changes
===================
1) vendor/nette/utils/src/Utils/Json.php:52
---------- begin diff ----------
@@ @@
*/
public static function decode(string $json, int $flags = 0)
{
- $value = json_decode($json, null, 512, $flags | JSON_BIGINT_AS_STRING);
+ $value = json_decode($json, (bool) false, 512, $flags | JSON_BIGINT_AS_STRING);
if ($error = json_last_error()) {
throw new JsonException(json_last_error_msg(), $error);
}
----------- end diff -----------
Applied rules:
* DowngradeJsonDecodeNullAssociativeArgRector
* DowngradeAttributeToAnnotationRector (https://php.watch/articles/php-attributes#syntax)
[OK] 1 file would have changed (dry-run) by Rector
|
Resolved with check original node 7eec01f ➜ rector-src git:(downgrade-json-decode-null) bin/rector process vendor/nette/utils/src/Utils/Json.php --config build/config/config-downgrade.php --dry-run
1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
1 file with changes
===================
1) vendor/nette/utils/src/Utils/Json.php:52
---------- begin diff ----------
@@ @@
*/
public static function decode(string $json, int $flags = 0)
{
- $value = json_decode($json, null, 512, $flags | JSON_BIGINT_AS_STRING);
+ $value = json_decode($json, false, 512, $flags | JSON_BIGINT_AS_STRING);
if ($error = json_last_error()) {
throw new JsonException(json_last_error_msg(), $error);
}
----------- end diff -----------
Applied rules:
* DowngradeJsonDecodeNullAssociativeArgRector
[OK] 1 file would have changed (dry-run) by Rector
|
The correct way to use created by rule attribute e9f89ce, solved 🎉 Let's give it a try |
Thank you 👍 |
It seems got different error now: PHP Fatal error: Uncaught TypeError: Return value of RectorPrefix20220125\Symplify\ComposerJsonManipulator\FileSystem\JsonFileManager::loadFromFilePath() must be of the type array, object returned in /home/runner/work/rector/rector/vendor/symplify/composer-json-manipulator/src/FileSystem/JsonFileManager.php:57 it possibly on casting |
Currect rector/rector dev-main on php 7.1 got broken build as
nette/utils: 3.2.7
has codewhich make invalid on php 7.1, ref https://3v4l.org/qisBB#v7.1.33
This PR add DowngradeJsonDecodeNullAssociativeArgRector to make it
false
or cast to(bool)
when not bool type.Fixes rectorphp/rector#6967