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
88 changes: 42 additions & 46 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
composer-require-checker:
strategy:
matrix:
php: [ "8.1", "8.2" ]
php: ["8.3", "8.4"]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -23,27 +23,26 @@ jobs:
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.deps }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.deps }}-
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-

- name: Install dependencies
run: composer update --no-interaction --no-progress --no-suggest ${{ matrix.deps }}
run: composer update --no-interaction --no-progress --no-suggest

- name: Composer Require Checker
run: composer check-deps

phpcs:
code-style:
strategy:
matrix:
php: [ "8.1", "8.2" ]
deps: [ "--prefer-lowest", "" ]
php: ["8.3", "8.4"]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -55,27 +54,26 @@ jobs:
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.deps }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.deps }}-
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-

- name: Install dependencies
run: composer update --no-interaction --no-progress --no-suggest ${{ matrix.deps }}
run: composer update --no-interaction --no-progress --no-suggest

- name: PHPCS
run: composer cs-check
- name: PHP Code Style
run: PHP_CS_FIXER_IGNORE_ENV=1 composer cs-check

phpstan:
strategy:
matrix:
php: [ "8.1", "8.2" ]
deps: [ "--prefer-lowest", "" ]
php: ["8.3", "8.4"]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -87,27 +85,26 @@ jobs:
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.deps }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.deps }}-
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-

- name: Install dependencies
run: composer update --no-interaction --no-progress --no-suggest ${{ matrix.deps }}
run: composer update --no-interaction --no-progress --no-suggest

- name: PHPStan
run: composer phpstan

psalm:
strategy:
matrix:
php: [ "8.1", "8.2" ]
deps: [ "--prefer-lowest", "" ]
php: ["8.3", "8.4"]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -119,27 +116,27 @@ jobs:
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.deps }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.deps }}-
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-

- name: Install dependencies
run: composer update --no-interaction --no-progress --no-suggest ${{ matrix.deps }}
run: composer update --no-interaction --no-progress --no-suggest

- name: Psalm
run: composer psalm

infection:

strategy:
matrix:
php: [ "8.1", "8.2" ]
deps: [ "--prefer-lowest", "" ]
php: ["8.3", "8.4"]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -151,14 +148,14 @@ jobs:
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.deps }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.deps }}-
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-

- name: Install dependencies
run: composer update --no-interaction --no-progress --no-suggest ${{ matrix.deps }}
run: composer update --no-interaction --no-progress --no-suggest

- name: Infection coverage of changed lines
if: "!contains(github.event.pull_request.labels.*.name, 'skip-infection')"
Expand All @@ -174,21 +171,20 @@ jobs:
-jmax

- name: Save Infection result
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: always()
with:
name: infection-log-${{ matrix.php }}-${{ matrix.deps }}.txt
name: infection-log-${{ matrix.php }}.txt
path: infection-log.txt

phpunit:
strategy:
matrix:
php: [ "8.1", "8.2" ]
deps: [ "--prefer-lowest", "" ]
php: ["8.3", "8.4"]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -200,14 +196,14 @@ jobs:
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.deps }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.deps }}-
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-

- name: Install dependencies
run: composer update --no-interaction --no-progress --no-suggest ${{ matrix.deps }}
run: composer update --no-interaction --no-progress --no-suggest

- name: Tests
run: vendor/bin/phpunit --coverage-clover=coverage.xml --stop-on-failure
Expand Down
53 changes: 27 additions & 26 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
{
"name": "eventjet/json",
"type": "library",
"description": "Type-safe JSON encoding and decoding",
"license": "MIT",
"type": "library",
"require": {
"php": ">=8.1",
"php": ">=8.3",
"ext-json": "*"
},
"require-dev": {
"eventjet/coding-standard": "^3.15",
"infection/infection": "^0.26.20",
"maglnet/composer-require-checker": "^4.6",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
"phpunit/phpunit": "^10.1",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.23"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"infection/extension-installer": true,
"phpstan/extension-installer": true
},
"sort-packages": true
"eventjet/coding-standard": "^3.18",
"infection/infection": "^0.31.2",
"maglnet/composer-require-checker": "^4.16.1",
"phpstan/extension-installer": "^1.4.3",
"phpstan/phpstan": "^2.1.7",
"phpstan/phpstan-phpunit": "^2.0.4",
"phpstan/phpstan-strict-rules": "^2.0.3",
"phpunit/phpunit": "^12.0.7",
"psalm/plugin-phpunit": "^0.19.2",
"vimeo/psalm": "^6.8.8"
},
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"Eventjet\\Json\\": "src"
Expand All @@ -37,7 +30,14 @@
"Eventjet\\Test\\Unit\\Json\\": "tests/unit"
}
},
"minimum-stability": "stable",
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"infection/extension-installer": true,
"phpstan/extension-installer": true
},
"sort-packages": true
},
"scripts": {
"check": [
"@check-deps",
Expand All @@ -47,12 +47,13 @@
"@phpunit",
"@infection"
],
"check-deps": "vendor/bin/composer-require-checker",
"check-deps": "composer-require-checker",
"cs-check": "php-cs-fixer fix --dry-run",
"cs-fix": "php-cs-fixer fix",
"infection": "vendor/bin/infection -jmax",
"phpstan": "vendor/bin/phpstan",
"phpunit": "vendor/bin/phpunit",
"psalm": "vendor/bin/psalm"
"infection": "infection -jmax",
"infection-diff": "infection -jmax --git-diff-lines --min-msi=100 --min-covered-msi=100 --ignore-msi-with-no-mutations",
"phpstan": "phpstan analyze",
"phpunit": "phpunit",
"psalm": "psalm"
}
}
1 change: 1 addition & 0 deletions infection.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"staticAnalysisTool":"phpstan",
"timeout": 10,
"source": {
"directories": [
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
parameters:
level: max
rememberPossiblyImpureFunctionValues: false
paths:
- src/
- tests/
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
ensureOverrideAttribute="false"
findUnusedBaselineEntry="true"
findUnusedCode="true"
findUnusedPsalmSuppress="true"
>
<projectFiles>
<directory name="src"/>
Expand Down
17 changes: 3 additions & 14 deletions src/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ public static function decode(string $json, object|string $value): object
}

/**
* @psalm-suppress MixedInferredReturnType
* @return string|int|float|bool|array<array-key, mixed>|null
*/
private static function preparePropertyValueForEncoding(mixed $value): string|int|float|bool|array|null
{
/** @psalm-suppress MixedReturnStatement */
return match (true) {
is_string($value), is_int($value), is_float($value), is_bool($value), $value === null => $value,
is_array($value) => self::encodeArray($value),
Expand Down Expand Up @@ -119,7 +117,6 @@ private static function getJsonKeyForProperty(ReflectionProperty $property): str
* @template T of object
* @param T | class-string<T> $value
* @return T
* @psalm-suppress InvalidReturnType
*/
private static function decodeClass(string $json, object|string $value): object
{
Expand All @@ -128,7 +125,7 @@ private static function decodeClass(string $json, object|string $value): object
throw JsonError::decodeFailed(error_get_last()['message'] ?? null);
}
if (!is_array($data)) {
throw JsonError::decodeFailed(sprintf("Expected JSON object, got %s", gettype($data)));
throw JsonError::decodeFailed(sprintf('Expected JSON object, got %s', gettype($data)));
}
/** @psalm-suppress DocblockTypeContradiction */
if (!is_string($value)) {
Expand Down Expand Up @@ -485,13 +482,13 @@ private static function parseUseStatements(string $file): array
if ($result !== 1) {
continue;
}
$useStatements[$matches['alias'] ?? $matches['class']] = ($matches['ns'] ?? '') . $matches['class'];
$useStatements[$matches['alias'] ?? $matches['class']] = $matches['ns'] . $matches['class'];
}
return $useStatements;
}

/**
* @return list<mixed> | array<string, mixed>
* @return list<mixed> | array<array-key, mixed>
*/
private static function createConstructorArgumentForArrayType(
ReflectionParameter $parameter,
Expand Down Expand Up @@ -615,16 +612,8 @@ private static function createConstructorArgumentForEnumType(
),
);
}
/**
* @psalm-suppress MixedAssignment
* @psalm-suppress MixedMethodCall
*/
$case = $typeName::tryFrom($value);
if ($case === null) {
/**
* @psalm-suppress MixedArgument
* @psalm-suppress MixedMethodCall
*/
throw JsonError::decodeFailed(
sprintf(
'"%s" is not a valid value for enum %s. Valid values are: %s',
Expand Down
2 changes: 1 addition & 1 deletion src/JsonError.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

final class JsonError extends RuntimeException
{
private function __construct(string $message = "", int $code = 0, Throwable|null $previous = null)
private function __construct(string $message = '', int $code = 0, Throwable|null $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
Loading
Loading