Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/setup-php-composer/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inputs:
php-version:
description: 'PHP version to use'
required: false
default: '8.3'
default: '8.4'
coverage:
description: 'Coverage driver to use (none, xdebug, pcov)'
required: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Setup PHP and Composer
uses: ./.github/actions/setup-php-composer
with:
php-version: 8.3
php-version: 8.4

# Store a baseline from the PR's base branch on this same runner, so the
# comparison is hardware-consistent (baselines are never committed).
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.3, 8.4, 8.5]
php: [8.4, 8.5]
stability: [prefer-lowest, prefer-stable]

name: PHP${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Repair invalid JSON strings by automatically fixing common syntax errors like si

## Requirements

- PHP 8.3+
- PHP 8.4+
- JSON PHP extension

## Installation
Expand All @@ -28,14 +28,14 @@ use function Cortex\JsonRepair\json_repair_decode;
// Broken JSON (single quotes, unquoted keys, trailing comma)
$broken = "{'name': 'John', age: 30, active: true,}";

$repaired = (new JsonRepairer($broken))->repair();
$repaired = new JsonRepairer($broken)->repair();
// {"name": "John", "age": 30, "active": true}

// Or use the helper function
$repaired = json_repair($broken);

// Repair and decode in one step
$data = (new JsonRepairer($broken))->decode();
$data = new JsonRepairer($broken)->decode();
// ['name' => 'John', 'age' => 30, 'active' => true]

// Or use the helper function
Expand Down
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@
}
],
"require": {
"php": "^8.3",
"php": "^8.4",
"ext-json": "*",
"psr/log": "^3.0"
},
"require-dev": {
"colinodell/psr-testlogger": "^1.3",
"pestphp/pest": "^4.1.4",
"pestphp/pest-plugin-type-coverage": "^4.0.3",
"pestphp/pest": "^5.0",
"pestphp/pest-plugin-phpstan": "^5.0",
"pestphp/pest-plugin-rector": "^5.0",
"pestphp/pest-plugin-type-coverage": "^5.0",
"phpbench/phpbench": "^1.4",
"phpstan/phpstan": "^2.1.32",
"phpstan/phpstan-strict-rules": "^2.0",
"rector/rector": "^2.2",
"symplify/easy-coding-standard": "^13.0"
"symplify/easy-coding-standard": "~13.1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -45,7 +47,7 @@
}
},
"scripts": {
"test": "pest",
"test": "pest --parallel",
"benchmark": "phpbench run",
"benchmark:base": "phpbench run --tag=base --progress=none",
"benchmark:ci": "phpbench run --ref=base --report=aggregate --progress=none --assert=\"mode(variant.time.avg) <= mode(baseline.time.avg) +/- 15%\"",
Expand Down
6 changes: 3 additions & 3 deletions docs/json-repair/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ $repaired = $repairer->repair();
```php
use Cortex\JsonRepair\JsonRepairer;

$result = (new JsonRepairer("{'key': 'value'}"))->repairWithDetails();
$result = new JsonRepairer("{'key': 'value'}")->repairWithDetails();
// $result->json, $result->wasAlreadyValid, $result->fixes
```

Expand All @@ -126,7 +126,7 @@ $result = (new JsonRepairer("{'key': 'value'}"))->repairWithDetails();
`repairAll()` repairs each top-level JSON value separately:

```php
$results = (new JsonRepairer("{'a':1}\n{'b':2}"))->repairAll();
$results = new JsonRepairer("{'a':1}\n{'b':2}")->repairAll();
// ['{"a": 1}', '{"b": 2}']
```

Expand All @@ -147,7 +147,7 @@ $partial = $stream->current(); // closes incomplete string/braces
`decode()` returns `mixed` — top-level scalars (strings, numbers, booleans, null) decode directly without being cast to arrays:

```php
(new JsonRepairer('true'))->decode(); // true
new JsonRepairer('true')->decode(); // true
json_repair_decode('null'); // null
```

Expand Down
2 changes: 1 addition & 1 deletion docs/json-repair/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ icon: 'terminal'

## Requirements

- PHP 8.3+
- PHP 8.4+
- JSON PHP extension
- Composer for dependency management

Expand Down
2 changes: 1 addition & 1 deletion docs/json-repair/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use Cortex\JsonRepair\JsonRepairer;
use Cortex\JsonRepair\Exceptions\JsonRepairException;

try {
$repaired = (new JsonRepairer($input))->repair();
$repaired = new JsonRepairer($input)->repair();
} catch (JsonRepairException $e) {
// input could not be repaired into valid JSON
}
Expand Down
2 changes: 1 addition & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
cleanCode: true,
)
->withPhpCsFixerSets(
php83Migration: true,
php84Migration: true,
)
->withRules([
NotOperatorWithSuccessorSpaceFixer::class,
Expand Down
2 changes: 2 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/pestphp/pest-plugin-phpstan/extension.neon

parameters:
level: 10
paths:
- src
- tests
tmpDir: .phpstan-cache
checkBenevolentUnionTypes: true
8 changes: 7 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Pest\Rector\Set\PestSetList;

return RectorConfig::configure()
->withPaths([
Expand All @@ -14,7 +15,12 @@
importDocBlockNames: false,
removeUnusedImports: true,
)
->withPhpSets()
->withPhpSets(
php84: true,
)
->withSets([
PestSetList::CODING_STYLE,
])
->withPreparedSets(
deadCode: true,
codeQuality: true,
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/InputSanitization.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private function removeComments(string $input): string
$this->log('Removing multi-line comment');
$i += 2;

while ($i + 1 < $length && ! ($input[$i] === '*' && $input[$i + 1] === '/')) {
while ($i + 1 < $length && ($input[$i] !== '*' || $input[$i + 1] !== '/')) {
$i++;
}

Expand Down
4 changes: 3 additions & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

namespace Cortex\JsonRepair\Tests;

uses(TestCase::class)->in('Unit');
pest()
->extend(TestCase::class)
->in('Unit');
Loading
Loading