Skip to content

Commit 5563a7c

Browse files
ArshidArshid
authored andcommitted
[php 8.3] Add json_validate rule
1 parent bf0637c commit 5563a7c

17 files changed

Lines changed: 386 additions & 0 deletions

config/set/php83.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

55
use Rector\Config\RectorConfig;
6+
use Rector\Php83\Rector\BooleanAnd\JsonValidateRector;
67
use Rector\Php83\Rector\Class_\ReadOnlyAnonymousClassRector;
78
use Rector\Php83\Rector\ClassConst\AddTypeToConstRector;
89
use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector;
@@ -18,5 +19,6 @@
1819
RemoveGetClassGetParentClassNoArgsRector::class,
1920
ReadOnlyAnonymousClassRector::class,
2021
DynamicClassConstFetchRector::class,
22+
JsonValidateRector::class,
2123
]);
2224
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
3+
4+
if ($flag) {
5+
echo "skip";
6+
} elseif (json_decode($config, true) !== null && json_last_error() === JSON_ERROR_NONE) {
7+
echo "valid config";
8+
}
9+
-----
10+
<?php
11+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
12+
13+
if ($flag) {
14+
echo "skip";
15+
} elseif (json_validate($config, true)) {
16+
echo "valid config";
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
3+
4+
if (json_decode('{"a":1}', true) !== null && json_last_error() === JSON_ERROR_NONE) {
5+
echo "inline";
6+
}
7+
-----
8+
<?php
9+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
10+
11+
if (json_validate('{"a":1}', true)) {
12+
echo "inline";
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
4+
5+
if (json_decode($json, true, 3) !== null && json_last_error() === JSON_ERROR_NONE){
6+
echo 1;
7+
}
8+
?>
9+
-----
10+
<?php
11+
12+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
13+
14+
if (json_validate($json, true, 3)){
15+
echo 1;
16+
}
17+
?>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
4+
5+
if (json_decode($json, true) !== null && json_last_error() === JSON_ERROR_NONE){
6+
echo 1;
7+
}
8+
?>
9+
-----
10+
<?php
11+
12+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
13+
14+
if (json_validate($json, true)){
15+
echo 1;
16+
}
17+
?>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
4+
5+
if (json_decode($json, true, 512) !== null && json_last_error() === JSON_ERROR_NONE){
6+
echo 1;
7+
}
8+
?>
9+
-----
10+
<?php
11+
12+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
13+
14+
if (json_validate($json, true, 512)){
15+
echo 1;
16+
}
17+
?>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
3+
4+
if (json_decode(associative: true, json: $json) !== null && json_last_error() === JSON_ERROR_NONE){
5+
echo 1;
6+
}
7+
?>
8+
-----
9+
<?php
10+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
11+
12+
if (json_validate(associative: true, json: $json)){
13+
echo 1;
14+
}
15+
?>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
3+
4+
if (json_decode(json: $json, associative: true) !== null && json_last_error() === JSON_ERROR_NONE){
5+
echo 1;
6+
}
7+
?>
8+
-----
9+
<?php
10+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
11+
12+
if (json_validate(json: $json, associative: true)){
13+
echo 1;
14+
}
15+
?>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
4+
5+
if (null !== json_decode($json) && JSON_ERROR_NONE === json_last_error()){
6+
echo 2;
7+
}
8+
?>
9+
-----
10+
<?php
11+
12+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
13+
14+
if (json_validate($json)){
15+
echo 2;
16+
}
17+
?>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
4+
5+
if (null !== json_decode($json) && json_last_error() === JSON_ERROR_NONE){
6+
echo 1;
7+
}
8+
?>
9+
-----
10+
<?php
11+
12+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;
13+
14+
if (json_validate($json)){
15+
echo 1;
16+
}
17+
?>

0 commit comments

Comments
 (0)