From 403ee9b17ebd65f92ee4c277c40023973091fb70 Mon Sep 17 00:00:00 2001 From: mroloux Date: Thu, 16 May 2024 12:57:35 +0200 Subject: [PATCH 1/7] JSON parsing now consumes significantly less memory --- composer.json | 3 +- composer.lock | 383 ++++++++++-------- src/Charts/Charts.php | 31 +- src/Events/Event.php | 2 - src/Events/Events.php | 20 +- src/GuzzleResponseDecoder.php | 46 +++ src/HoldTokens/HoldTokens.php | 8 +- src/PageFetcher.php | 3 +- src/Reports/Charts/ChartReports.php | 9 +- src/Reports/Events/EventReports.php | 54 +-- src/Reports/Usage/UsageReports.php | 9 +- src/Seasons/Seasons.php | 14 +- src/SeatsioClient.php | 2 +- src/SeatsioException.php | 3 +- src/Workspaces/Workspaces.php | 9 +- tests/EventLog/ListAllEventLogItemsTest.php | 3 - tests/Events/CreateEventsTest.php | 1 - tests/Events/ListStatusChangesTest.php | 2 - .../Events/OverrideSeasonObjectStatusTest.php | 3 - tests/Events/UpdateEventTest.php | 1 - tests/Events/UseSeasonObjectStatusTest.php | 3 - tests/SeatsioClientTest.php | 3 +- tests/Workspaces/CreateWorkspaceTest.php | 1 - tests/Workspaces/RetrieveWorkspaceTest.php | 1 - tests/Workspaces/UpdateWorkspaceTest.php | 1 - 25 files changed, 345 insertions(+), 270 deletions(-) create mode 100644 src/GuzzleResponseDecoder.php diff --git a/composer.json b/composer.json index ff9b4be..42fe94e 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,8 @@ "guzzlehttp/guzzle": "7.8.1", "guzzlehttp/uri-template": "v1.0.3", "netresearch/jsonmapper": "4.4.1", - "lstrojny/functional-php": "1.17.0" + "lstrojny/functional-php": "1.17.0", + "halaxa/json-machine": "1.1.4" }, "require-dev": { "brianium/paratest": "7.3.1" diff --git a/composer.lock b/composer.lock index 754ae5b..07416e3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1c3c00327811483af0bb963c876d7b04", + "content-hash": "0df7111d19f19ed6dff53672700c54a7", "packages": [ { "name": "guzzlehttp/guzzle", @@ -417,6 +417,65 @@ ], "time": "2023-12-03T19:50:20+00:00" }, + { + "name": "halaxa/json-machine", + "version": "1.1.4", + "source": { + "type": "git", + "url": "https://github.com/halaxa/json-machine.git", + "reference": "5147f38f74d7ab3e27733e3f3bdabbd2fd28e3fa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/halaxa/json-machine/zipball/5147f38f74d7ab3e27733e3f3bdabbd2fd28e3fa", + "reference": "5147f38f74d7ab3e27733e3f3bdabbd2fd28e3fa", + "shasum": "" + }, + "require": { + "php": "7.0 - 8.3" + }, + "require-dev": { + "ext-json": "*", + "friendsofphp/php-cs-fixer": "^3.0", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^8.0" + }, + "suggest": { + "ext-json": "To run JSON Machine out of the box without custom decoders.", + "guzzlehttp/guzzle": "To run example with GuzzleHttp" + }, + "type": "library", + "autoload": { + "psr-4": { + "JsonMachine\\": "src/" + }, + "exclude-from-classmap": [ + "src/autoloader.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Filip Halaxa", + "email": "filip@halaxa.cz" + } + ], + "description": "Efficient, easy-to-use and fast JSON pull parser", + "support": { + "issues": "https://github.com/halaxa/json-machine/issues", + "source": "https://github.com/halaxa/json-machine/tree/1.1.4" + }, + "funding": [ + { + "url": "https://ko-fi.com/G2G57KTE4", + "type": "other" + } + ], + "time": "2023-11-28T21:12:40+00:00" + }, { "name": "lstrojny/functional-php", "version": "1.17.0", @@ -676,20 +735,20 @@ }, { "name": "psr/http-factory", - "version": "1.0.2", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/php-fig/http-factory.git", - "reference": "e616d01114759c4c489f93b099585439f795fe35" + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35", - "reference": "e616d01114759c4c489f93b099585439f795fe35", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a", "shasum": "" }, "require": { - "php": ">=7.0.0", + "php": ">=7.1", "psr/http-message": "^1.0 || ^2.0" }, "type": "library", @@ -713,7 +772,7 @@ "homepage": "https://www.php-fig.org/" } ], - "description": "Common interfaces for PSR-7 HTTP message factories", + "description": "PSR-17: Common interfaces for PSR-7 HTTP message factories", "keywords": [ "factory", "http", @@ -725,9 +784,9 @@ "response" ], "support": { - "source": "https://github.com/php-fig/http-factory/tree/1.0.2" + "source": "https://github.com/php-fig/http-factory" }, - "time": "2023-04-10T20:10:41+00:00" + "time": "2024-04-15T12:06:14+00:00" }, { "name": "psr/http-message", @@ -828,16 +887,16 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v3.4.0", + "version": "v3.5.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", "shasum": "" }, "require": { @@ -846,7 +905,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.4-dev" + "dev-main": "3.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -875,7 +934,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.4.0" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.0" }, "funding": [ { @@ -891,20 +950,20 @@ "type": "tidelift" } ], - "time": "2023-05-23T14:45:45+00:00" + "time": "2024-04-18T09:32:20+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5" + "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/6caa57379c4aec19c0a12a38b59b26487dcfe4b5", - "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", + "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", "shasum": "" }, "require": { @@ -912,9 +971,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -958,7 +1014,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.29.0" }, "funding": [ { @@ -974,7 +1030,7 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" } ], "packages-dev": [ @@ -1075,16 +1131,16 @@ }, { "name": "fidry/cpu-core-counter", - "version": "1.0.0", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/theofidry/cpu-core-counter.git", - "reference": "85193c0b0cb5c47894b5eaec906e946f054e7077" + "reference": "f92996c4d5c1a696a6a970e20f7c4216200fcc42" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/85193c0b0cb5c47894b5eaec906e946f054e7077", - "reference": "85193c0b0cb5c47894b5eaec906e946f054e7077", + "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/f92996c4d5c1a696a6a970e20f7c4216200fcc42", + "reference": "f92996c4d5c1a696a6a970e20f7c4216200fcc42", "shasum": "" }, "require": { @@ -1124,7 +1180,7 @@ ], "support": { "issues": "https://github.com/theofidry/cpu-core-counter/issues", - "source": "https://github.com/theofidry/cpu-core-counter/tree/1.0.0" + "source": "https://github.com/theofidry/cpu-core-counter/tree/1.1.0" }, "funding": [ { @@ -1132,20 +1188,20 @@ "type": "github" } ], - "time": "2023-09-17T21:38:23+00:00" + "time": "2024-02-07T09:43:46+00:00" }, { "name": "jean85/pretty-package-versions", - "version": "2.0.5", + "version": "2.0.6", "source": { "type": "git", "url": "https://github.com/Jean85/pretty-package-versions.git", - "reference": "ae547e455a3d8babd07b96966b17d7fd21d9c6af" + "reference": "f9fdd29ad8e6d024f52678b570e5593759b550b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/ae547e455a3d8babd07b96966b17d7fd21d9c6af", - "reference": "ae547e455a3d8babd07b96966b17d7fd21d9c6af", + "url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/f9fdd29ad8e6d024f52678b570e5593759b550b4", + "reference": "f9fdd29ad8e6d024f52678b570e5593759b550b4", "shasum": "" }, "require": { @@ -1153,9 +1209,9 @@ "php": "^7.1|^8.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.17", + "friendsofphp/php-cs-fixer": "^3.2", "jean85/composer-provided-replaced-stub-package": "^1.0", - "phpstan/phpstan": "^0.12.66", + "phpstan/phpstan": "^1.4", "phpunit/phpunit": "^7.5|^8.5|^9.4", "vimeo/psalm": "^4.3" }, @@ -1189,9 +1245,9 @@ ], "support": { "issues": "https://github.com/Jean85/pretty-package-versions/issues", - "source": "https://github.com/Jean85/pretty-package-versions/tree/2.0.5" + "source": "https://github.com/Jean85/pretty-package-versions/tree/2.0.6" }, - "time": "2021-10-08T21:21:46+00:00" + "time": "2024-03-08T09:58:59+00:00" }, { "name": "myclabs/deep-copy", @@ -1254,16 +1310,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.0.0", + "version": "v5.0.2", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "4a21235f7e56e713259a6f76bf4b5ea08502b9dc" + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4a21235f7e56e713259a6f76bf4b5ea08502b9dc", - "reference": "4a21235f7e56e713259a6f76bf4b5ea08502b9dc", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/139676794dc1e9231bf7bcd123cfc0c99182cb13", + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13", "shasum": "" }, "require": { @@ -1306,26 +1362,27 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.2" }, - "time": "2024-01-07T17:17:35+00:00" + "time": "2024-03-05T20:51:40+00:00" }, { "name": "phar-io/manifest", - "version": "2.0.3", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "97803eca37d319dfa7826cc2437fc020857acb53" + "reference": "54750ef60c58e43759730615a392c31c80e23176" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", - "reference": "97803eca37d319dfa7826cc2437fc020857acb53", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176", + "reference": "54750ef60c58e43759730615a392c31c80e23176", "shasum": "" }, "require": { "ext-dom": "*", + "ext-libxml": "*", "ext-phar": "*", "ext-xmlwriter": "*", "phar-io/version": "^3.0.1", @@ -1366,9 +1423,15 @@ "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", "support": { "issues": "https://github.com/phar-io/manifest/issues", - "source": "https://github.com/phar-io/manifest/tree/2.0.3" + "source": "https://github.com/phar-io/manifest/tree/2.0.4" }, - "time": "2021-07-20T11:28:43+00:00" + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:33:53+00:00" }, { "name": "phar-io/version", @@ -1423,16 +1486,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "10.1.11", + "version": "10.1.14", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "78c3b7625965c2513ee96569a4dbb62601784145" + "reference": "e3f51450ebffe8e0efdf7346ae966a656f7d5e5b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/78c3b7625965c2513ee96569a4dbb62601784145", - "reference": "78c3b7625965c2513ee96569a4dbb62601784145", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/e3f51450ebffe8e0efdf7346ae966a656f7d5e5b", + "reference": "e3f51450ebffe8e0efdf7346ae966a656f7d5e5b", "shasum": "" }, "require": { @@ -1489,7 +1552,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.11" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.14" }, "funding": [ { @@ -1497,7 +1560,7 @@ "type": "github" } ], - "time": "2023-12-21T15:38:30+00:00" + "time": "2024-03-12T15:33:41+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1744,16 +1807,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.5.9", + "version": "10.5.20", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "0bd663704f0165c9e76fe4f06ffa6a1ca727fdbe" + "reference": "547d314dc24ec1e177720d45c6263fb226cc2ae3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0bd663704f0165c9e76fe4f06ffa6a1ca727fdbe", - "reference": "0bd663704f0165c9e76fe4f06ffa6a1ca727fdbe", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/547d314dc24ec1e177720d45c6263fb226cc2ae3", + "reference": "547d314dc24ec1e177720d45c6263fb226cc2ae3", "shasum": "" }, "require": { @@ -1825,7 +1888,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.9" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.20" }, "funding": [ { @@ -1841,7 +1904,7 @@ "type": "tidelift" } ], - "time": "2024-01-22T14:35:40+00:00" + "time": "2024-04-24T06:32:35+00:00" }, { "name": "psr/container", @@ -1898,16 +1961,16 @@ }, { "name": "sebastian/cli-parser", - "version": "2.0.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/cli-parser.git", - "reference": "efdc130dbbbb8ef0b545a994fd811725c5282cae" + "reference": "c34583b87e7b7a8055bf6c450c2c77ce32a24084" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/efdc130dbbbb8ef0b545a994fd811725c5282cae", - "reference": "efdc130dbbbb8ef0b545a994fd811725c5282cae", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/c34583b87e7b7a8055bf6c450c2c77ce32a24084", + "reference": "c34583b87e7b7a8055bf6c450c2c77ce32a24084", "shasum": "" }, "require": { @@ -1942,7 +2005,8 @@ "homepage": "https://github.com/sebastianbergmann/cli-parser", "support": { "issues": "https://github.com/sebastianbergmann/cli-parser/issues", - "source": "https://github.com/sebastianbergmann/cli-parser/tree/2.0.0" + "security": "https://github.com/sebastianbergmann/cli-parser/security/policy", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/2.0.1" }, "funding": [ { @@ -1950,7 +2014,7 @@ "type": "github" } ], - "time": "2023-02-03T06:58:15+00:00" + "time": "2024-03-02T07:12:49+00:00" }, { "name": "sebastian/code-unit", @@ -2200,16 +2264,16 @@ }, { "name": "sebastian/diff", - "version": "5.1.0", + "version": "5.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "fbf413a49e54f6b9b17e12d900ac7f6101591b7f" + "reference": "c41e007b4b62af48218231d6c2275e4c9b975b2e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/fbf413a49e54f6b9b17e12d900ac7f6101591b7f", - "reference": "fbf413a49e54f6b9b17e12d900ac7f6101591b7f", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/c41e007b4b62af48218231d6c2275e4c9b975b2e", + "reference": "c41e007b4b62af48218231d6c2275e4c9b975b2e", "shasum": "" }, "require": { @@ -2217,7 +2281,7 @@ }, "require-dev": { "phpunit/phpunit": "^10.0", - "symfony/process": "^4.2 || ^5" + "symfony/process": "^6.4" }, "type": "library", "extra": { @@ -2255,7 +2319,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", "security": "https://github.com/sebastianbergmann/diff/security/policy", - "source": "https://github.com/sebastianbergmann/diff/tree/5.1.0" + "source": "https://github.com/sebastianbergmann/diff/tree/5.1.1" }, "funding": [ { @@ -2263,20 +2327,20 @@ "type": "github" } ], - "time": "2023-12-22T10:55:06+00:00" + "time": "2024-03-02T07:15:17+00:00" }, { "name": "sebastian/environment", - "version": "6.0.1", + "version": "6.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951" + "reference": "8074dbcd93529b357029f5cc5058fd3e43666984" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/43c751b41d74f96cbbd4e07b7aec9675651e2951", - "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/8074dbcd93529b357029f5cc5058fd3e43666984", + "reference": "8074dbcd93529b357029f5cc5058fd3e43666984", "shasum": "" }, "require": { @@ -2291,7 +2355,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "6.0-dev" + "dev-main": "6.1-dev" } }, "autoload": { @@ -2319,7 +2383,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", "security": "https://github.com/sebastianbergmann/environment/security/policy", - "source": "https://github.com/sebastianbergmann/environment/tree/6.0.1" + "source": "https://github.com/sebastianbergmann/environment/tree/6.1.0" }, "funding": [ { @@ -2327,20 +2391,20 @@ "type": "github" } ], - "time": "2023-04-11T05:39:26+00:00" + "time": "2024-03-23T08:47:14+00:00" }, { "name": "sebastian/exporter", - "version": "5.1.1", + "version": "5.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "64f51654862e0f5e318db7e9dcc2292c63cdbddc" + "reference": "955288482d97c19a372d3f31006ab3f37da47adf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/64f51654862e0f5e318db7e9dcc2292c63cdbddc", - "reference": "64f51654862e0f5e318db7e9dcc2292c63cdbddc", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/955288482d97c19a372d3f31006ab3f37da47adf", + "reference": "955288482d97c19a372d3f31006ab3f37da47adf", "shasum": "" }, "require": { @@ -2397,7 +2461,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", "security": "https://github.com/sebastianbergmann/exporter/security/policy", - "source": "https://github.com/sebastianbergmann/exporter/tree/5.1.1" + "source": "https://github.com/sebastianbergmann/exporter/tree/5.1.2" }, "funding": [ { @@ -2405,20 +2469,20 @@ "type": "github" } ], - "time": "2023-09-24T13:22:09+00:00" + "time": "2024-03-02T07:17:12+00:00" }, { "name": "sebastian/global-state", - "version": "6.0.1", + "version": "6.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4" + "reference": "987bafff24ecc4c9ac418cab1145b96dd6e9cbd9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/7ea9ead78f6d380d2a667864c132c2f7b83055e4", - "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/987bafff24ecc4c9ac418cab1145b96dd6e9cbd9", + "reference": "987bafff24ecc4c9ac418cab1145b96dd6e9cbd9", "shasum": "" }, "require": { @@ -2452,14 +2516,14 @@ } ], "description": "Snapshotting of global state", - "homepage": "http://www.github.com/sebastianbergmann/global-state", + "homepage": "https://www.github.com/sebastianbergmann/global-state", "keywords": [ "global state" ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", "security": "https://github.com/sebastianbergmann/global-state/security/policy", - "source": "https://github.com/sebastianbergmann/global-state/tree/6.0.1" + "source": "https://github.com/sebastianbergmann/global-state/tree/6.0.2" }, "funding": [ { @@ -2467,7 +2531,7 @@ "type": "github" } ], - "time": "2023-07-19T07:19:23+00:00" + "time": "2024-03-02T07:19:19+00:00" }, { "name": "sebastian/lines-of-code", @@ -2813,16 +2877,16 @@ }, { "name": "symfony/console", - "version": "v6.4.3", + "version": "v6.4.7", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "2aaf83b4de5b9d43b93e4aec6f2f8b676f7c567e" + "reference": "a170e64ae10d00ba89e2acbb590dc2e54da8ad8f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/2aaf83b4de5b9d43b93e4aec6f2f8b676f7c567e", - "reference": "2aaf83b4de5b9d43b93e4aec6f2f8b676f7c567e", + "url": "https://api.github.com/repos/symfony/console/zipball/a170e64ae10d00ba89e2acbb590dc2e54da8ad8f", + "reference": "a170e64ae10d00ba89e2acbb590dc2e54da8ad8f", "shasum": "" }, "require": { @@ -2887,7 +2951,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v6.4.3" + "source": "https://github.com/symfony/console/tree/v6.4.7" }, "funding": [ { @@ -2903,20 +2967,20 @@ "type": "tidelift" } ], - "time": "2024-01-23T14:51:35+00:00" + "time": "2024-04-18T09:22:46+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb" + "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", - "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ef4d7e442ca910c4764bce785146269b30cb5fc4", + "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4", "shasum": "" }, "require": { @@ -2930,9 +2994,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -2969,7 +3030,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.29.0" }, "funding": [ { @@ -2985,20 +3046,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "875e90aeea2777b6f135677f618529449334a612" + "reference": "32a9da87d7b3245e09ac426c83d334ae9f06f80f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/875e90aeea2777b6f135677f618529449334a612", - "reference": "875e90aeea2777b6f135677f618529449334a612", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/32a9da87d7b3245e09ac426c83d334ae9f06f80f", + "reference": "32a9da87d7b3245e09ac426c83d334ae9f06f80f", "shasum": "" }, "require": { @@ -3009,9 +3070,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -3050,7 +3108,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.29.0" }, "funding": [ { @@ -3066,20 +3124,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92" + "reference": "bc45c394692b948b4d383a08d7753968bed9a83d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92", - "reference": "8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/bc45c394692b948b4d383a08d7753968bed9a83d", + "reference": "bc45c394692b948b4d383a08d7753968bed9a83d", "shasum": "" }, "require": { @@ -3090,9 +3148,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -3134,7 +3189,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.29.0" }, "funding": [ { @@ -3150,20 +3205,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "42292d99c55abe617799667f454222c54c60e229" + "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/42292d99c55abe617799667f454222c54c60e229", - "reference": "42292d99c55abe617799667f454222c54c60e229", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9773676c8a1bb1f8d4340a62efe641cf76eda7ec", + "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec", "shasum": "" }, "require": { @@ -3177,9 +3232,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -3217,7 +3269,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.29.0" }, "funding": [ { @@ -3233,20 +3285,20 @@ "type": "tidelift" } ], - "time": "2023-07-28T09:04:16+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/process", - "version": "v6.4.3", + "version": "v6.4.7", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "31642b0818bfcff85930344ef93193f8c607e0a3" + "reference": "cdb1c81c145fd5aa9b0038bab694035020943381" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/31642b0818bfcff85930344ef93193f8c607e0a3", - "reference": "31642b0818bfcff85930344ef93193f8c607e0a3", + "url": "https://api.github.com/repos/symfony/process/zipball/cdb1c81c145fd5aa9b0038bab694035020943381", + "reference": "cdb1c81c145fd5aa9b0038bab694035020943381", "shasum": "" }, "require": { @@ -3278,7 +3330,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v6.4.3" + "source": "https://github.com/symfony/process/tree/v6.4.7" }, "funding": [ { @@ -3294,25 +3346,26 @@ "type": "tidelift" } ], - "time": "2024-01-23T14:51:35+00:00" + "time": "2024-04-18T09:22:46+00:00" }, { "name": "symfony/service-contracts", - "version": "v3.4.1", + "version": "v3.5.0", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "fe07cbc8d837f60caf7018068e350cc5163681a0" + "reference": "bd1d9e59a81d8fa4acdcea3f617c581f7475a80f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/fe07cbc8d837f60caf7018068e350cc5163681a0", - "reference": "fe07cbc8d837f60caf7018068e350cc5163681a0", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/bd1d9e59a81d8fa4acdcea3f617c581f7475a80f", + "reference": "bd1d9e59a81d8fa4acdcea3f617c581f7475a80f", "shasum": "" }, "require": { "php": ">=8.1", - "psr/container": "^1.1|^2.0" + "psr/container": "^1.1|^2.0", + "symfony/deprecation-contracts": "^2.5|^3" }, "conflict": { "ext-psr": "<1.1|>=2" @@ -3320,7 +3373,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.4-dev" + "dev-main": "3.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -3360,7 +3413,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.4.1" + "source": "https://github.com/symfony/service-contracts/tree/v3.5.0" }, "funding": [ { @@ -3376,20 +3429,20 @@ "type": "tidelift" } ], - "time": "2023-12-26T14:02:43+00:00" + "time": "2024-04-18T09:32:20+00:00" }, { "name": "symfony/string", - "version": "v6.4.3", + "version": "v6.4.7", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "7a14736fb179876575464e4658fce0c304e8c15b" + "reference": "ffeb9591c61f65a68d47f77d12b83fa530227a69" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/7a14736fb179876575464e4658fce0c304e8c15b", - "reference": "7a14736fb179876575464e4658fce0c304e8c15b", + "url": "https://api.github.com/repos/symfony/string/zipball/ffeb9591c61f65a68d47f77d12b83fa530227a69", + "reference": "ffeb9591c61f65a68d47f77d12b83fa530227a69", "shasum": "" }, "require": { @@ -3446,7 +3499,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v6.4.3" + "source": "https://github.com/symfony/string/tree/v6.4.7" }, "funding": [ { @@ -3462,20 +3515,20 @@ "type": "tidelift" } ], - "time": "2024-01-25T09:26:29+00:00" + "time": "2024-04-18T09:22:46+00:00" }, { "name": "theseer/tokenizer", - "version": "1.2.2", + "version": "1.2.3", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96" + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/b2ad5003ca10d4ee50a12da31de12a5774ba6b96", - "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", "shasum": "" }, "require": { @@ -3504,7 +3557,7 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "support": { "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/1.2.2" + "source": "https://github.com/theseer/tokenizer/tree/1.2.3" }, "funding": [ { @@ -3512,7 +3565,7 @@ "type": "github" } ], - "time": "2023-11-20T00:12:19+00:00" + "time": "2024-03-03T12:36:25+00:00" } ], "aliases": [], @@ -3524,5 +3577,5 @@ "php": ">=8.1.0" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.1.0" } diff --git a/src/Charts/Charts.php b/src/Charts/Charts.php index bb9874d..b0ae3ca 100644 --- a/src/Charts/Charts.php +++ b/src/Charts/Charts.php @@ -4,8 +4,8 @@ use GuzzleHttp\Client; use GuzzleHttp\UriTemplate\UriTemplate; -use GuzzleHttp\Utils; use Psr\Http\Message\StreamInterface; +use Seatsio\GuzzleResponseDecoder; use Seatsio\PageFetcher; use Seatsio\SeatsioJsonMapper; use stdClass; @@ -44,7 +44,7 @@ public function create(string $name = null, string $venueType = null, array $cat $request->categories = $categories; } $res = $this->client->post('/charts', ['json' => $request]); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new Chart()); } @@ -82,9 +82,8 @@ public function removeCategory(string $key, $categoryKey): void public function listCategories(string $chartKey): array { $res = $this->client->get('/charts/' . $chartKey . '/categories'); - $json = Utils::jsonDecode($res->getBody()); - $mapper = SeatsioJsonMapper::create(); - return array_map(function($cat) { + $json = GuzzleResponseDecoder::decodeToObject($res); + return array_map(function ($cat) { return new Category($cat->key, $cat->label, $cat->color, $cat->accessible); }, $json->categories); } @@ -103,7 +102,7 @@ public function updateCategory(string $chartKey, $categoryKey, CategoryUpdatePar public function retrieve(string $key): Chart { $res = $this->client->get('/charts/' . $key); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new Chart()); } @@ -111,7 +110,7 @@ public function retrieve(string $key): Chart public function retrieveWithEvents(string $key): Chart { $res = $this->client->get('/charts/' . $key . '?expand=events'); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new Chart()); } @@ -119,13 +118,13 @@ public function retrieveWithEvents(string $key): Chart public function retrievePublishedVersion(string $key): object { $res = $this->client->get('/charts/' . $key . '/version/published'); - return Utils::jsonDecode($res->getBody()); + return GuzzleResponseDecoder::decodeToObject($res); } public function retrieveDraftVersion(string $key): object { $res = $this->client->get('/charts/' . $key . '/version/draft'); - return Utils::jsonDecode($res->getBody()); + return GuzzleResponseDecoder::decodeToObject($res); } public function publishDraftVersion(string $key): void @@ -151,7 +150,7 @@ public function moveOutOfArchive(string $key): void public function copy(string $key): Chart { $res = $this->client->post('/charts/' . $key . '/version/published/actions/copy'); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new Chart()); } @@ -159,7 +158,7 @@ public function copy(string $key): Chart public function copyDraftVersion(string $key): Chart { $res = $this->client->post('/charts/' . $key . '/version/draft/actions/copy'); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new Chart()); } @@ -167,7 +166,7 @@ public function copyDraftVersion(string $key): Chart public function copyToWorkspace(string $chartKey, string $toWorkspaceKey): Chart { $res = $this->client->post('/charts/' . $chartKey . '/version/published/actions/copy-to-workspace/' . $toWorkspaceKey); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new Chart()); } @@ -175,7 +174,7 @@ public function copyToWorkspace(string $chartKey, string $toWorkspaceKey): Chart public function copyFromWorkspaceTo(string $chartKey, string $fromWorkspaceKey, string $toWorkspaceKey): Chart { $res = $this->client->post('/charts/' . $chartKey . '/version/published/actions/copy/from/' . $fromWorkspaceKey . '/to/' . $toWorkspaceKey); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new Chart()); } @@ -189,13 +188,13 @@ public function retrievePublishedVersionThumbnail(string $key): StreamInterface public function validatePublishedVersion(string $key): object { $res = $this->client->post('/charts/' . $key . '/version/published/actions/validate'); - return Utils::jsonDecode($res->getBody()); + return GuzzleResponseDecoder::decodeToObject($res); } public function validateDraftVersion(string $key): object { $res = $this->client->post('/charts/' . $key . '/version/draft/actions/validate'); - return Utils::jsonDecode($res->getBody()); + return GuzzleResponseDecoder::decodeToObject($res); } public function retrieveDraftVersionThumbnail(string $key): StreamInterface @@ -210,7 +209,7 @@ public function retrieveDraftVersionThumbnail(string $key): StreamInterface public function listAllTags(): array { $res = $this->client->get('/charts/tags'); - return Utils::jsonDecode($res->getBody())->tags; + return GuzzleResponseDecoder::decodeToObject($res)->tags; } public function addTag(string $key, string $tag): void diff --git a/src/Events/Event.php b/src/Events/Event.php index c1d26de..bffd3cd 100644 --- a/src/Events/Event.php +++ b/src/Events/Event.php @@ -2,8 +2,6 @@ namespace Seatsio\Events; -use Seatsio\LocalDate; - class Event { /** diff --git a/src/Events/Events.php b/src/Events/Events.php index 68b2511..ecfb0ce 100644 --- a/src/Events/Events.php +++ b/src/Events/Events.php @@ -5,7 +5,7 @@ use GuzzleHttp\Client; use GuzzleHttp\Psr7\Query; use GuzzleHttp\UriTemplate\UriTemplate; -use GuzzleHttp\Utils; +use Seatsio\GuzzleResponseDecoder; use Seatsio\PageFetcher; use Seatsio\Seasons\Season; use Seatsio\SeatsioJsonMapper; @@ -72,7 +72,7 @@ public function create(string $chartKey, CreateEventParams $params = null): Even } $res = $this->client->post('/events', ['json' => $request]); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new Event()); } @@ -124,16 +124,16 @@ public function createMultiple(string $chartKey, array $createEventParams): arra } $res = $this->client->post('/events/actions/create-multiple', ['json' => $request]); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res, '/events'); $mapper = SeatsioJsonMapper::create(); - return $mapper->mapArray($json->events, array(), 'Seatsio\Events\Event'); + return $mapper->mapArray($json, array(), 'Seatsio\Events\Event'); } public function retrieve(string $eventKey): Event { $res = $this->client->get(UriTemplate::expand('/events/{key}', array("key" => $eventKey))); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToObject($res); $mapper = SeatsioJsonMapper::create(); if ($json->isSeason) { return $mapper->map($json, new Season()); @@ -327,7 +327,7 @@ public function retrieveObjectInfos(string $eventKey, array $objectLabels): arra { $options = ['query' => Query::build(["label" => $objectLabels])]; $res = $this->client->get(UriTemplate::expand('/events/{key}/objects', ["key" => $eventKey]), $options); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); $result = []; foreach ($json as $objectLabel => $objectInfo) { @@ -377,7 +377,7 @@ public function changeObjectStatus($eventKeyOrKeys, $objectOrObjects, string $st '/events/groups/actions/change-object-status', ['json' => $request, 'query' => ['expand' => 'objects']] ); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new ChangeObjectStatusResult()); } @@ -396,9 +396,9 @@ public function changeObjectStatusInBatch(array $statusChangeRequests): array '/events/actions/change-object-status', ['json' => $request, 'query' => ['expand' => 'objects']] ); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res, '/results'); $mapper = SeatsioJsonMapper::create(); - return $mapper->mapArray($json->results, array(), ChangeObjectStatusResult::class); + return $mapper->mapArray($json, array(), ChangeObjectStatusResult::class); } private function serializeStatusChangeRequest($statusChangeRequest) @@ -534,7 +534,7 @@ public function changeBestAvailableObjectStatus(string $eventKey, int $number, s UriTemplate::expand('/events/{key}/actions/change-object-status', array("key" => $eventKey)), ['json' => $request] ); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new BestAvailableObjects()); } diff --git a/src/GuzzleResponseDecoder.php b/src/GuzzleResponseDecoder.php new file mode 100644 index 0000000..1103fa8 --- /dev/null +++ b/src/GuzzleResponseDecoder.php @@ -0,0 +1,46 @@ +getBody()), $options); + } + + public static function decodeToObject($res) + { + $mapper = self::mapperThatSetsUnknownProperties(); + $json = GuzzleResponseDecoder::decodeToJson($res); + return $mapper->map($json, 'stdClass'); + } + + public static function decodeToArray($res) + { + return Utils::jsonDecode($res->getBody(), true); + } + + /** + * @return JsonMapper + */ + public static function mapperThatSetsUnknownProperties(): JsonMapper + { + $mapper = new JsonMapper(); + $mapper->undefinedPropertyHandler = function ($object, $propName, $jsonValue) { + $object->{$propName} = $jsonValue; + }; + return $mapper; + } +} diff --git a/src/HoldTokens/HoldTokens.php b/src/HoldTokens/HoldTokens.php index 46c3125..cc6ce1d 100644 --- a/src/HoldTokens/HoldTokens.php +++ b/src/HoldTokens/HoldTokens.php @@ -3,7 +3,7 @@ namespace Seatsio\HoldTokens; use GuzzleHttp\Client; -use GuzzleHttp\Utils; +use Seatsio\GuzzleResponseDecoder; use Seatsio\SeatsioJsonMapper; use stdClass; @@ -27,7 +27,7 @@ public function create(int $expiresInMinutes = null): HoldToken $request->expiresInMinutes = $expiresInMinutes; } $res = $this->client->post('/hold-tokens', ['json' => $request]); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new HoldToken()); } @@ -37,7 +37,7 @@ public function expireInMinutes(string $holdToken, int $minutes): HoldToken $request = new stdClass(); $request->expiresInMinutes = $minutes; $res = $this->client->post('/hold-tokens/' . $holdToken, ['json' => $request]); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new HoldToken()); } @@ -45,7 +45,7 @@ public function expireInMinutes(string $holdToken, int $minutes): HoldToken public function retrieve(string $holdToken): HoldToken { $res = $this->client->get('/hold-tokens/' . $holdToken); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new HoldToken()); } diff --git a/src/PageFetcher.php b/src/PageFetcher.php index abfaaf4..25fa706 100644 --- a/src/PageFetcher.php +++ b/src/PageFetcher.php @@ -3,7 +3,6 @@ namespace Seatsio; use GuzzleHttp\Client; -use GuzzleHttp\Utils; class PageFetcher { @@ -46,7 +45,7 @@ public function fetch($queryParams, $pageSize) } $mergedQueryParams = $this->queryParams ? array_merge($queryParams, $this->queryParams) : $queryParams; $res = $this->client->get($this->url, ['query' => $mergedQueryParams]); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, $this->pageCreator->__invoke()); } diff --git a/src/Reports/Charts/ChartReports.php b/src/Reports/Charts/ChartReports.php index 2d14cfe..0351600 100644 --- a/src/Reports/Charts/ChartReports.php +++ b/src/Reports/Charts/ChartReports.php @@ -3,11 +3,10 @@ namespace Seatsio\Reports\Charts; use GuzzleHttp\Client; -use GuzzleHttp\Utils; -use Seatsio\SeatsioJsonMapper; use GuzzleHttp\UriTemplate\UriTemplate; use Seatsio\Charts\ChartObjectInfo; -use function Symfony\Component\String\b; +use Seatsio\GuzzleResponseDecoder; +use Seatsio\SeatsioJsonMapper; class ChartReports { @@ -98,14 +97,14 @@ private static function summaryReportUrl($reportType, $chartKey): string private function getChartReport(string $reportType, string $chartKey, ?string $bookWholeTables, ?string $version): array { $res = $this->client->get(self::reportUrl($reportType, $chartKey), ["query" => ["bookWholeTables" => $bookWholeTables, "version" => $version]]); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); return $this->mapMultiValuedReport($json); } private function getChartSummaryReport(string $reportType, string $chartKey, ?string $bookWholeTables, ?string $version): array { $res = $this->client->get(self::summaryReportUrl($reportType, $chartKey), ["query" => ["bookWholeTables" => $bookWholeTables, "version" => $version]]); - return Utils::jsonDecode($res->getBody(), true); + return GuzzleResponseDecoder::decodeToArray($res); } /** diff --git a/src/Reports/Events/EventReports.php b/src/Reports/Events/EventReports.php index 2a69a73..f3abab1 100644 --- a/src/Reports/Events/EventReports.php +++ b/src/Reports/Events/EventReports.php @@ -4,8 +4,8 @@ use GuzzleHttp\Client; use GuzzleHttp\UriTemplate\UriTemplate; -use GuzzleHttp\Utils; use Seatsio\Events\EventObjectInfo; +use Seatsio\GuzzleResponseDecoder; use Seatsio\SeatsioJsonMapper; class EventReports @@ -27,21 +27,21 @@ public function __construct(Client $client) public function byStatus(string $eventKey, string $status = null): array { $res = $this->client->get(self::reportUrl('byStatus', $eventKey, $status)); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); return $this->mapMultiValuedReport($json, $status); } public function summaryByStatus(string $eventKey): array { $res = $this->client->get(self::summaryReportUrl('byStatus', $eventKey)); - $json = Utils::jsonDecode($res->getBody(), true); + $json = GuzzleResponseDecoder::decodeToArray($res); return $json; } public function deepSummaryByStatus(string $eventKey): array { $res = $this->client->get(self::deepSummaryReportUrl('byStatus', $eventKey)); - $json = Utils::jsonDecode($res->getBody(), true); + $json = GuzzleResponseDecoder::decodeToArray($res); return $json; } @@ -51,21 +51,21 @@ public function deepSummaryByStatus(string $eventKey): array public function byObjectType(string $eventKey, string $objectType = null): array { $res = $this->client->get(self::reportUrl('byObjectType', $eventKey, $objectType)); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); return $this->mapMultiValuedReport($json, $objectType); } public function summaryByObjectType(string $eventKey): array { $res = $this->client->get(self::summaryReportUrl('byObjectType', $eventKey)); - $json = Utils::jsonDecode($res->getBody(), true); + $json = GuzzleResponseDecoder::decodeToArray($res); return $json; } public function deepSummaryByObjectType(string $eventKey): array { $res = $this->client->get(self::deepSummaryReportUrl('byObjectType', $eventKey)); - $json = Utils::jsonDecode($res->getBody(), true); + $json = GuzzleResponseDecoder::decodeToArray($res); return $json; } @@ -75,20 +75,20 @@ public function deepSummaryByObjectType(string $eventKey): array public function byCategoryLabel(string $eventKey, string $categoryLabel = null): array { $res = $this->client->get(self::reportUrl('byCategoryLabel', $eventKey, $categoryLabel)); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); return $this->mapMultiValuedReport($json, $categoryLabel); } public function summaryByCategoryLabel(string $eventKey): array { $res = $this->client->get(self::summaryReportUrl('byCategoryLabel', $eventKey)); - return Utils::jsonDecode($res->getBody(), true); + return GuzzleResponseDecoder::decodeToArray($res); } public function deepSummaryByCategoryLabel(string $eventKey): array { $res = $this->client->get(self::deepSummaryReportUrl('byCategoryLabel', $eventKey)); - return Utils::jsonDecode($res->getBody(), true); + return GuzzleResponseDecoder::decodeToArray($res); } /** @@ -97,20 +97,20 @@ public function deepSummaryByCategoryLabel(string $eventKey): array public function byCategoryKey(string $eventKey, string $categoryKey = null): array { $res = $this->client->get(self::reportUrl('byCategoryKey', $eventKey, $categoryKey)); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); return $this->mapMultiValuedReport($json, $categoryKey); } public function summaryByCategoryKey(string $eventKey): array { $res = $this->client->get(self::summaryReportUrl('byCategoryKey', $eventKey)); - return Utils::jsonDecode($res->getBody(), true); + return GuzzleResponseDecoder::decodeToArray($res); } public function deepSummaryByCategoryKey(string $eventKey): array { $res = $this->client->get(self::deepSummaryReportUrl('byCategoryKey', $eventKey)); - return Utils::jsonDecode($res->getBody(), true); + return GuzzleResponseDecoder::decodeToArray($res); } /** @@ -119,7 +119,7 @@ public function deepSummaryByCategoryKey(string $eventKey): array public function byLabel(string $eventKey, string $label = null): array { $res = $this->client->get(self::reportUrl('byLabel', $eventKey, $label)); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); return $this->mapMultiValuedReport($json, $label); } @@ -129,7 +129,7 @@ public function byLabel(string $eventKey, string $label = null): array public function byOrderId(string $eventKey, string $orderId = null): array { $res = $this->client->get(self::reportUrl('byOrderId', $eventKey, $orderId)); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); return $this->mapMultiValuedReport($json, $orderId); } @@ -139,20 +139,20 @@ public function byOrderId(string $eventKey, string $orderId = null): array public function bySection(string $eventKey, string $section = null): array { $res = $this->client->get(self::reportUrl('bySection', $eventKey, $section)); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); return $this->mapMultiValuedReport($json, $section); } public function summaryBySection(string $eventKey): array { $res = $this->client->get(self::summaryReportUrl('bySection', $eventKey)); - return Utils::jsonDecode($res->getBody(), true); + return GuzzleResponseDecoder::decodeToArray($res); } public function deepSummaryBySection(string $eventKey): array { $res = $this->client->get(self::deepSummaryReportUrl('bySection', $eventKey)); - return Utils::jsonDecode($res->getBody(), true); + return GuzzleResponseDecoder::decodeToArray($res); } /** @@ -161,20 +161,20 @@ public function deepSummaryBySection(string $eventKey): array public function byChannel(string $eventKey, string $channel = null): array { $res = $this->client->get(self::reportUrl('byChannel', $eventKey, $channel)); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); return $this->mapMultiValuedReport($json, $channel); } public function summaryByChannel(string $eventKey): array { $res = $this->client->get(self::summaryReportUrl('byChannel', $eventKey)); - return Utils::jsonDecode($res->getBody(), true); + return GuzzleResponseDecoder::decodeToArray($res); } public function deepSummaryByChannel(string $eventKey): array { $res = $this->client->get(self::deepSummaryReportUrl('byChannel', $eventKey)); - return Utils::jsonDecode($res->getBody(), true); + return GuzzleResponseDecoder::decodeToArray($res); } /** @@ -183,7 +183,7 @@ public function deepSummaryByChannel(string $eventKey): array public function byAvailability(string $eventKey, string $selectability = null): array { $res = $this->client->get(self::reportUrl('byAvailability', $eventKey, $selectability)); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); return $this->mapMultiValuedReport($json, $selectability); } @@ -193,7 +193,7 @@ public function byAvailability(string $eventKey, string $selectability = null): public function byAvailabilityReason(string $eventKey, string $availabilityReason = null): array { $res = $this->client->get(self::reportUrl('byAvailabilityReason', $eventKey, $availabilityReason)); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); return $this->mapMultiValuedReport($json, $availabilityReason); } @@ -203,7 +203,7 @@ public function byAvailabilityReason(string $eventKey, string $availabilityReaso public function summaryByAvailability(string $eventKey): array { $res = $this->client->get(self::summaryReportUrl('byAvailability', $eventKey)); - return Utils::jsonDecode($res->getBody(), true); + return GuzzleResponseDecoder::decodeToArray($res); } /** @@ -212,19 +212,19 @@ public function summaryByAvailability(string $eventKey): array public function summaryByAvailabilityReason(string $eventKey): array { $res = $this->client->get(self::summaryReportUrl('byAvailabilityReason', $eventKey)); - return Utils::jsonDecode($res->getBody(), true); + return GuzzleResponseDecoder::decodeToArray($res); } public function deepSummaryByAvailability(string $eventKey): array { $res = $this->client->get(self::deepSummaryReportUrl('byAvailability', $eventKey)); - return Utils::jsonDecode($res->getBody(), true); + return GuzzleResponseDecoder::decodeToArray($res); } public function deepSummaryByAvailabilityReason(string $eventKey): array { $res = $this->client->get(self::deepSummaryReportUrl('byAvailabilityReason', $eventKey)); - return Utils::jsonDecode($res->getBody(), true); + return GuzzleResponseDecoder::decodeToArray($res); } /** diff --git a/src/Reports/Usage/UsageReports.php b/src/Reports/Usage/UsageReports.php index d4453d4..90345a1 100644 --- a/src/Reports/Usage/UsageReports.php +++ b/src/Reports/Usage/UsageReports.php @@ -3,13 +3,12 @@ namespace Seatsio\Reports\Usage; use GuzzleHttp\Client; -use GuzzleHttp\Utils; +use Seatsio\GuzzleResponseDecoder; use Seatsio\Reports\Usage\DetailsForEventInMonth\UsageForObjectV1; use Seatsio\Reports\Usage\DetailsForEventInMonth\UsageForObjectV2; use Seatsio\Reports\Usage\DetailsForMonth\UsageDetails; use Seatsio\Reports\Usage\SummaryForMonths\Month; use Seatsio\Reports\Usage\SummaryForMonths\UsageSummaryForAllMonths; -use Seatsio\Reports\Usage\SummaryForMonths\UsageSummaryForMonth; use Seatsio\SeatsioJsonMapper; class UsageReports @@ -28,7 +27,7 @@ public function __construct(Client $client) public function summaryForAllMonths(): UsageSummaryForAllMonths { $res = $this->client->get('/reports/usage?version=2'); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new UsageSummaryForAllMonths()); } @@ -39,7 +38,7 @@ public function summaryForAllMonths(): UsageSummaryForAllMonths public function detailsForMonth(Month $month): array { $res = $this->client->get('/reports/usage/month/' . $month->serialize()); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->mapArray($json, array(), UsageDetails::class); } @@ -50,7 +49,7 @@ public function detailsForMonth(Month $month): array public function detailsForEventInMonth(int $eventId, Month $month): array { $res = $this->client->get('/reports/usage/month/' . $month->serialize() . '/event/' . $eventId); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToArray($res); $mapper = SeatsioJsonMapper::create(); if (count($json) == 0 || !isset($json[0]->usageByReason)) { return $mapper->mapArray($json, array(), UsageForObjectV1::class); diff --git a/src/Seasons/Seasons.php b/src/Seasons/Seasons.php index 63966e0..a0df3e6 100644 --- a/src/Seasons/Seasons.php +++ b/src/Seasons/Seasons.php @@ -4,7 +4,7 @@ use GuzzleHttp\Client; use GuzzleHttp\UriTemplate\UriTemplate; -use GuzzleHttp\Utils; +use Seatsio\GuzzleResponseDecoder; use Seatsio\SeatsioJsonMapper; use stdClass; @@ -57,7 +57,7 @@ public function create(string $chartKey, SeasonCreationParams $seasonCreationPar } $res = $this->client->post('/seasons', ['json' => $request]); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new Season()); } @@ -83,7 +83,7 @@ public function createPartialSeason(string $topLevelSeasonKey, string $partialSe } $res = $this->client->post(UriTemplate::expand('/seasons/{seasonKey}/partial-seasons', ['seasonKey' => $topLevelSeasonKey]), ['json' => $request]); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new Season()); } @@ -93,7 +93,7 @@ public function addEventsToPartialSeason(string $topLevelSeasonKey, string $part $request = new stdClass(); $request->eventKeys = $eventKeys; $res = $this->client->post(UriTemplate::expand('/seasons/{topLevelSeasonKey}/partial-seasons/{partialSeasonKey}/actions/add-events', ['topLevelSeasonKey' => $topLevelSeasonKey, 'partialSeasonKey' => $partialSeasonKey]), ['json' => $request]); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new Season()); } @@ -115,16 +115,16 @@ public function createEvents(string $seasonKey, array $eventKeys = null, int $nu } $res = $this->client->post(UriTemplate::expand('/seasons/{seasonKey}/actions/create-events', ['seasonKey' => $seasonKey]), ['json' => $request]); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res, '/events'); $mapper = SeatsioJsonMapper::create(); - return $mapper->mapArray($json->events, array(), 'Seatsio\Events\Event'); + return $mapper->mapArray($json, array(), 'Seatsio\Events\Event'); } public function removeEventFromPartialSeason(string $topLevelSeasonKey, string $partialSeasonKey, string $eventKey): Season { $request = new stdClass(); $res = $this->client->delete(UriTemplate::expand('/seasons/{topLevelSeasonKey}/partial-seasons/{partialSeasonKey}/events/{eventKey}', ['topLevelSeasonKey' => $topLevelSeasonKey, 'partialSeasonKey' => $partialSeasonKey, 'eventKey' => $eventKey]), ['json' => $request]); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new Season()); } diff --git a/src/SeatsioClient.php b/src/SeatsioClient.php index 41bfa33..b3fdf6d 100644 --- a/src/SeatsioClient.php +++ b/src/SeatsioClient.php @@ -9,11 +9,11 @@ use Seatsio\Charts\Charts; use Seatsio\EventLog\EventLog; use Seatsio\Events\Events; -use Seatsio\Seasons\Seasons; use Seatsio\HoldTokens\HoldTokens; use Seatsio\Reports\Charts\ChartReports; use Seatsio\Reports\Events\EventReports; use Seatsio\Reports\Usage\UsageReports; +use Seatsio\Seasons\Seasons; use Seatsio\Workspaces\Workspaces; class SeatsioClient diff --git a/src/SeatsioException.php b/src/SeatsioException.php index 482b16b..b0e7b16 100644 --- a/src/SeatsioException.php +++ b/src/SeatsioException.php @@ -2,7 +2,6 @@ namespace Seatsio; -use GuzzleHttp\Utils; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use RuntimeException; @@ -50,7 +49,7 @@ private static function extractInfo($response) { $contentType = $response->getHeaderLine("content-type"); if (strpos($contentType, 'application/json') !== false) { - $json = Utils::jsonDecode($response->getBody()); + $json = GuzzleResponseDecoder::decodeToObject($response); $mapper = SeatsioJsonMapper::create(); $errors = $mapper->mapArray($json->errors, array(), 'Seatsio\ApiError'); return ["messages" => $json->messages, "errors" => $errors, "requestId" => $json->requestId ?? null]; diff --git a/src/Workspaces/Workspaces.php b/src/Workspaces/Workspaces.php index 306b740..cc12179 100644 --- a/src/Workspaces/Workspaces.php +++ b/src/Workspaces/Workspaces.php @@ -4,7 +4,7 @@ use GuzzleHttp\Client; use GuzzleHttp\UriTemplate\UriTemplate; -use GuzzleHttp\Utils; +use Seatsio\GuzzleResponseDecoder; use Seatsio\PageFetcher; use Seatsio\SeatsioJsonMapper; use stdClass; @@ -42,7 +42,7 @@ public function create(string $name, bool $isTest = null): Workspace $request->isTest = $isTest; } $res = $this->client->post('/workspaces', ['json' => $request]); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new Workspace()); } @@ -57,8 +57,7 @@ public function update(string $key, string $name): void public function regenerateSecretKey(string $key): string { $res = $this->client->post(UriTemplate::expand('/workspaces/{key}/actions/regenerate-secret-key', array("key" => $key))); - $json = Utils::jsonDecode($res->getBody()); - return $json->secretKey; + return GuzzleResponseDecoder::decodeToObject($res)->secretKey; } public function activate(string $key): void @@ -79,7 +78,7 @@ public function setDefault(string $key): void public function retrieve(string $key): Workspace { $res = $this->client->get(UriTemplate::expand('/workspaces/{key}', array("key" => $key))); - $json = Utils::jsonDecode($res->getBody()); + $json = GuzzleResponseDecoder::decodeToJson($res); $mapper = SeatsioJsonMapper::create(); return $mapper->map($json, new Workspace()); } diff --git a/tests/EventLog/ListAllEventLogItemsTest.php b/tests/EventLog/ListAllEventLogItemsTest.php index d846480..6204e2b 100644 --- a/tests/EventLog/ListAllEventLogItemsTest.php +++ b/tests/EventLog/ListAllEventLogItemsTest.php @@ -2,9 +2,6 @@ namespace Seatsio\EventLog; -use Seatsio\Charts\ChartListParams; -use Seatsio\Events\CreateEventParams; -use Seatsio\Events\ForSaleConfig; use Seatsio\SeatsioClientTest; use function Functional\map; diff --git a/tests/Events/CreateEventsTest.php b/tests/Events/CreateEventsTest.php index 8da175b..b431907 100644 --- a/tests/Events/CreateEventsTest.php +++ b/tests/Events/CreateEventsTest.php @@ -2,7 +2,6 @@ namespace Seatsio\Events; -use Composer\DependencyResolver\LocalRepoTransaction; use Seatsio\Charts\Category; use Seatsio\LocalDate; use Seatsio\SeatsioClientTest; diff --git a/tests/Events/ListStatusChangesTest.php b/tests/Events/ListStatusChangesTest.php index a6c78d3..3ae5b35 100644 --- a/tests/Events/ListStatusChangesTest.php +++ b/tests/Events/ListStatusChangesTest.php @@ -2,9 +2,7 @@ namespace Seatsio\Charts; -use GuzzleHttp\Promise\Create; use Seatsio\Events\CreateEventParams; -use Seatsio\Events\Event; use Seatsio\Events\EventObjectInfo; use Seatsio\Events\ObjectProperties; use Seatsio\Events\StatusChangeRequest; diff --git a/tests/Events/OverrideSeasonObjectStatusTest.php b/tests/Events/OverrideSeasonObjectStatusTest.php index c82566f..07bf806 100644 --- a/tests/Events/OverrideSeasonObjectStatusTest.php +++ b/tests/Events/OverrideSeasonObjectStatusTest.php @@ -2,9 +2,6 @@ namespace Events; -use Seatsio\Common\IDs; -use Seatsio\Events\Channel; -use Seatsio\Events\CreateEventParams; use Seatsio\Events\EventObjectInfo; use Seatsio\Seasons\SeasonCreationParams; use Seatsio\SeatsioClientTest; diff --git a/tests/Events/UpdateEventTest.php b/tests/Events/UpdateEventTest.php index 29e019f..143ecb9 100644 --- a/tests/Events/UpdateEventTest.php +++ b/tests/Events/UpdateEventTest.php @@ -6,7 +6,6 @@ use Seatsio\LocalDate; use Seatsio\Seasons\SeasonCreationParams; use Seatsio\SeatsioClientTest; -use Seatsio\SeatsioException; use stdClass; class UpdateEventTest extends SeatsioClientTest diff --git a/tests/Events/UseSeasonObjectStatusTest.php b/tests/Events/UseSeasonObjectStatusTest.php index 3876809..20cd02b 100644 --- a/tests/Events/UseSeasonObjectStatusTest.php +++ b/tests/Events/UseSeasonObjectStatusTest.php @@ -2,9 +2,6 @@ namespace Events; -use Seatsio\Common\IDs; -use Seatsio\Events\Channel; -use Seatsio\Events\CreateEventParams; use Seatsio\Events\EventObjectInfo; use Seatsio\Seasons\SeasonCreationParams; use Seatsio\SeatsioClientTest; diff --git a/tests/SeatsioClientTest.php b/tests/SeatsioClientTest.php index 7b04661..250b78c 100644 --- a/tests/SeatsioClientTest.php +++ b/tests/SeatsioClientTest.php @@ -3,7 +3,6 @@ namespace Seatsio; use GuzzleHttp\Client; -use GuzzleHttp\Utils; use PHPUnit\Framework\TestCase; use Seatsio\Events\Event; @@ -37,7 +36,7 @@ private function createTestCompany() { $client = new Client(); $res = $client->post(self::$BASE_URL . 'system/public/users/actions/create-test-company'); - return Utils::jsonDecode($res->getBody()); + return GuzzleResponseDecoder::decodeToObject($res); } protected function randomEmail() diff --git a/tests/Workspaces/CreateWorkspaceTest.php b/tests/Workspaces/CreateWorkspaceTest.php index fabf089..8e76af3 100644 --- a/tests/Workspaces/CreateWorkspaceTest.php +++ b/tests/Workspaces/CreateWorkspaceTest.php @@ -2,7 +2,6 @@ namespace Seatsio\Workspaces; -use DateTime; use Seatsio\SeatsioClientTest; class CreateWorkspaceTest extends SeatsioClientTest diff --git a/tests/Workspaces/RetrieveWorkspaceTest.php b/tests/Workspaces/RetrieveWorkspaceTest.php index c0a5621..c6136df 100644 --- a/tests/Workspaces/RetrieveWorkspaceTest.php +++ b/tests/Workspaces/RetrieveWorkspaceTest.php @@ -2,7 +2,6 @@ namespace Seatsio\Workspaces; -use DateTime; use Seatsio\SeatsioClientTest; class RetrieveWorkspaceTest extends SeatsioClientTest diff --git a/tests/Workspaces/UpdateWorkspaceTest.php b/tests/Workspaces/UpdateWorkspaceTest.php index ba47abf..c43dd19 100644 --- a/tests/Workspaces/UpdateWorkspaceTest.php +++ b/tests/Workspaces/UpdateWorkspaceTest.php @@ -2,7 +2,6 @@ namespace Seatsio\Workspaces; -use DateTime; use Seatsio\SeatsioClientTest; class UpdateWorkspaceTest extends SeatsioClientTest From 0cc07091c566037bb9e5ec98ff06f1c6ed09494b Mon Sep 17 00:00:00 2001 From: mroloux Date: Thu, 16 May 2024 12:59:34 +0200 Subject: [PATCH 2/7] Don't use the default Guzzle decoder --- src/GuzzleResponseDecoder.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/GuzzleResponseDecoder.php b/src/GuzzleResponseDecoder.php index 1103fa8..bbba769 100644 --- a/src/GuzzleResponseDecoder.php +++ b/src/GuzzleResponseDecoder.php @@ -29,7 +29,12 @@ public static function decodeToObject($res) public static function decodeToArray($res) { - return Utils::jsonDecode($res->getBody(), true); + $json = GuzzleResponseDecoder::decodeToJson($res); + $array = []; + foreach ($json as $name => $item) { + $array[$name] = json_decode(json_encode($item), true); + } + return $array; } /** From 0d6886cb2306b85a13d9f0457557543720314cc9 Mon Sep 17 00:00:00 2001 From: mroloux Date: Thu, 16 May 2024 13:05:45 +0200 Subject: [PATCH 3/7] decodeToObject and decodeToArray work similarly --- src/GuzzleResponseDecoder.php | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/GuzzleResponseDecoder.php b/src/GuzzleResponseDecoder.php index bbba769..403ed9e 100644 --- a/src/GuzzleResponseDecoder.php +++ b/src/GuzzleResponseDecoder.php @@ -22,9 +22,12 @@ public static function decodeToJson($res, $pointer = null) public static function decodeToObject($res) { - $mapper = self::mapperThatSetsUnknownProperties(); $json = GuzzleResponseDecoder::decodeToJson($res); - return $mapper->map($json, 'stdClass'); + $object = new \stdClass(); + foreach ($json as $name => $item) { + $object->$name = $item; + } + return $object; } public static function decodeToArray($res) @@ -36,16 +39,4 @@ public static function decodeToArray($res) } return $array; } - - /** - * @return JsonMapper - */ - public static function mapperThatSetsUnknownProperties(): JsonMapper - { - $mapper = new JsonMapper(); - $mapper->undefinedPropertyHandler = function ($object, $propName, $jsonValue) { - $object->{$propName} = $jsonValue; - }; - return $mapper; - } } From 4714c610f38a6c6abfc106efc868c334b37bba38 Mon Sep 17 00:00:00 2001 From: mroloux Date: Thu, 16 May 2024 13:08:25 +0200 Subject: [PATCH 4/7] Refactoring --- src/Events/Events.php | 8 ++++---- src/GuzzleResponseDecoder.php | 11 ++--------- src/Seasons/Seasons.php | 4 ++-- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/Events/Events.php b/src/Events/Events.php index ecfb0ce..9a13330 100644 --- a/src/Events/Events.php +++ b/src/Events/Events.php @@ -124,10 +124,10 @@ public function createMultiple(string $chartKey, array $createEventParams): arra } $res = $this->client->post('/events/actions/create-multiple', ['json' => $request]); - $json = GuzzleResponseDecoder::decodeToJson($res, '/events'); + $json = GuzzleResponseDecoder::decodeToObject($res); $mapper = SeatsioJsonMapper::create(); - return $mapper->mapArray($json, array(), 'Seatsio\Events\Event'); + return $mapper->mapArray($json->events, array(), 'Seatsio\Events\Event'); } public function retrieve(string $eventKey): Event @@ -396,9 +396,9 @@ public function changeObjectStatusInBatch(array $statusChangeRequests): array '/events/actions/change-object-status', ['json' => $request, 'query' => ['expand' => 'objects']] ); - $json = GuzzleResponseDecoder::decodeToJson($res, '/results'); + $json = GuzzleResponseDecoder::decodeToObject($res); $mapper = SeatsioJsonMapper::create(); - return $mapper->mapArray($json, array(), ChangeObjectStatusResult::class); + return $mapper->mapArray($json->results, array(), ChangeObjectStatusResult::class); } private function serializeStatusChangeRequest($statusChangeRequest) diff --git a/src/GuzzleResponseDecoder.php b/src/GuzzleResponseDecoder.php index 403ed9e..ccf390a 100644 --- a/src/GuzzleResponseDecoder.php +++ b/src/GuzzleResponseDecoder.php @@ -3,21 +3,14 @@ namespace Seatsio; use GuzzleHttp\Psr7\StreamWrapper; -use GuzzleHttp\Utils; use JsonMachine\Items; -use JsonMapper; class GuzzleResponseDecoder { - public static function decodeToJson($res, $pointer = null) + public static function decodeToJson($res) { - $options = []; - if ($pointer != null) { - $options["pointer"] = $pointer; - } - - return Items::fromStream(StreamWrapper::getResource($res->getBody()), $options); + return Items::fromStream(StreamWrapper::getResource($res->getBody())); } public static function decodeToObject($res) diff --git a/src/Seasons/Seasons.php b/src/Seasons/Seasons.php index a0df3e6..9814dac 100644 --- a/src/Seasons/Seasons.php +++ b/src/Seasons/Seasons.php @@ -115,9 +115,9 @@ public function createEvents(string $seasonKey, array $eventKeys = null, int $nu } $res = $this->client->post(UriTemplate::expand('/seasons/{seasonKey}/actions/create-events', ['seasonKey' => $seasonKey]), ['json' => $request]); - $json = GuzzleResponseDecoder::decodeToJson($res, '/events'); + $json = GuzzleResponseDecoder::decodeToObject($res); $mapper = SeatsioJsonMapper::create(); - return $mapper->mapArray($json, array(), 'Seatsio\Events\Event'); + return $mapper->mapArray($json->events, array(), 'Seatsio\Events\Event'); } public function removeEventFromPartialSeason(string $topLevelSeasonKey, string $partialSeasonKey, string $eventKey): Season From 0c52da16bfd0a33163b7fb924a5647ebe3b23000 Mon Sep 17 00:00:00 2001 From: mroloux Date: Thu, 16 May 2024 13:20:16 +0200 Subject: [PATCH 5/7] Fixed deprecation warnings --- tests/Reports/Charts/ChartReportsTest.php | 53 ++++++++++++----------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/tests/Reports/Charts/ChartReportsTest.php b/tests/Reports/Charts/ChartReportsTest.php index 470ccce..bd4867a 100644 --- a/tests/Reports/Charts/ChartReportsTest.php +++ b/tests/Reports/Charts/ChartReportsTest.php @@ -3,20 +3,21 @@ namespace Reports\Charts; use Seatsio\Common\IDs; +use Seatsio\Reports\Charts\ChartReports; use Seatsio\SeatsioClient; use Seatsio\SeatsioClientTest; class ChartReportsTest extends SeatsioClientTest { - private function noChartUpdate(): \Closure + private static function noChartUpdate(): \Closure { return function(SeatsioClient $client, string $chartKey) { // no-op }; } - private function createDraftReport(): \Closure + private static function createDraftReport(): \Closure { return function(SeatsioClient $client, string $chartKey) { $client->events->create($chartKey); @@ -24,7 +25,7 @@ private function createDraftReport(): \Closure }; } - public function byLabelDataProvider(): array + public static function byLabelDataProvider(): array { $getReport = function(SeatsioClient $client, string $chartKey) { @@ -35,24 +36,24 @@ public function byLabelDataProvider(): array return $client->chartReports->byLabel($chartKey, null, "draft"); }; return array( - array($this->noChartUpdate(), $getReport), - array($this->createDraftReport(), $getDraftReport) + array(ChartReportsTest::noChartUpdate(), $getReport), + array(ChartReportsTest::createDraftReport(), $getDraftReport) ); } - public function byLabelAndChart(): array { - return $this->byLabelAndTableBookingModelDataProvider("chart"); + public static function byLabelAndChart(): array { + return ChartReportsTest::byLabelAndTableBookingModelDataProvider("chart"); } - public function byLabelAndTrue(): array { - return $this->byLabelAndTableBookingModelDataProvider("true"); + public static function byLabelAndTrue(): array { + return ChartReportsTest::byLabelAndTableBookingModelDataProvider("true"); } - public function byLabelAndFalse(): array { - return $this->byLabelAndTableBookingModelDataProvider("false"); + public static function byLabelAndFalse(): array { + return ChartReportsTest::byLabelAndTableBookingModelDataProvider("false"); } - private function byLabelAndTableBookingModelDataProvider(string $tableBookingMode): array + private static function byLabelAndTableBookingModelDataProvider(string $tableBookingMode): array { $getReport = function(SeatsioClient $client, string $chartKey) use ($tableBookingMode) { @@ -63,8 +64,8 @@ private function byLabelAndTableBookingModelDataProvider(string $tableBookingMod return $client->chartReports->byLabel($chartKey, $tableBookingMode, "draft"); }; return array( - array($this->noChartUpdate(), $getReport), - array($this->createDraftReport(), $getDraftReport) + array(ChartReportsTest::noChartUpdate(), $getReport), + array(ChartReportsTest::createDraftReport(), $getDraftReport) ); } @@ -154,7 +155,7 @@ public function testByObjectType($updateChart, $getReport) self::assertCount(2, $report["generalAdmission"]); } - public function byObjectTypeDataProvider(): array + public static function byObjectTypeDataProvider(): array { $getReport = function(SeatsioClient $client, string $chartKey) { @@ -165,8 +166,8 @@ public function byObjectTypeDataProvider(): array return $client->chartReports->byObjectType($chartKey, null, "draft"); }; return array( - array($this->noChartUpdate(), $getReport), - array($this->createDraftReport(), $getDraftReport) + array(ChartReportsTest::noChartUpdate(), $getReport), + array(ChartReportsTest::createDraftReport(), $getDraftReport) ); } @@ -236,7 +237,7 @@ public function testByCategoryKey($updateChart, $getReport) self::assertCount(17, $report["10"]); } - public function byCategoryKeyDataProvider(): array + public static function byCategoryKeyDataProvider(): array { $getReport = function(SeatsioClient $client, string $chartKey) { $bySection = $client->chartReports->byCategoryKey($chartKey); @@ -247,8 +248,8 @@ public function byCategoryKeyDataProvider(): array return $bySection; }; return array( - array($this->noChartUpdate(), $getReport), - array($this->createDraftReport(), $getDraftReport) + array(ChartReportsTest::noChartUpdate(), $getReport), + array(ChartReportsTest::createDraftReport(), $getDraftReport) ); } @@ -266,7 +267,7 @@ public function testByCategoryLabel($updateChart, $getReport) self::assertCount(17, $report["Cat2"]); } - public function byCategoryLabelDataProvider(): array + public static function byCategoryLabelDataProvider(): array { $getReport = function(SeatsioClient $client, string $chartKey) { $bySection = $client->chartReports->byCategoryLabel($chartKey); @@ -277,8 +278,8 @@ public function byCategoryLabelDataProvider(): array return $bySection; }; return array( - array($this->noChartUpdate(), $getReport), - array($this->createDraftReport(), $getDraftReport) + array(ChartReportsTest::noChartUpdate(), $getReport), + array(ChartReportsTest::createDraftReport(), $getDraftReport) ); } @@ -296,7 +297,7 @@ public function testBySection($updateChart, $getReport) self::assertCount(35, $report["Section B"]); } - public function bySectionDataProvider(): array + public static function bySectionDataProvider(): array { $getReport = function(SeatsioClient $client, string $chartKey) { $bySection = $client->chartReports->bySection($chartKey); @@ -307,8 +308,8 @@ public function bySectionDataProvider(): array return $bySection; }; return array( - array($this->noChartUpdate(), $getReport), - array($this->createDraftReport(), $getDraftReport) + array(ChartReportsTest::noChartUpdate(), $getReport), + array(ChartReportsTest::createDraftReport(), $getDraftReport) ); } } From 2706f0a2cbc68ce77c088826c5336632d4b8d800 Mon Sep 17 00:00:00 2001 From: mroloux Date: Thu, 16 May 2024 13:42:39 +0200 Subject: [PATCH 6/7] Fixed usage reports --- src/Reports/Usage/UsageReports.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Reports/Usage/UsageReports.php b/src/Reports/Usage/UsageReports.php index 90345a1..a150c7c 100644 --- a/src/Reports/Usage/UsageReports.php +++ b/src/Reports/Usage/UsageReports.php @@ -49,12 +49,15 @@ public function detailsForMonth(Month $month): array public function detailsForEventInMonth(int $eventId, Month $month): array { $res = $this->client->get('/reports/usage/month/' . $month->serialize() . '/event/' . $eventId); - $json = GuzzleResponseDecoder::decodeToArray($res); $mapper = SeatsioJsonMapper::create(); - if (count($json) == 0 || !isset($json[0]->usageByReason)) { - return $mapper->mapArray($json, array(), UsageForObjectV1::class); + $json = GuzzleResponseDecoder::decodeToJson($res); + + $report = []; + foreach ($json as $item) { + $targetClass = isset($item->usageByReason) ? UsageForObjectV2::class : UsageForObjectV1::class; + $report[] = $mapper->map($item, $targetClass); } - return $mapper->mapArray($json, array(), UsageForObjectV2::class); + return $report; } } From dcf78a2a57767158ad7266220b5006502e2107eb Mon Sep 17 00:00:00 2001 From: mroloux Date: Thu, 16 May 2024 13:45:43 +0200 Subject: [PATCH 7/7] Fixed deprecations --- .../Charts/ChartReportsSummaryTest.php | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/Reports/Charts/ChartReportsSummaryTest.php b/tests/Reports/Charts/ChartReportsSummaryTest.php index fc8072e..0427048 100644 --- a/tests/Reports/Charts/ChartReportsSummaryTest.php +++ b/tests/Reports/Charts/ChartReportsSummaryTest.php @@ -7,14 +7,14 @@ class ChartReportsSummaryTest extends SeatsioClientTest { - private function noChartUpdate(): \Closure + private static function noChartUpdate(): \Closure { return function(SeatsioClient $client, string $chartKey) { // no-op }; } - private function createDraftReport(): \Closure + private static function createDraftReport(): \Closure { return function(SeatsioClient $client, string $chartKey) { $client->events->create($chartKey); @@ -61,7 +61,7 @@ public function testSummaryByObjectType($updateChart, $getReport) self::assertEquals($expectedReport, $report); } - public function summaryByObjectTypeDataProvider(): array + public static function summaryByObjectTypeDataProvider(): array { $getReport = function(SeatsioClient $client, string $chartKey) { @@ -72,8 +72,8 @@ public function summaryByObjectTypeDataProvider(): array return $client->chartReports->summaryByObjectType($chartKey, null, "draft"); }; return array( - array($this->noChartUpdate(), $getReport), - array($this->createDraftReport(), $getDraftReport) + array(ChartReportsSummaryTest::noChartUpdate(), $getReport), + array(ChartReportsSummaryTest::createDraftReport(), $getDraftReport) ); } @@ -116,7 +116,7 @@ public function testSummaryByObjectType_bookWholeTablesTrue($updateChart, $getRe self::assertEquals($expectedReport, $report); } - public function summaryByObjectTypeDataProvider_bookWholeTablesTrue(): array + public static function summaryByObjectTypeDataProvider_bookWholeTablesTrue(): array { $getReport = function(SeatsioClient $client, string $chartKey) { @@ -127,8 +127,8 @@ public function summaryByObjectTypeDataProvider_bookWholeTablesTrue(): array return $client->chartReports->summaryByObjectType($chartKey, 'true', "draft"); }; return array( - array($this->noChartUpdate(), $getReport), - array($this->createDraftReport(), $getDraftReport) + array(ChartReportsSummaryTest::noChartUpdate(), $getReport), + array(ChartReportsSummaryTest::createDraftReport(), $getDraftReport) ); } @@ -167,7 +167,7 @@ public function testSummaryByCategoryKey($updateChart, $getReport) self::assertEquals($expectedReport, $report); } - public function summaryByCategoryKeyDataProvider(): array + public static function summaryByCategoryKeyDataProvider(): array { $getReport = function(SeatsioClient $client, string $chartKey) { @@ -178,8 +178,8 @@ public function summaryByCategoryKeyDataProvider(): array return $client->chartReports->summaryByCategoryKey($chartKey, null, "draft"); }; return array( - array($this->noChartUpdate(), $getReport), - array($this->createDraftReport(), $getDraftReport) + array(ChartReportsSummaryTest::noChartUpdate(), $getReport), + array(ChartReportsSummaryTest::createDraftReport(), $getDraftReport) ); } @@ -218,7 +218,7 @@ public function testSummaryByCategoryLabel($updateChart, $getReport) self::assertEquals($expectedReport, $report); } - public function summaryByCategoryLabelDataProvider(): array + public static function summaryByCategoryLabelDataProvider(): array { $getReport = function(SeatsioClient $client, string $chartKey) { @@ -229,8 +229,8 @@ public function summaryByCategoryLabelDataProvider(): array return $client->chartReports->summaryByCategoryLabel($chartKey, null, "draft"); }; return array( - array($this->noChartUpdate(), $getReport), - array($this->createDraftReport(), $getDraftReport) + array(ChartReportsSummaryTest::noChartUpdate(), $getReport), + array(ChartReportsSummaryTest::createDraftReport(), $getDraftReport) ); } @@ -255,7 +255,7 @@ public function testSummaryBySection($updateChart, $getReport) self::assertEquals($expectedReport, $report); } - public function summaryBySectionDataProvider(): array + public static function summaryBySectionDataProvider(): array { $getReport = function(SeatsioClient $client, string $chartKey) { @@ -266,8 +266,8 @@ public function summaryBySectionDataProvider(): array return $client->chartReports->summaryBySection($chartKey, null, "draft"); }; return array( - array($this->noChartUpdate(), $getReport), - array($this->createDraftReport(), $getDraftReport) + array(ChartReportsSummaryTest::noChartUpdate(), $getReport), + array(ChartReportsSummaryTest::createDraftReport(), $getDraftReport) ); } }