diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 27cc5d8..03d977c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,21 +7,21 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Cache Composer dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: /tmp/composer-cache key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} - - uses: php-actions/composer@v5 + - uses: php-actions/composer@v6 - name: Archive build run: mkdir /tmp/github-actions/ && tar -cvf /tmp/github-actions/build.tar ./ - name: Upload build archive for test runners - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: build-artifact path: /tmp/github-actions @@ -31,7 +31,7 @@ jobs: needs: [composer] steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: build-artifact path: /tmp/github-actions @@ -40,9 +40,9 @@ jobs: run: tar -xvf /tmp/github-actions/build.tar ./ - name: PHP Unit tests - uses: php-actions/phpunit@v2 + uses: php-actions/phpunit@v3 with: - php_version: 8.0 + php_version: 8.1 php_extensions: xdebug configuration: test/phpunit/phpunit.xml bootstrap: vendor/autoload.php @@ -52,7 +52,7 @@ jobs: needs: [composer] steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: build-artifact path: /tmp/github-actions @@ -61,6 +61,7 @@ jobs: run: tar -xvf /tmp/github-actions/build.tar ./ - name: PHP Static Analysis - uses: php-actions/phpstan@v2 + uses: php-actions/phpstan@v3 with: - path: src/ \ No newline at end of file + path: src/ + php_version: 8.1 diff --git a/composer.lock b/composer.lock index acad0c7..096317e 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "phpgt/dataobject", - "version": "v1.0.0", + "version": "v1.0.4", "source": { "type": "git", "url": "https://github.com/PhpGt/DataObject.git", - "reference": "02e08144a0ed4b2bf022baf125803dfbbfc1b487" + "reference": "dde4c5ba9e4cd0e048e4558107da32ce3f9ce7e4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PhpGt/DataObject/zipball/02e08144a0ed4b2bf022baf125803dfbbfc1b487", - "reference": "02e08144a0ed4b2bf022baf125803dfbbfc1b487", + "url": "https://api.github.com/repos/PhpGt/DataObject/zipball/dde4c5ba9e4cd0e048e4558107da32ce3f9ce7e4", + "reference": "dde4c5ba9e4cd0e048e4558107da32ce3f9ce7e4", "shasum": "" }, "require": { @@ -26,8 +26,8 @@ "phpgt/typesafegetter": "^1.0" }, "require-dev": { - "phpstan/phpstan": ">=0.12.64", - "phpunit/phpunit": "9.*" + "phpstan/phpstan": "^v1.8", + "phpunit/phpunit": "^v9.5" }, "type": "library", "autoload": { @@ -48,7 +48,7 @@ "description": " Structured, type-safe, immutable data transfer.", "support": { "issues": "https://github.com/PhpGt/DataObject/issues", - "source": "https://github.com/PhpGt/DataObject/tree/v1.0.0" + "source": "https://github.com/PhpGt/DataObject/tree/v1.0.4" }, "funding": [ { @@ -56,7 +56,7 @@ "type": "github" } ], - "time": "2021-03-15T18:03:44+00:00" + "time": "2022-09-15T09:21:05+00:00" }, { "name": "phpgt/typesafegetter", @@ -408,16 +408,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.8.4", + "version": "1.8.5", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "eed4c9da531f6ebb4787235b6fb486e2c20f34e5" + "reference": "f6598a5ff12ca4499a836815e08b4d77a2ddeb20" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/eed4c9da531f6ebb4787235b6fb486e2c20f34e5", - "reference": "eed4c9da531f6ebb4787235b6fb486e2c20f34e5", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/f6598a5ff12ca4499a836815e08b4d77a2ddeb20", + "reference": "f6598a5ff12ca4499a836815e08b4d77a2ddeb20", "shasum": "" }, "require": { @@ -447,7 +447,7 @@ ], "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.8.4" + "source": "https://github.com/phpstan/phpstan/tree/1.8.5" }, "funding": [ { @@ -463,7 +463,7 @@ "type": "tidelift" } ], - "time": "2022-09-03T13:08:04+00:00" + "time": "2022-09-07T16:05:32+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1050,16 +1050,16 @@ }, { "name": "sebastian/comparator", - "version": "4.0.6", + "version": "4.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "55f4261989e546dc112258c7a75935a81a7ce382" + "reference": "fa0f136dd2334583309d32b62544682ee972b51a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/55f4261989e546dc112258c7a75935a81a7ce382", - "reference": "55f4261989e546dc112258c7a75935a81a7ce382", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/fa0f136dd2334583309d32b62544682ee972b51a", + "reference": "fa0f136dd2334583309d32b62544682ee972b51a", "shasum": "" }, "require": { @@ -1112,7 +1112,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", - "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.6" + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.8" }, "funding": [ { @@ -1120,7 +1120,7 @@ "type": "github" } ], - "time": "2020-10-26T15:49:45+00:00" + "time": "2022-09-14T12:41:17+00:00" }, { "name": "sebastian/complexity", @@ -1310,16 +1310,16 @@ }, { "name": "sebastian/exporter", - "version": "4.0.4", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9" + "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/65e8b7db476c5dd267e65eea9cab77584d3cfff9", - "reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", + "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", "shasum": "" }, "require": { @@ -1375,7 +1375,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.4" + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.5" }, "funding": [ { @@ -1383,7 +1383,7 @@ "type": "github" } ], - "time": "2021-11-11T14:18:36+00:00" + "time": "2022-09-14T06:03:37+00:00" }, { "name": "sebastian/global-state", @@ -1738,16 +1738,16 @@ }, { "name": "sebastian/type", - "version": "3.1.0", + "version": "3.2.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "fb44e1cc6e557418387ad815780360057e40753e" + "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/fb44e1cc6e557418387ad815780360057e40753e", - "reference": "fb44e1cc6e557418387ad815780360057e40753e", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e", + "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e", "shasum": "" }, "require": { @@ -1759,7 +1759,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "3.2-dev" } }, "autoload": { @@ -1782,7 +1782,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/3.1.0" + "source": "https://github.com/sebastianbergmann/type/tree/3.2.0" }, "funding": [ { @@ -1790,7 +1790,7 @@ "type": "github" } ], - "time": "2022-08-29T06:55:37+00:00" + "time": "2022-09-12T14:47:03+00:00" }, { "name": "sebastian/version", diff --git a/src/JsonObjectBuilder.php b/src/JsonObjectBuilder.php index 90a2b96..6304e9b 100644 --- a/src/JsonObjectBuilder.php +++ b/src/JsonObjectBuilder.php @@ -12,8 +12,13 @@ use stdClass; class JsonObjectBuilder extends DataObjectBuilder { + public function __construct( + private readonly int $depth = 512, + ) { + } + public function fromJsonString(string $jsonString):JsonObject { - $json = json_decode($jsonString); + $json = json_decode($jsonString, depth: $this->depth); if(is_null($json)) { // It's completely reasonable to have a null value here, so we need to check the // error code before throwing an exception. @@ -26,7 +31,7 @@ public function fromJsonString(string $jsonString):JsonObject { } /** - * @param object|array|string|int|float|bool|null $jsonDecoded + * @param object|array|string|int|float|bool|null $jsonDecoded */ public function fromJsonDecoded( object|array|string|int|float|bool|null $jsonDecoded diff --git a/test/phpunit/JsonObjectBuilderTest.php b/test/phpunit/JsonObjectBuilderTest.php index 41027a8..b323cdb 100644 --- a/test/phpunit/JsonObjectBuilderTest.php +++ b/test/phpunit/JsonObjectBuilderTest.php @@ -194,4 +194,25 @@ public function testFromJson_illegalCharacters() { self::expectExceptionMessage("Error decoding JSON: Malformed UTF-8 characters, possibly incorrectly encoded"); $sut->fromJsonString($jsonString); } + + public function testFromJson_depth() { + $jsonString = <<fromJsonString($jsonString); + } }