Skip to content

[php 8.3] Add json_validate rule#7200

Closed
arshidkv12 wants to merge 50 commits intorectorphp:mainfrom
arshidkv12:json_validate
Closed

[php 8.3] Add json_validate rule#7200
arshidkv12 wants to merge 50 commits intorectorphp:mainfrom
arshidkv12:json_validate

Conversation

@arshidkv12
Copy link
Contributor

@arshidkv12
Copy link
Contributor Author

vendor/bin/phpstan analyse --ansi                                                                             ✔   
Note: Using configuration file /Users/arshid/Downloads/rector-src/phpstan.neon.

In Resolver.php line 482:
                                                                                                                                                                  
  Service 'rules.0' (type of Symplify\PHPStanRules\Rules\NoDynamicNameRule): Service of type Symplify\PHPStanRules\TypeAnalyzer\CallableTypeAnalyzer required by  
   $callableTypeAnalyzer in NoDynamicNameRule::__construct() not found. Did you add it to configuration file?  

@arshidkv12
Copy link
Contributor Author

Changed the value from 80 to 83

@@ -0,0 +1,15 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use lower character on fixture if possible for fixture filnames:

-Json_validate.php.inc
+json_validate.php.inc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems still use upper case fixfture file name, please use lower case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

github diff seems still show old name, is this file not removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

<?php
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;

if (json_decode($json, true) !== null && json_last_error() === JSON_ERROR_NONE){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fixture content seems equal with other fixture, seems copy paste content.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it.

[
new CodeSample(
<<<'CODE_SAMPLE'
if (json_decode($json, true) !== null && json_last_error() === JSON_ERROR_NONE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json_decode() allow pass depth and flag argument, and from index 1 to 3, they are optional so isset on function arguments per index target is needed.

<?php
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;

if (json_decode(json: $json, true) !== null && json_last_error() === JSON_ERROR_NONE){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this goes to be check, add flipped named argument position fixture as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me check.

samsonasik and others added 2 commits September 1, 2025 17:09
…absSetList" usage (rectorphp#7204)

* Remove removed "Rector\Symfony\Set\FOSRestSetList" usage

* SetList more removal
<?php
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;

if (json_last_error() === JSON_ERROR_NONE && json_decode(associative: true, json: $json) !== null){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking for a previous json_* calls error should not transform the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed 1259088

Copy link
Member

@samsonasik samsonasik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The depth and flag value need to check, if not match, just skip as that means possibly different purpose, see polyfill code

https://github.com/symfony/polyfill-php83/blob/17f6f9a6b1735c0f163024d959f700cfbc5155e5/Php83.php#L26-L36

public const DYNAMIC_CLASS_CONST_FETCH = PhpVersion::PHP_83;

/**
* @var int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add @see to wiki for it.

@see https://wiki.php.net/rfc/json_validate

@arshidkv12
Copy link
Contributor Author

arshidkv12 commented Sep 3, 2025

The depth and flag value need to check, if not match, just skip as that means possibly different purpose, see polyfill code

https://github.com/symfony/polyfill-php83/blob/17f6f9a6b1735c0f163024d959f700cfbc5155e5/Php83.php#L26-L36

Let me check it.

@samsonasik
Copy link
Member

Ref for downgrade rule that ready as well:

{
foreach ($positions as $position) {
$arg = $args[$position] ?? '';
if ($arg instanceof Arg && $arg->name instanceof Identifier && $arg->name->toString() === 'flags') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

colors="true"
executionOrder="defects"
defaultTestSuite="main"
stopOnError="true"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? please create separate PR for unrelated change

@@ -0,0 +1,13 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this .php fixture file seems commited during cut in the middle run unit test, please revert

return PhpVersionFeature::DEPRECATE_OUTSIDE_INTERVEL_VAL_IN_CHR_FUNCTION;
}
}
} No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change, please revert

return $this;
}
}
} No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change, please revert

@arshidkv12
Copy link
Contributor Author

arshidkv12 commented Sep 3, 2025

#7213 Apologies for the mistake, corrected now

@arshidkv12 arshidkv12 closed this Sep 3, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2026

This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants