diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3a22dd1..9ff0bbb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,6 +18,7 @@ jobs: - '8.0' - '8.1' - '8.2' + - '8.3' experimental: [false] include: - php-versions: nightly diff --git a/CHANGELOG.md b/CHANGELOG.md index 76abadf..53c5cda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased][] -Spring clean 2022! +## [1.0.0][] – 2024-12-16 + +**Note:** Support for all PHP `7` versions has been dropped. PHP `8+` only, from now on :) ### Added - `Idoit::search()`, `Idoit::batchSearch`: Add search modes "normal" (default), "deep" and "auto-deep" +- Support for PHP `8.3` ### Changed @@ -19,16 +22,12 @@ Spring clean 2022! - **Breaking:** Change PHP namespace to `Idoit\APIClient` - **Breaking:** Move repository to `github.com/i-doit/api-client-php` - **Breaking:** Require at least PHP version `8.0` -- Recommend PHP version `8.1` +- Recommend PHP version `8.2` - **Breaking:** Require at least i-doit `1.18.1` and its API add-on `1.12.3` -### Deprecated - -- Deprecate support of PHP version `7.4` - ### Removed -- **Breaking:** Drop support of PHP version `7.1`, `7.2`, and `7.3` +- **Breaking:** Drop support of PHP version `7.1`, `7.2`, `7.3` and `7.4` ## [0.10][] – 2020-04-07 @@ -234,7 +233,8 @@ Happy summer time ⛱️ Initial release -[Unreleased]: https://github.com/i-doit/api-client-php/compare/0.10...HEAD +[Unreleased]: https://github.com/i-doit/api-client-php/compare/1.0.0...HEAD +[1.0.0]: https://github.com/i-doit/api-client-php/compare/0.10...1.0.0 [0.10]: https://github.com/i-doit/api-client-php/compare/0.9...0.10 [0.9]: https://github.com/i-doit/api-client-php/compare/0.8...0.9 [0.8]: https://github.com/i-doit/api-client-php/compare/0.7...0.8 diff --git a/composer.json b/composer.json index 8bf8a45..c925f77 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "source": "https://github.com/i-doit/api-client-php" }, "require": { - "php": "^8.0 || ^8.1 || ^8.2", + "php": "^8.0 || ^8.1 || ^8.2 || ^8.3", "ext-curl": "*", "ext-date": "*", "ext-json": "*", @@ -35,23 +35,23 @@ "require-dev": { "ext-dom": "*", "ext-xml": "*", - "brianium/paratest": "^6.4", + "brianium/paratest": "^6.11", "dealerdirect/phpcodesniffer-composer-installer": "^0.7.2", "j13k/yaml-lint": "^1.1", - "phan/phan": "^5.3", + "phan/phan": "^5.4", "php-parallel-lint/php-parallel-lint": "^1.3", "phpcompatibility/php-compatibility": "^9.3", "phploc/phploc": "^7.0", - "phpmd/phpmd": "^2.12", - "phpstan/phpstan": "^1.7", - "phpunit/phpunit": "^9.5", + "phpmd/phpmd": "^2.15", + "phpstan/phpstan": "^2.0", + "phpunit/phpunit": "^9.6", "povils/phpmnd": "^2.5", - "psalm/phar": "^4.23", + "psalm/phar": "^5.26", "roave/security-advisories": "dev-master", "sclable/xml-lint": "^0.8.0", "sebastian/phpcpd": "^6.0", - "seld/jsonlint": "^1.9", - "squizlabs/php_codesniffer": "^3.6", + "seld/jsonlint": "^1.11", + "squizlabs/php_codesniffer": "^3.11", "symfony/dotenv": "^5.4" }, "suggest": { diff --git a/composer.lock b/composer.lock index 83089d9..fb692fc 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": "f0dcc1a13f36c9edf17ddd3928f17e41", + "content-hash": "2349020d74a0d1cb40b3ba5b72ac40fe", "packages": [], "packages-dev": [ { @@ -1812,20 +1812,20 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.12", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0" + "reference": "46b4d3529b12178112d9008337beda0cc2a1a6b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0", - "reference": "b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/46b4d3529b12178112d9008337beda0cc2a1a6b4", + "reference": "46b4d3529b12178112d9008337beda0cc2a1a6b4", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": "^7.4|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -1866,7 +1866,7 @@ "type": "github" } ], - "time": "2024-11-28T22:13:23+00:00" + "time": "2024-11-28T22:19:37+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2349,16 +2349,16 @@ }, { "name": "psalm/phar", - "version": "4.30.0", + "version": "5.26.1", "source": { "type": "git", "url": "https://github.com/psalm/phar.git", - "reference": "33723713902e1345904a5c9064ef7848bee0d490" + "reference": "8a38e7ad04499a0ccd2c506fd1da6fc01fff4547" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/psalm/phar/zipball/33723713902e1345904a5c9064ef7848bee0d490", - "reference": "33723713902e1345904a5c9064ef7848bee0d490", + "url": "https://api.github.com/repos/psalm/phar/zipball/8a38e7ad04499a0ccd2c506fd1da6fc01fff4547", + "reference": "8a38e7ad04499a0ccd2c506fd1da6fc01fff4547", "shasum": "" }, "require": { @@ -2378,9 +2378,9 @@ "description": "Composer-based Psalm Phar", "support": { "issues": "https://github.com/psalm/phar/issues", - "source": "https://github.com/psalm/phar/tree/4.30.0" + "source": "https://github.com/psalm/phar/tree/5.26.1" }, - "time": "2022-11-06T20:41:58+00:00" + "time": "2024-09-09T16:22:43+00:00" }, { "name": "psr/container", @@ -6195,7 +6195,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^8.0 || ^8.1 || ^8.2", + "php": "^8.0 || ^8.1 || ^8.2 || ^8.3", "ext-curl": "*", "ext-date": "*", "ext-json": "*", diff --git a/phpstan.neon b/phpstan.neon index 749d469..91e6453 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,11 +1,4 @@ parameters: level: 5 - checkMissingIterableValueType: false paths: - src - - tests - ignoreErrors: - # Ignore skipped tests: - - message: "#Unreachable statement#" - paths: - - tests/Idoit/APIClient/* diff --git a/phpunit.xml b/phpunit.xml index 8e82caf..b0915c5 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,28 +1,21 @@ - - - - ./tests/Idoit/APIClient/ - - - - - - - - ./src/ - - - - + + + + + ./src/ + + + + + + + + ./tests/Idoit/APIClient/ + + + + + diff --git a/psalm.xml b/psalm.xml index 7b66b9b..dfeb35a 100644 --- a/psalm.xml +++ b/psalm.xml @@ -4,7 +4,7 @@ resolveFromConfigFile="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" - phpVersion="7.4" + phpVersion="8.0" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" errorBaseline="psalm-baseline.xml" > diff --git a/src/API.php b/src/API.php index 2feec6e..dcf6423 100644 --- a/src/API.php +++ b/src/API.php @@ -139,9 +139,9 @@ class API { /** * cURL resource * - * @var CurlHandle|resource|false|null + * @var CurlHandle|null */ - protected $resource; + protected CurlHandle|null $resource = null; /** * Information about last client request @@ -247,7 +247,7 @@ public function __destruct() { * @return bool */ public function isConnected(): bool { - return is_resource($this->resource) || $this->resource instanceof CurlHandle; + return $this->resource instanceof CurlHandle; } /** @@ -346,12 +346,14 @@ protected function setCURLOptions(): self { * @throws RuntimeException on error */ public function connect(): self { - $this->resource = curl_init(); + $curl = curl_init(); - if ($this->resource == false) { + if (!$curl instanceof CurlHandle) { throw new RuntimeException('Unable to initiate cURL session'); } + $this->resource = $curl; + return $this; } @@ -371,6 +373,7 @@ public function disconnect(): self { } curl_close($this->resource); + $this->resource = null; return $this; } @@ -619,7 +622,7 @@ protected function execute(array $data): array { $lastResponse = json_decode(trim($body), true); if (!is_array($lastResponse)) { - if (is_string($body) && strlen($body) > 0) { + if (strlen($body) > 0) { throw new RuntimeException(sprintf( 'i-doit responded with an unknown message: %s', $body diff --git a/src/CMDBCategory.php b/src/CMDBCategory.php index 36eac99..73d2518 100644 --- a/src/CMDBCategory.php +++ b/src/CMDBCategory.php @@ -94,13 +94,13 @@ public function save(int $objectID, string $categoryConstant, array $attributes, */ public function create(int $objectID, string $categoryConst, array $attributes): int { $params = [ - 'objID' => $objectID, + 'object' => $objectID, 'data' => $attributes, 'category' => $categoryConst ]; $result = $this->api->request( - 'cmdb.category.create', + 'cmdb.category.save', $params ); @@ -217,9 +217,9 @@ public function update(int $objectID, string $categoryConst, array $attributes, } $result = $this->api->request( - 'cmdb.category.update', + 'cmdb.category.save', [ - 'objID' => $objectID, + 'object' => $objectID, 'category' => $categoryConst, 'data' => $attributes ] @@ -376,13 +376,13 @@ public function batchCreate(array $objectIDs, string $categoryConst, array $attr foreach ($objectIDs as $objectID) { foreach ($attributes as $data) { $params = [ - 'objID' => $objectID, + 'object' => $objectID, 'data' => $data, 'category' => $categoryConst ]; $requests[] = [ - 'method' => 'cmdb.category.create', + 'method' => 'cmdb.category.save', 'params' => $params ]; } @@ -493,9 +493,9 @@ public function batchUpdate(array $objectIDs, string $categoryConst, array $attr foreach ($objectIDs as $objectID) { $requests[] = [ - 'method' => 'cmdb.category.update', + 'method' => 'cmdb.category.save', 'params' => [ - 'objID' => $objectID, + 'object' => $objectID, 'category' => $categoryConst, 'data' => $attributes ] diff --git a/src/CMDBCategoryInfo.php b/src/CMDBCategoryInfo.php index aa93bfd..8c70e53 100644 --- a/src/CMDBCategoryInfo.php +++ b/src/CMDBCategoryInfo.php @@ -131,13 +131,7 @@ public function readAll(): array { $categories = $this->batchRead($cleanCategoryConstants); - $combinedArray = array_combine($cleanCategoryConstants, $categories); - - if (!is_array($combinedArray)) { - throw new RuntimeException('Unable to restructure result'); - } - - return $combinedArray; + return array_combine($cleanCategoryConstants, $categories); } /** diff --git a/tests/Idoit/APIClient/APITest.php b/tests/Idoit/APIClient/APITest.php index 2ca3aea..b9adb5c 100644 --- a/tests/Idoit/APIClient/APITest.php +++ b/tests/Idoit/APIClient/APITest.php @@ -327,7 +327,7 @@ public function testInvalidBatchRequest($request) { foreach ($response as $result) { $this->isError($result); $this->assertNull($result['id']); - $this->assertSame(-32600, $result['error']['code']); + $this->assertSame(-32604, $result['error']['code']); // <-- Previously 'Invalid request' -32600 } } @@ -347,7 +347,7 @@ public function testRequestWithMissingParameters() { $this->assertIsArray($response); $this->isError($response); $this->hasValidJSONRPCIdentifier($request, $response); - $this->assertSame(-32602, $response['error']['code']); + $this->assertSame(-32604, $response['error']['code']); // <-- Previously 'Invalid params' -32602 } /** @@ -385,7 +385,7 @@ public function testRequestWithInvalidParameters($parameters) { $this->assertIsArray($response); $this->isError($response); $this->hasValidJSONRPCIdentifier($request, $response); - $this->assertSame(-32602, $response['error']['code']); + $this->assertSame(-32604, $response['error']['code']); // <-- Previously 'Invalid params' -32602 } /** @@ -406,7 +406,7 @@ public function testRequestWithMissingApiKey() { $this->assertIsArray($response); $this->isError($response); $this->hasValidJSONRPCIdentifier($request, $response); - $this->assertSame(-32099, $response['error']['code']); + $this->assertSame(-32604, $response['error']['code']); // <-- Previously 'System error' -32099 } /** @@ -449,7 +449,7 @@ public function testRequestWithInvalidApiKeys($apiKey) { $this->assertIsArray($response); $this->isError($response); $this->hasValidJSONRPCIdentifier($request, $response); - $this->assertSame(-32099, $response['error']['code']); + $this->assertSame(-32604, $response['error']['code']); // <-- Previously 'System error' -32099 } /** diff --git a/tests/Idoit/APIClient/BaseTest.php b/tests/Idoit/APIClient/BaseTest.php index 7e52546..8e7d89f 100644 --- a/tests/Idoit/APIClient/BaseTest.php +++ b/tests/Idoit/APIClient/BaseTest.php @@ -741,14 +741,8 @@ protected function isIDAsString(string $value) { protected function isConstant(string $value) { $this->assertNotEmpty($value); - // @todo Remove this method switch if PHPunit >= v9 is in use: - if (method_exists($this, 'assertMatchesRegularExpression')) { - $this->assertMatchesRegularExpression('/([A-Z0-9_]+)/', $value); - $this->assertMatchesRegularExpression('/^([A-Z]+)/', $value); - } else { - $this->assertRegExp('/([A-Z0-9_]+)/', $value); - $this->assertRegExp('/^([A-Z]+)/', $value); - } + $this->assertMatchesRegularExpression('/([A-Z0-9_]+)/', $value); + $this->assertMatchesRegularExpression('/^([A-Z]+)/', $value); } protected function isValidResponse(array $response, array $request) {