diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06ada0e..a311e64 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest] - php-version: ['8.2', '8.3'] + php-version: ['8.2', '8.3', '8.4'] dependency-versions: ['lowest', 'highest'] name: 'PHPUnit' steps: @@ -30,43 +30,8 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} psalm: - runs-on: ubuntu-latest - strategy: - matrix: - php-version: ['8.2', '8.3'] - dependency-versions: ['lowest', 'highest'] - name: 'Psalm' - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - extensions: mbstring, intl - coverage: none - - name: Composer - uses: "ramsey/composer-install@v2" - with: - dependency-versions: ${{ matrix.dependencies }} - - name: Psalm - run: vendor/bin/psalm --shepherd + uses: innmind/github-workflows/.github/workflows/psalm-matrix.yml@main cs: - runs-on: ubuntu-latest - strategy: - matrix: - php-version: ['8.2'] - name: 'CS' - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - extensions: mbstring, intl - coverage: none - - name: Composer - uses: "ramsey/composer-install@v2" - - name: CS - run: vendor/bin/php-cs-fixer fix --diff --dry-run + uses: innmind/github-workflows/.github/workflows/cs.yml@main + with: + php-version: '8.2' diff --git a/composer.json b/composer.json index 733dfb7..d821dfa 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ }, "require-dev": { "phpunit/phpunit": "~10.0", - "vimeo/psalm": "~5.23", + "vimeo/psalm": "~5.23|dev-master", "innmind/coding-standard": "~2.0" } } diff --git a/src/Json.php b/src/Json.php index 2f2d27f..7976490 100644 --- a/src/Json.php +++ b/src/Json.php @@ -67,11 +67,20 @@ public static function maybeDecode(string $string): Maybe public static function encode(mixed $content, int $options = 0, int $depth = 512): string { try { - return \json_encode( + $content = \json_encode( $content, $options | \JSON_THROW_ON_ERROR, $depth, ); + + if ($content === false) { + // This case should not happen since we use the option to throw + // on error. But Psalm doesn't understand that so we have to + // handle the `false` case. + throw new \JsonException; + } + + return $content; } catch (\JsonException $e) { throw self::wrap($e); }