Skip to content
Merged
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
9 changes: 4 additions & 5 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ on:
pull_request:
paths: &paths
- 'src/**'
- 'config/**'
- '.github/workflows/static.yml'
- 'psalm*.xml'
- 'phpstan.neon'
- 'composer.json'
push:
branches: ['master']
Expand All @@ -20,10 +19,10 @@ concurrency:
cancel-in-progress: true

jobs:
psalm:
uses: yiisoft/actions/.github/workflows/psalm.yml@master
phpstan:
uses: yiisoft/actions/.github/workflows/phpstan.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.1.1 under development

- Enh #61: Explicitly import constants in "use" section (@mspirkov)
- Chg #70: Replace Psalm with PHPStan (@vjik)

## 1.1.0 November 21, 2025

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
[![Code Coverage](https://codecov.io/gh/yiisoft/json/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisoft/json)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fjson%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/json/master)
[![Static analysis](https://github.com/yiisoft/json/actions/workflows/static.yml/badge.svg?branch=master)](https://github.com/yiisoft/json/actions/workflows/static.yml?query=branch%3Amaster)
[![type-coverage](https://shepherd.dev/github/yiisoft/json/coverage.svg)](https://shepherd.dev/github/yiisoft/json)

The package provides methods to encode and decode JSON.

Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"friendsofphp/php-cs-fixer": "^3.93",
"phpstan/phpstan": "^2.3",
"phpunit/phpunit": "^9.6.22",
"rector/rector": "^2.8.1",
"shipmonk/composer-dependency-analyser": "^1.8",
Expand Down Expand Up @@ -67,6 +68,7 @@
"scripts": {
"cs-fix": "php-cs-fixer fix",
"dependency-analyser": "composer-dependency-analyser",
"phpstan": "phpstan",
"rector": "rector",
"test": "phpunit --testdox --no-interaction",
"test-watch": "phpunit-watcher watch"
Expand Down
4 changes: 2 additions & 2 deletions docs/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ The package tests are checked with [Infection](https://infection.github.io/) mut

## Static analysis

The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:
The code is statically analyzed with [PHPStan](https://phpstan.org/). To run static analysis:

```shell
./vendor/bin/psalm
./vendor/bin/phpstan
```

## Code style
Expand Down
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
level: max
paths:
- src
ignoreErrors:
# `UnitEnum` is not available in PHP 8.0 and earlier
-
identifier: class.notFound
message: '#^Class UnitEnum not found\.$#'
path: src/Json.php
reportUnmatched: false
16 changes: 0 additions & 16 deletions psalm.xml

This file was deleted.

15 changes: 5 additions & 10 deletions src/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
* @param int $options The encoding options. For more details please refer to
* {@see https://www.php.net/manual/en/function.json-encode.php}.
* Default is `JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR`.
* @param int $depth The maximum depth.
*
* @psalm-param int<1, 2147483647> $depth
* @param int<1, 2147483647> $depth The maximum depth.
*
* @throws JsonException if there is any encoding error.
*
Expand All @@ -55,7 +53,7 @@
public static function encode(
$value,
int $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR,
int $depth = 512

Check warning on line 56 in src/Json.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": @@ @@ * * @return string The encoding result. */ - public static function encode($value, int $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR, int $depth = 512): string + public static function encode($value, int $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR, int $depth = 513): string { if (is_array($value)) { $value = self::processArray($value);

Check warning on line 56 in src/Json.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ * * @return string The encoding result. */ - public static function encode($value, int $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR, int $depth = 512): string + public static function encode($value, int $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR, int $depth = 511): string { if (is_array($value)) { $value = self::processArray($value);
): string {
if (is_array($value)) {
$value = self::processArray($value);
Expand All @@ -64,7 +62,7 @@
}

/**
* @var string We use flag `JSON_THROW_ON_ERROR`, so `json_encode` never returns `false`.
* @var non-empty-string We use flag `JSON_THROW_ON_ERROR`, so `json_encode` never returns `false`.
*/
return json_encode($value, JSON_THROW_ON_ERROR | $options, $depth);
}
Expand Down Expand Up @@ -94,11 +92,9 @@
*
* @param string $json The JSON string to be decoded.
* @param bool $asArray Whether to return objects in terms of associative arrays.
* @param int $depth The recursion depth.
* @param int<1, 2147483647> $depth The recursion depth.
* @param int $options The decode options.
*
* @psalm-param int<1, 2147483647> $depth
*
* @throws JsonException If there is any decoding error.
*
* @return mixed The PHP data.
Expand All @@ -106,7 +102,7 @@
public static function decode(
string $json,
bool $asArray = true,
int $depth = 512,

Check warning on line 105 in src/Json.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": @@ @@ * * @return mixed The PHP data. */ - public static function decode(string $json, bool $asArray = true, int $depth = 512, int $options = JSON_THROW_ON_ERROR) + public static function decode(string $json, bool $asArray = true, int $depth = 513, int $options = JSON_THROW_ON_ERROR) { if ($json === '') { return null;

Check warning on line 105 in src/Json.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ * * @return mixed The PHP data. */ - public static function decode(string $json, bool $asArray = true, int $depth = 512, int $options = JSON_THROW_ON_ERROR) + public static function decode(string $json, bool $asArray = true, int $depth = 511, int $options = JSON_THROW_ON_ERROR) { if ($json === '') { return null;
int $options = JSON_THROW_ON_ERROR
) {
if ($json === '') {
Expand All @@ -118,9 +114,9 @@
/**
* Pre-processes the array before sending it to `json_encode()`.
*
* @param array $data The array to be processed.
* @param array<mixed> $data The array to be processed.
*
* @return array The processed array.
* @return array<mixed> The processed array.
*/
private static function processArray(array $data): array
{
Expand Down Expand Up @@ -148,7 +144,7 @@
$data = $data->jsonSerialize();

if (is_array($data)) {
return self::processArray($data);

Check warning on line 147 in src/Json.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ if ($data instanceof JsonSerializable) { $data = $data->jsonSerialize(); if (is_array($data)) { - return self::processArray($data); + } if (is_object($data)) { return self::processObject($data);
}

if (is_object($data)) {
Expand All @@ -158,7 +154,6 @@
return $data;
}

/** @psalm-suppress UndefinedClass Required for PHP 8.0 and earlier */
if ($data instanceof DateTimeInterface
|| $data instanceof UnitEnum
) {
Expand Down
5 changes: 0 additions & 5 deletions tools/psalm/composer.json

This file was deleted.

Loading