Skip to content

Commit f99fbbd

Browse files
ArshidArshid
authored andcommitted
[php 8.3] Add json_validate rule
1 parent 295bf3e commit f99fbbd

12 files changed

Lines changed: 202 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace Rector\Tests\Php80\Rector\BooleanAnd\JsonValidate\Fixture;
3+
4+
if (json_decode($json, true) !== null && json_last_error() === JSON_ERROR_NONE){
5+
echo 1;
6+
}
7+
?>
8+
-----
9+
<?php
10+
namespace Rector\Tests\Php80\Rector\BooleanAnd\JsonValidate\Fixture;
11+
12+
if (json_validate($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\Php80\Rector\BooleanAnd\JsonValidate\Fixture;
3+
4+
if (json_decode($json, true) !== null && json_last_error() === JSON_ERROR_NONE){
5+
echo 1;
6+
}
7+
?>
8+
-----
9+
<?php
10+
namespace Rector\Tests\Php80\Rector\BooleanAnd\JsonValidate\Fixture;
11+
12+
if (json_validate($json)){
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+
namespace Rector\Tests\Php80\Rector\BooleanAnd\JsonValidate\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\Php80\Rector\BooleanAnd\JsonValidate\Fixture;
12+
13+
if ($flag) {
14+
echo "skip";
15+
} elseif (json_validate($config)) {
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\Php80\Rector\BooleanAnd\JsonValidate\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\Php80\Rector\BooleanAnd\JsonValidate\Fixture;
10+
11+
if (json_validate('{"a":1}')) {
12+
echo "inline";
13+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\Php80\Rector\BooleanAnd\JsonValidate;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class JsonValidateTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Php80\Rector\BooleanAnd\JsonValidate;
7+
use Rector\ValueObject\PhpVersion;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->phpVersion(PhpVersion::PHP_80);
11+
12+
$rectorConfig->rule(JsonValidate::class);
13+
};
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\JsonValidate\Fixture;
3+
4+
if (json_decode($json, true) !== null && json_last_error() === JSON_ERROR_NONE){
5+
echo 1;
6+
}
7+
?>
8+
-----
9+
<?php
10+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidate\Fixture;
11+
12+
if (json_validate($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\JsonValidate\Fixture;
3+
4+
if (json_decode($json, true) !== null && json_last_error() === JSON_ERROR_NONE){
5+
echo 1;
6+
}
7+
?>
8+
-----
9+
<?php
10+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidate\Fixture;
11+
12+
if (json_validate($json)){
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+
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidate\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\JsonValidate\Fixture;
12+
13+
if ($flag) {
14+
echo "skip";
15+
} elseif (json_validate($config)) {
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\JsonValidate\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\JsonValidate\Fixture;
10+
11+
if (json_validate('{"a":1}')) {
12+
echo "inline";
13+
}

0 commit comments

Comments
 (0)