diff --git a/composer.json b/composer.json index edd29d47..c28720b1 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "require-dev": { "phpunit/phpunit": "^9", "spatie/phpunit-watcher": "^1.22", - "vimeo/psalm": "^4.10", + "vimeo/psalm": "^4.10 || ^5.0", "squizlabs/php_codesniffer": "^3.6" }, "config": { diff --git a/composer.lock b/composer.lock index af0f3885..67e86521 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": "8693c4e6fa75b816346d0f466dcb2f92", + "content-hash": "3eb1fd049f2b5d629b669a5dea01f0d2", "packages": [], "packages-dev": [ { @@ -385,79 +385,6 @@ ], "time": "2020-11-06T11:48:09+00:00" }, - { - "name": "composer/package-versions-deprecated", - "version": "1.11.99.5", - "source": { - "type": "git", - "url": "https://github.com/composer/package-versions-deprecated.git", - "reference": "b4f54f74ef3453349c24a845d22392cd31e65f1d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/b4f54f74ef3453349c24a845d22392cd31e65f1d", - "reference": "b4f54f74ef3453349c24a845d22392cd31e65f1d", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.1.0 || ^2.0", - "php": "^7 || ^8" - }, - "replace": { - "ocramius/package-versions": "1.11.99" - }, - "require-dev": { - "composer/composer": "^1.9.3 || ^2.0@dev", - "ext-zip": "^1.13", - "phpunit/phpunit": "^6.5 || ^7" - }, - "type": "composer-plugin", - "extra": { - "class": "PackageVersions\\Installer", - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "PackageVersions\\": "src/PackageVersions" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com" - }, - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be" - } - ], - "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", - "support": { - "issues": "https://github.com/composer/package-versions-deprecated/issues", - "source": "https://github.com/composer/package-versions-deprecated/tree/1.11.99.5" - }, - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], - "time": "2022-01-17T14:14:24+00:00" - }, { "name": "composer/pcre", "version": "3.1.0", @@ -715,25 +642,29 @@ }, { "name": "doctrine/deprecations", - "version": "v1.0.0", + "version": "v1.1.1", "source": { "type": "git", "url": "https://github.com/doctrine/deprecations.git", - "reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de" + "reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/deprecations/zipball/0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de", - "reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/612a3ee5ab0d5dd97b7cf3874a6efe24325efac3", + "reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3", "shasum": "" }, "require": { - "php": "^7.1|^8.0" + "php": "^7.1 || ^8.0" }, "require-dev": { "doctrine/coding-standard": "^9", - "phpunit/phpunit": "^7.5|^8.5|^9.5", - "psr/log": "^1|^2|^3" + "phpstan/phpstan": "1.4.10 || 1.10.15", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "psalm/plugin-phpunit": "0.18.4", + "psr/log": "^1 || ^2 || ^3", + "vimeo/psalm": "4.30.0 || 5.12.0" }, "suggest": { "psr/log": "Allows logging deprecations via PSR-3 logger implementation" @@ -752,9 +683,9 @@ "homepage": "https://www.doctrine-project.org/", "support": { "issues": "https://github.com/doctrine/deprecations/issues", - "source": "https://github.com/doctrine/deprecations/tree/v1.0.0" + "source": "https://github.com/doctrine/deprecations/tree/v1.1.1" }, - "time": "2022-05-02T15:47:09+00:00" + "time": "2023-06-03T09:27:29+00:00" }, { "name": "doctrine/instantiator", @@ -974,6 +905,67 @@ }, "time": "2022-03-02T22:36:06+00:00" }, + { + "name": "fidry/cpu-core-counter", + "version": "0.5.1", + "source": { + "type": "git", + "url": "https://github.com/theofidry/cpu-core-counter.git", + "reference": "b58e5a3933e541dc286cc91fc4f3898bbc6f1623" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/b58e5a3933e541dc286cc91fc4f3898bbc6f1623", + "reference": "b58e5a3933e541dc286cc91fc4f3898bbc6f1623", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "fidry/makefile": "^0.2.0", + "phpstan/extension-installer": "^1.2.0", + "phpstan/phpstan": "^1.9.2", + "phpstan/phpstan-deprecation-rules": "^1.0.0", + "phpstan/phpstan-phpunit": "^1.2.2", + "phpstan/phpstan-strict-rules": "^1.4.4", + "phpunit/phpunit": "^9.5.26 || ^8.5.31", + "theofidry/php-cs-fixer-config": "^1.0", + "webmozarts/strict-phpunit": "^7.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Fidry\\CpuCoreCounter\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Théo FIDRY", + "email": "theo.fidry@gmail.com" + } + ], + "description": "Tiny utility to get the number of CPU cores.", + "keywords": [ + "CPU", + "core" + ], + "support": { + "issues": "https://github.com/theofidry/cpu-core-counter/issues", + "source": "https://github.com/theofidry/cpu-core-counter/tree/0.5.1" + }, + "funding": [ + { + "url": "https://github.com/theofidry", + "type": "github" + } + ], + "time": "2022-12-24T12:35:10+00:00" + }, { "name": "jolicode/jolinotif", "version": "v2.4.0", @@ -1202,59 +1194,6 @@ }, "time": "2023-06-25T14:52:30+00:00" }, - { - "name": "openlss/lib-array2xml", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/nullivex/lib-array2xml.git", - "reference": "a91f18a8dfc69ffabe5f9b068bc39bb202c81d90" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nullivex/lib-array2xml/zipball/a91f18a8dfc69ffabe5f9b068bc39bb202c81d90", - "reference": "a91f18a8dfc69ffabe5f9b068bc39bb202c81d90", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "type": "library", - "autoload": { - "psr-0": { - "LSS": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Bryan Tong", - "email": "bryan@nullivex.com", - "homepage": "https://www.nullivex.com" - }, - { - "name": "Tony Butler", - "email": "spudz76@gmail.com", - "homepage": "https://www.nullivex.com" - } - ], - "description": "Array2XML conversion library credit to lalit.org", - "homepage": "https://www.nullivex.com", - "keywords": [ - "array", - "array conversion", - "xml", - "xml conversion" - ], - "support": { - "issues": "https://github.com/nullivex/lib-array2xml/issues", - "source": "https://github.com/nullivex/lib-array2xml/tree/master" - }, - "time": "2019-03-29T20:06:56+00:00" - }, { "name": "phar-io/manifest", "version": "2.0.3", @@ -1478,16 +1417,16 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.7.1", + "version": "1.7.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "dfc078e8af9c99210337325ff5aa152872c98714" + "reference": "b2fe4d22a5426f38e014855322200b97b5362c0d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/dfc078e8af9c99210337325ff5aa152872c98714", - "reference": "dfc078e8af9c99210337325ff5aa152872c98714", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/b2fe4d22a5426f38e014855322200b97b5362c0d", + "reference": "b2fe4d22a5426f38e014855322200b97b5362c0d", "shasum": "" }, "require": { @@ -1530,28 +1469,30 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.7.1" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.7.2" }, - "time": "2023-03-27T19:02:04+00:00" + "time": "2023-05-30T18:13:47+00:00" }, { "name": "phpstan/phpdoc-parser", - "version": "1.20.4", + "version": "1.22.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd" + "reference": "65c39594fbd8c67abfc68bb323f86447bab79cc0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd", - "reference": "7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/65c39594fbd8c67abfc68bb323f86447bab79cc0", + "reference": "65c39594fbd8c67abfc68bb323f86447bab79cc0", "shasum": "" }, "require": { "php": "^7.2 || ^8.0" }, "require-dev": { + "doctrine/annotations": "^2.0", + "nikic/php-parser": "^4.15", "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^1.5", @@ -1575,9 +1516,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.20.4" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.22.1" }, - "time": "2023-05-02T09:19:37+00:00" + "time": "2023-06-29T20:46:06+00:00" }, { "name": "phpunit/php-code-coverage", @@ -3216,6 +3157,70 @@ ], "time": "2020-09-28T06:39:44+00:00" }, + { + "name": "spatie/array-to-xml", + "version": "2.17.1", + "source": { + "type": "git", + "url": "https://github.com/spatie/array-to-xml.git", + "reference": "5cbec9c6ab17e320c58a259f0cebe88bde4a7c46" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/array-to-xml/zipball/5cbec9c6ab17e320c58a259f0cebe88bde4a7c46", + "reference": "5cbec9c6ab17e320c58a259f0cebe88bde4a7c46", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "php": "^7.4|^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.2", + "pestphp/pest": "^1.21", + "phpunit/phpunit": "^9.0", + "spatie/pest-plugin-snapshots": "^1.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\ArrayToXml\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://freek.dev", + "role": "Developer" + } + ], + "description": "Convert an array to xml", + "homepage": "https://github.com/spatie/array-to-xml", + "keywords": [ + "array", + "convert", + "xml" + ], + "support": { + "source": "https://github.com/spatie/array-to-xml/tree/2.17.1" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + }, + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2022-12-26T08:22:07+00:00" + }, { "name": "spatie/phpunit-watcher", "version": "1.23.6", @@ -3339,16 +3344,16 @@ }, { "name": "symfony/console", - "version": "v5.4.23", + "version": "v5.4.24", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "90f21e27d0d88ce38720556dd164d4a1e4c3934c" + "reference": "560fc3ed7a43e6d30ea94a07d77f9a60b8ed0fb8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/90f21e27d0d88ce38720556dd164d4a1e4c3934c", - "reference": "90f21e27d0d88ce38720556dd164d4a1e4c3934c", + "url": "https://api.github.com/repos/symfony/console/zipball/560fc3ed7a43e6d30ea94a07d77f9a60b8ed0fb8", + "reference": "560fc3ed7a43e6d30ea94a07d77f9a60b8ed0fb8", "shasum": "" }, "require": { @@ -3418,7 +3423,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.23" + "source": "https://github.com/symfony/console/tree/v5.4.24" }, "funding": [ { @@ -3434,7 +3439,7 @@ "type": "tidelift" } ], - "time": "2023-04-24T18:47:29+00:00" + "time": "2023-05-26T05:13:16+00:00" }, { "name": "symfony/deprecation-contracts", @@ -3503,6 +3508,70 @@ ], "time": "2022-01-02T09:53:40+00:00" }, + { + "name": "symfony/filesystem", + "version": "v5.4.25", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "0ce3a62c9579a53358d3a7eb6b3dfb79789a6364" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/0ce3a62c9579a53358d3a7eb6b3dfb79789a6364", + "reference": "0ce3a62c9579a53358d3a7eb6b3dfb79789a6364", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.8", + "symfony/polyfill-php80": "^1.16" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides basic utilities for the filesystem", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/filesystem/tree/v5.4.25" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-05-31T13:04:02+00:00" + }, { "name": "symfony/finder", "version": "v5.4.21", @@ -4416,24 +4485,24 @@ }, { "name": "vimeo/psalm", - "version": "4.30.0", + "version": "5.13.1", "source": { "type": "git", "url": "https://github.com/vimeo/psalm.git", - "reference": "d0bc6e25d89f649e4f36a534f330f8bb4643dd69" + "reference": "086b94371304750d1c673315321a55d15fc59015" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vimeo/psalm/zipball/d0bc6e25d89f649e4f36a534f330f8bb4643dd69", - "reference": "d0bc6e25d89f649e4f36a534f330f8bb4643dd69", + "url": "https://api.github.com/repos/vimeo/psalm/zipball/086b94371304750d1c673315321a55d15fc59015", + "reference": "086b94371304750d1c673315321a55d15fc59015", "shasum": "" }, "require": { "amphp/amp": "^2.4.2", "amphp/byte-stream": "^1.5", - "composer/package-versions-deprecated": "^1.8.0", + "composer-runtime-api": "^2", "composer/semver": "^1.4 || ^2.0 || ^3.0", - "composer/xdebug-handler": "^1.1 || ^2.0 || ^3.0", + "composer/xdebug-handler": "^2.0 || ^3.0", "dnoegel/php-xdg-base-dir": "^0.1.1", "ext-ctype": "*", "ext-dom": "*", @@ -4442,35 +4511,35 @@ "ext-mbstring": "*", "ext-simplexml": "*", "ext-tokenizer": "*", - "felixfbecker/advanced-json-rpc": "^3.0.3", - "felixfbecker/language-server-protocol": "^1.5", + "felixfbecker/advanced-json-rpc": "^3.1", + "felixfbecker/language-server-protocol": "^1.5.2", + "fidry/cpu-core-counter": "^0.4.1 || ^0.5.1", "netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0 || ^4.0", - "nikic/php-parser": "^4.13", - "openlss/lib-array2xml": "^1.0", - "php": "^7.1|^8", - "sebastian/diff": "^3.0 || ^4.0", - "symfony/console": "^3.4.17 || ^4.1.6 || ^5.0 || ^6.0", - "symfony/polyfill-php80": "^1.25", - "webmozart/path-util": "^2.3" + "nikic/php-parser": "^4.14", + "php": "^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0", + "sebastian/diff": "^4.0 || ^5.0", + "spatie/array-to-xml": "^2.17.0 || ^3.0", + "symfony/console": "^4.1.6 || ^5.0 || ^6.0", + "symfony/filesystem": "^5.4 || ^6.0" }, "provide": { "psalm/psalm": "self.version" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.2", - "brianium/paratest": "^4.0||^6.0", + "amphp/phpunit-util": "^2.0", + "bamarni/composer-bin-plugin": "^1.4", + "brianium/paratest": "^6.9", "ext-curl": "*", + "mockery/mockery": "^1.5", + "nunomaduro/mock-final-classes": "^1.1", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpdocumentor/reflection-docblock": "^5", - "phpmyadmin/sql-parser": "5.1.0||dev-master", - "phpspec/prophecy": ">=1.9.0", - "phpstan/phpdoc-parser": "1.2.* || 1.6.4", - "phpunit/phpunit": "^9.0", - "psalm/plugin-phpunit": "^0.16", - "slevomat/coding-standard": "^7.0", - "squizlabs/php_codesniffer": "^3.5", - "symfony/process": "^4.3 || ^5.0 || ^6.0", - "weirdan/prophecy-shim": "^1.0 || ^2.0" + "phpstan/phpdoc-parser": "^1.6", + "phpunit/phpunit": "^9.6", + "psalm/plugin-mockery": "^1.1", + "psalm/plugin-phpunit": "^0.18", + "slevomat/coding-standard": "^8.4", + "squizlabs/php_codesniffer": "^3.6", + "symfony/process": "^4.4 || ^5.0 || ^6.0" }, "suggest": { "ext-curl": "In order to send data to shepherd", @@ -4486,17 +4555,14 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.x-dev", + "dev-master": "5.x-dev", + "dev-4.x": "4.x-dev", "dev-3.x": "3.x-dev", "dev-2.x": "2.x-dev", "dev-1.x": "1.x-dev" } }, "autoload": { - "files": [ - "src/functions.php", - "src/spl_object_id.php" - ], "psr-4": { "Psalm\\": "src/Psalm/" } @@ -4514,13 +4580,14 @@ "keywords": [ "code", "inspection", - "php" + "php", + "static analysis" ], "support": { "issues": "https://github.com/vimeo/psalm/issues", - "source": "https://github.com/vimeo/psalm/tree/4.30.0" + "source": "https://github.com/vimeo/psalm/tree/5.13.1" }, - "time": "2022-11-06T20:37:08+00:00" + "time": "2023-06-27T16:39:49+00:00" }, { "name": "webmozart/assert", @@ -4580,57 +4647,6 @@ }, "time": "2022-06-03T18:03:27+00:00" }, - { - "name": "webmozart/path-util", - "version": "2.3.0", - "source": { - "type": "git", - "url": "https://github.com/webmozart/path-util.git", - "reference": "d939f7edc24c9a1bb9c0dee5cb05d8e859490725" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webmozart/path-util/zipball/d939f7edc24c9a1bb9c0dee5cb05d8e859490725", - "reference": "d939f7edc24c9a1bb9c0dee5cb05d8e859490725", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "webmozart/assert": "~1.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.3-dev" - } - }, - "autoload": { - "psr-4": { - "Webmozart\\PathUtil\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" - } - ], - "description": "A robust cross-platform utility for normalizing, comparing and modifying file paths.", - "support": { - "issues": "https://github.com/webmozart/path-util/issues", - "source": "https://github.com/webmozart/path-util/tree/2.3.0" - }, - "abandoned": "symfony/filesystem", - "time": "2015-12-17T08:42:14+00:00" - }, { "name": "yosymfony/resource-watcher", "version": "v3.0.0", diff --git a/psalm.xml b/psalm.xml index 91d9afed..ee216500 100644 --- a/psalm.xml +++ b/psalm.xml @@ -3,6 +3,8 @@ protocol) { - $version = ('' == $this->version) ? null : $this->version; - $requestXml = new SimpleXMLElement((string) $request); - /** @psalm-suppress UndefinedClass */ - $xml = \pm_ApiRpc::getService($version)->call($requestXml->children()[0]->asXml(), $this->login); + $xml = $this->performSdkCall((string) $request); } else { $xml = $this->performHttpRequest((string) $request); } @@ -179,8 +176,25 @@ public function request($request, int $mode = self::RESPONSE_SHORT): XmlResponse ? call_user_func($this->verifyResponseCallback, $xml) : $this->verifyResponse($xml); - $result = (self::RESPONSE_FULL === $mode) ? $xml : $xml->xpath('//result')[0]; - return new XmlResponse((string) $result->asXML()); + $result = (self::RESPONSE_FULL === $mode) + ? $xml + : ($xml->xpath('//result') ?: [null])[0]; + + return new XmlResponse($result ? (string) $result->asXML() : ''); + } + + private function performSdkCall(string $request): XmlResponse + { + $version = ('' == $this->version) ? null : $this->version; + + $requestXml = new SimpleXMLElement($request); + $innerNodes = $requestXml->children(); + $innerXml = $innerNodes && count($innerNodes) > 0 && $innerNodes[0] ? $innerNodes[0]->asXml() : ''; + + /** @psalm-suppress UndefinedClass */ + $result = \pm_ApiRpc::getService($version)->call($innerXml, $this->login); + + return new XmlResponse($result ? (string) $result->asXML() : ''); } /** @@ -265,7 +279,12 @@ private function splitResponseToArray(XmlResponse $responseXml, $mode = self::RE { $responses = []; - foreach ($responseXml->children() as $childNode) { + $nodes = $responseXml->children(); + if (!$nodes) { + return []; + } + + foreach ($nodes as $childNode) { $dom = $this->getDomDocument($this->getPacket()); if (!$dom) { continue; @@ -278,7 +297,13 @@ private function splitResponseToArray(XmlResponse $responseXml, $mode = self::RE } $response = simplexml_load_string($dom->saveXML()); - $responses[] = (self::RESPONSE_FULL == $mode) ? $response : $response->xpath('//result')[0]; + if (!$response) { + return []; + } + + $responses[] = (self::RESPONSE_FULL == $mode) + ? $response + : ($response->xpath('//result') ?: [null])[0]; } return $responses; @@ -330,8 +355,8 @@ private function verifyResponse($xml): void } if ($xml->xpath('//status[text()="error"]') && $xml->xpath('//errcode') && $xml->xpath('//errtext')) { - $errorCode = (int) $xml->xpath('//errcode')[0]; - $errorMessage = (string) $xml->xpath('//errtext')[0]; + $errorCode = (int) ($xml->xpath('//errcode') ?: [null])[0]; + $errorMessage = (string) ($xml->xpath('//errtext') ?: [null])[0]; throw new Exception($errorMessage, $errorCode); } diff --git a/src/Api/Operator.php b/src/Api/Operator.php index 835f1552..ee3fcb73 100644 --- a/src/Api/Operator.php +++ b/src/Api/Operator.php @@ -86,11 +86,11 @@ protected function getItems($structClass, $infoTag, $field = null, $value = null $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); $items = []; - foreach ($response->xpath('//result') as $xmlResult) { - if (!is_null($filter) && !$filter($xmlResult->data->$infoTag)) { + foreach ((array) $response->xpath('//result') as $xmlResult) { + if (!$xmlResult || !isset($xmlResult->data) || !isset($xmlResult->data->$infoTag)) { continue; } - if (!isset($xmlResult->data) || !isset($xmlResult->data->$infoTag)) { + if (!is_null($filter) && !$filter($xmlResult->data->$infoTag)) { continue; } /** @psalm-suppress InvalidStringClass */ diff --git a/src/Api/Operator/Database.php b/src/Api/Operator/Database.php index 39614a10..803e454e 100644 --- a/src/Api/Operator/Database.php +++ b/src/Api/Operator/Database.php @@ -77,8 +77,10 @@ public function getAll(string $field, $value): array { $response = $this->getBy('get-db', $field, $value); $items = []; - foreach ($response->xpath('//result') as $xmlResult) { - $items[] = new Struct\Info($xmlResult); + foreach ((array) $response->xpath('//result') as $xmlResult) { + if ($xmlResult) { + $items[] = new Struct\Info($xmlResult); + } } return $items; @@ -94,8 +96,10 @@ public function getAllUsers(string $field, $value): array { $response = $this->getBy('get-db-users', $field, $value); $items = []; - foreach ($response->xpath('//result') as $xmlResult) { - $items[] = new Struct\UserInfo($xmlResult); + foreach ((array) $response->xpath('//result') as $xmlResult) { + if ($xmlResult) { + $items[] = new Struct\UserInfo($xmlResult); + } } return $items; diff --git a/src/Api/Operator/DatabaseServer.php b/src/Api/Operator/DatabaseServer.php index bc077674..4066a359 100644 --- a/src/Api/Operator/DatabaseServer.php +++ b/src/Api/Operator/DatabaseServer.php @@ -56,7 +56,10 @@ private function getBy($field = null, $value = null): array $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); $items = []; - foreach ($response->xpath('//result') as $xmlResult) { + foreach ((array) $response->xpath('//result') as $xmlResult) { + if (!$xmlResult) { + continue; + } $item = new Struct\Info($xmlResult->data); $item->id = (int) $xmlResult->id; $items[] = $item; diff --git a/src/Api/Operator/Dns.php b/src/Api/Operator/Dns.php index 60f6e813..fab5fb99 100644 --- a/src/Api/Operator/Dns.php +++ b/src/Api/Operator/Dns.php @@ -40,8 +40,10 @@ public function bulkCreate(array $records): array $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); $items = []; - foreach ($response->xpath('//result') as $xmlResult) { - $items[] = $xmlResult; + foreach ((array) $response->xpath('//result') as $xmlResult) { + if ($xmlResult) { + $items[] = $xmlResult; + } } return $items; @@ -76,7 +78,10 @@ public function getAll(string $field, $value): array $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); $items = []; - foreach ($response->xpath('//result') as $xmlResult) { + foreach ((array) $response->xpath('//result') as $xmlResult) { + if (!$xmlResult) { + continue; + } $item = new Struct\Info($xmlResult->data); $item->id = (int) $xmlResult->id; $items[] = $item; @@ -114,8 +119,10 @@ public function bulkDelete(array $recordIds): array $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); $items = []; - foreach ($response->xpath('//result') as $xmlResult) { - $items[] = $xmlResult; + foreach ((array) $response->xpath('//result') as $xmlResult) { + if ($xmlResult) { + $items[] = $xmlResult; + } } return $items; diff --git a/src/Api/Operator/DnsTemplate.php b/src/Api/Operator/DnsTemplate.php index bfea44b0..34a471a8 100644 --- a/src/Api/Operator/DnsTemplate.php +++ b/src/Api/Operator/DnsTemplate.php @@ -59,7 +59,10 @@ public function getAll($field = null, $value = null): array $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); $items = []; - foreach ($response->xpath('//result') as $xmlResult) { + foreach ((array) $response->xpath('//result') as $xmlResult) { + if (!$xmlResult) { + continue; + } $item = new Struct\Info($xmlResult->data); $item->id = (int) $xmlResult->id; $items[] = $item; diff --git a/src/Api/Operator/Mail.php b/src/Api/Operator/Mail.php index 0679fd95..d9ccf2d1 100644 --- a/src/Api/Operator/Mail.php +++ b/src/Api/Operator/Mail.php @@ -76,8 +76,8 @@ public function getAll(int $siteId, $name = null): array $response = $this->client->request($packet, Client::RESPONSE_FULL); $items = []; - foreach ($response->xpath('//result') as $xmlResult) { - if (!isset($xmlResult->mailname)) { + foreach ((array) $response->xpath('//result') as $xmlResult) { + if (!$xmlResult || !isset($xmlResult->mailname)) { continue; } $item = new Struct\GeneralInfo($xmlResult->mailname); diff --git a/src/Api/Operator/PhpHandler.php b/src/Api/Operator/PhpHandler.php index 3fdd15f8..68725b51 100644 --- a/src/Api/Operator/PhpHandler.php +++ b/src/Api/Operator/PhpHandler.php @@ -15,7 +15,7 @@ class PhpHandler extends Operator * * @return Info */ - public function get($field = null, $value = null): Info + public function get($field = null, $value = null): ?Info { $packet = $this->client->getPacket(); $getTag = $packet->addChild($this->wrapperTag)->addChild('get'); @@ -26,9 +26,9 @@ public function get($field = null, $value = null): Info } $response = $this->client->request($packet, Client::RESPONSE_FULL); - $xmlResult = $response->xpath('//result')[0]; + $xmlResult = ($response->xpath('//result') ?: [null])[0]; - return new Info($xmlResult); + return $xmlResult ? new Info($xmlResult) : null; } /** @@ -49,7 +49,10 @@ public function getAll($field = null, $value = null): array $response = $this->client->request($packet, Client::RESPONSE_FULL); $items = []; - foreach ($response->xpath('//result') as $xmlResult) { + foreach ((array) $response->xpath('//result') as $xmlResult) { + if (!$xmlResult) { + continue; + } $item = new Info($xmlResult); $items[] = $item; } diff --git a/src/Api/Operator/ProtectedDirectory.php b/src/Api/Operator/ProtectedDirectory.php index 0292cc0e..ce555358 100644 --- a/src/Api/Operator/ProtectedDirectory.php +++ b/src/Api/Operator/ProtectedDirectory.php @@ -57,7 +57,10 @@ public function getAll(string $field, $value): array { $response = $this->getBy('get', $field, $value); $items = []; - foreach ($response->xpath('//result/data') as $xmlResult) { + foreach ((array) $response->xpath('//result/data') as $xmlResult) { + if (!$xmlResult) { + continue; + } $items[] = new Struct\DataInfo($xmlResult); } diff --git a/src/Api/Operator/Reseller.php b/src/Api/Operator/Reseller.php index ff5678d7..d5fe2965 100644 --- a/src/Api/Operator/Reseller.php +++ b/src/Api/Operator/Reseller.php @@ -68,8 +68,8 @@ public function getAll($field = null, $value = null): array $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); $items = []; - foreach ($response->xpath('//result') as $xmlResult) { - if (!$xmlResult->data) { + foreach ((array) $response->xpath('//result') as $xmlResult) { + if (!$xmlResult || !$xmlResult->data) { continue; } diff --git a/src/Api/Operator/SecretKey.php b/src/Api/Operator/SecretKey.php index b8ef6c86..4cf93a88 100644 --- a/src/Api/Operator/SecretKey.php +++ b/src/Api/Operator/SecretKey.php @@ -65,7 +65,10 @@ public function getBy($keyId = null): array $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); $items = []; - foreach ($response->xpath('//result/key_info') as $keyInfo) { + foreach ((array) $response->xpath('//result/key_info') as $keyInfo) { + if (!$keyInfo) { + continue; + } $items[] = new Struct\Info($keyInfo); } diff --git a/src/Api/Operator/ServicePlan.php b/src/Api/Operator/ServicePlan.php index e351738a..5e446cab 100644 --- a/src/Api/Operator/ServicePlan.php +++ b/src/Api/Operator/ServicePlan.php @@ -65,7 +65,10 @@ private function getBy($field = null, $value = null): array $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); $items = []; - foreach ($response->xpath('//result') as $xmlResult) { + foreach ((array) $response->xpath('//result') as $xmlResult) { + if (!$xmlResult) { + continue; + } $items[] = new Struct\Info($xmlResult); } diff --git a/src/Api/Operator/ServicePlanAddon.php b/src/Api/Operator/ServicePlanAddon.php index 6d348da2..f17cedf4 100644 --- a/src/Api/Operator/ServicePlanAddon.php +++ b/src/Api/Operator/ServicePlanAddon.php @@ -65,7 +65,10 @@ private function getBy($field = null, $value = null): array $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); $items = []; - foreach ($response->xpath('//result') as $xmlResult) { + foreach ((array) $response->xpath('//result') as $xmlResult) { + if (!$xmlResult) { + continue; + } $items[] = new Struct\Info($xmlResult); } diff --git a/src/Api/Operator/SiteAlias.php b/src/Api/Operator/SiteAlias.php index d7ee2100..ec5aaee0 100644 --- a/src/Api/Operator/SiteAlias.php +++ b/src/Api/Operator/SiteAlias.php @@ -70,7 +70,10 @@ public function getAll($field = null, $value = null): array $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); $items = []; - foreach ($response->xpath('//result') as $xmlResult) { + foreach ((array) $response->xpath('//result') as $xmlResult) { + if (!$xmlResult) { + continue; + } $item = new Struct\GeneralInfo($xmlResult->info); $items[] = $item; } diff --git a/src/Api/Operator/Subdomain.php b/src/Api/Operator/Subdomain.php index baf7f643..2eff9636 100644 --- a/src/Api/Operator/Subdomain.php +++ b/src/Api/Operator/Subdomain.php @@ -72,8 +72,8 @@ public function getAll($field = null, $value = null): array $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); $items = []; - foreach ($response->xpath('//result') as $xmlResult) { - if (empty($xmlResult->data)) { + foreach ((array) $response->xpath('//result') as $xmlResult) { + if (!$xmlResult || empty($xmlResult->data)) { continue; } $item = new Struct\Info($xmlResult->data); diff --git a/src/Api/XmlResponse.php b/src/Api/XmlResponse.php index 1d681c05..a2aaab8f 100644 --- a/src/Api/XmlResponse.php +++ b/src/Api/XmlResponse.php @@ -17,6 +17,11 @@ class XmlResponse extends \SimpleXMLElement */ public function getValue(string $node): string { - return (string) $this->xpath('//' . $node)[0]; + $result = $this->xpath('//' . $node); + if (is_array($result) && isset($result[0])) { + return (string) $result[0]; + } + + return ''; } }