From a794579615de61db18b41ecf265300c19c113abc Mon Sep 17 00:00:00 2001 From: Artur Weigandt Date: Fri, 21 Nov 2025 08:17:14 +0100 Subject: [PATCH 1/5] feat: add rector config, add rector dependency --- .phpstan.neon | 3 --- .rector.php | 18 ++++++++++++++++++ composer.json | 4 +++- docker-compose.yml | 3 +++ 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 .rector.php diff --git a/.phpstan.neon b/.phpstan.neon index b5eae346..4b04a84b 100644 --- a/.phpstan.neon +++ b/.phpstan.neon @@ -5,9 +5,6 @@ parameters: - src/ - tests/ - scanDirectories: - - vendor - treatPhpDocTypesAsCertain: false ignoreErrors: diff --git a/.rector.php b/.rector.php new file mode 100644 index 00000000..9d0cd896 --- /dev/null +++ b/.rector.php @@ -0,0 +1,18 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + // uncomment to reach your current PHP version + //->withPhpSets() + ->withPhp74Sets() + ->withTypeCoverageLevel(0) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0) +; diff --git a/composer.json b/composer.json index 6f2a63c5..559fc42f 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,8 @@ "guzzlehttp/psr7": "^2", "php-mock/php-mock-phpunit": "^2.13", "phpstan/phpstan": "^2.1", - "phpunit/phpunit": "^9.5 || ^10.5 || ^11.2 || ^12.0.9" + "phpunit/phpunit": "^9.5 || ^10.5 || ^11.2 || ^12.0.9", + "rector/rector": "^2.2" }, "autoload": { "psr-4": { @@ -62,6 +63,7 @@ "coverage": "phpunit --coverage-html=\".phpunit.cache/code-coverage\"", "phpstan": "phpstan analyze --memory-limit 512M --configuration .phpstan.neon", "phpunit": "phpunit", + "rector": "rector -c .rector.php", "test": [ "@phpstan", "@phpunit", diff --git a/docker-compose.yml b/docker-compose.yml index 8b11af78..356ba77a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,9 @@ services: - 8111:80 depends_on: - redmine-dev + - redmine-6-1 + - redmine-6-0 + - redmine-5-1 volumes: - ./:/var/www/project/ # Location of the project for php-fpm. Note this should be the same for NGINX.* From 918b31e15b56225141dc224d5b517ee6a04346c4 Mon Sep 17 00:00:00 2001 From: Artur Weigandt Date: Fri, 21 Nov 2025 08:18:48 +0100 Subject: [PATCH 2/5] ci: add test job with php 8.6 --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 81e12c0b..e07f6d06 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: operating-system: ["ubuntu-latest"] - php: ["7.4", "8.0", "8.1", "8.2", "8.3", "8.4", "8.5"] + php: ["7.4", "8.0", "8.1", "8.2", "8.3", "8.4", "8.5", "8.6"] steps: - name: Checkout @@ -93,7 +93,7 @@ jobs: fail-fast: false matrix: operating-system: ["ubuntu-latest"] - php: ["8.3"] + php: ["8.4"] tool: ["phpstan", "code-coverage", "code-style"] steps: From 2d63c884bd349de674f6c8c14c6f98fe86b7efdc Mon Sep 17 00:00:00 2001 From: Artur Weigandt Date: Fri, 21 Nov 2025 09:05:51 +0100 Subject: [PATCH 3/5] refactor: add rector rules - StringClassNameToClassConstantRector - ClassConstantToSelfClassRector --- .rector.php | 2 +- src/Redmine/Api/AbstractApi.php | 2 +- src/Redmine/Api/CustomField.php | 6 +-- src/Redmine/Api/Group.php | 4 +- src/Redmine/Api/Issue.php | 2 +- src/Redmine/Api/IssueCategory.php | 6 +-- src/Redmine/Api/IssuePriority.php | 2 +- src/Redmine/Api/IssueRelation.php | 2 +- src/Redmine/Api/IssueStatus.php | 6 +-- src/Redmine/Api/Membership.php | 2 +- src/Redmine/Api/News.php | 2 +- src/Redmine/Api/Project.php | 6 +-- src/Redmine/Api/Query.php | 2 +- src/Redmine/Api/Role.php | 4 +- src/Redmine/Api/Search.php | 2 +- src/Redmine/Api/TimeEntry.php | 2 +- src/Redmine/Api/TimeEntryActivity.php | 6 +-- src/Redmine/Api/Tracker.php | 6 +-- src/Redmine/Api/User.php | 8 ++-- src/Redmine/Api/Version.php | 6 +-- src/Redmine/Api/Wiki.php | 2 +- src/Redmine/Client/ClientApiTrait.php | 40 +++++++++---------- tests/Integration/IssueCategoryXmlTest.php | 2 +- .../Psr18ClientRequestGenerationTest.php | 4 +- tests/Integration/UserXmlTest.php | 2 +- tests/Unit/Client/NativeCurlClientTest.php | 38 +++++++++--------- tests/Unit/Client/Psr18ClientTest.php | 38 +++++++++--------- 27 files changed, 101 insertions(+), 103 deletions(-) diff --git a/.rector.php b/.rector.php index 9d0cd896..0e157272 100644 --- a/.rector.php +++ b/.rector.php @@ -12,7 +12,7 @@ // uncomment to reach your current PHP version //->withPhpSets() ->withPhp74Sets() - ->withTypeCoverageLevel(0) + ->withTypeCoverageLevel(1) ->withDeadCodeLevel(0) ->withCodeQualityLevel(0) ; diff --git a/src/Redmine/Api/AbstractApi.php b/src/Redmine/Api/AbstractApi.php index 9eb7c497..211bfa86 100644 --- a/src/Redmine/Api/AbstractApi.php +++ b/src/Redmine/Api/AbstractApi.php @@ -73,7 +73,7 @@ final protected function getHttpClient(): HttpClient final public function getLastResponse(): Response { - return $this->lastResponse !== null ? $this->lastResponse : HttpFactory::makeResponse(0, '', ''); + return ($this->lastResponse instanceof Response) ? $this->lastResponse : HttpFactory::makeResponse(0, '', ''); } /** diff --git a/src/Redmine/Api/CustomField.php b/src/Redmine/Api/CustomField.php index bbd8e799..3f2a0faa 100644 --- a/src/Redmine/Api/CustomField.php +++ b/src/Redmine/Api/CustomField.php @@ -83,7 +83,7 @@ final public function listNames(): array */ public function all(array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::list()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` instead.', E_USER_DEPRECATED); try { $this->customFields = $this->list($params); @@ -115,7 +115,7 @@ public function all(array $params = []) */ public function listing($forceUpdate = false, array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED); return $this->doListing($forceUpdate, $params); } @@ -133,7 +133,7 @@ public function listing($forceUpdate = false, array $params = []) */ public function getIdByName($name, array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED); $arr = $this->doListing(false, $params); diff --git a/src/Redmine/Api/Group.php b/src/Redmine/Api/Group.php index 04d10064..d91eae4c 100644 --- a/src/Redmine/Api/Group.php +++ b/src/Redmine/Api/Group.php @@ -85,7 +85,7 @@ final public function listNames(): array */ public function all(array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::list()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` instead.', E_USER_DEPRECATED); try { $this->groups = $this->list($params); @@ -116,7 +116,7 @@ public function all(array $params = []) */ public function listing($forceUpdate = false) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED); if (empty($this->groups) || $forceUpdate) { $this->groups = $this->list(); diff --git a/src/Redmine/Api/Issue.php b/src/Redmine/Api/Issue.php index 3b052777..cefb612b 100644 --- a/src/Redmine/Api/Issue.php +++ b/src/Redmine/Api/Issue.php @@ -126,7 +126,7 @@ final public function list(array $params = []): array */ public function all(array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::list()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` instead.', E_USER_DEPRECATED); try { return $this->list($params); diff --git a/src/Redmine/Api/IssueCategory.php b/src/Redmine/Api/IssueCategory.php index fa16fb39..96ca4901 100644 --- a/src/Redmine/Api/IssueCategory.php +++ b/src/Redmine/Api/IssueCategory.php @@ -111,7 +111,7 @@ final public function listNamesByProject($projectIdentifier): array */ public function all($project, array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::listByProject()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::listByProject()` instead.', E_USER_DEPRECATED); try { return $this->listByProject(strval($project), $params); @@ -141,7 +141,7 @@ public function all($project, array $params = []) */ public function listing($project, $forceUpdate = false) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNamesByProject()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNamesByProject()` instead.', E_USER_DEPRECATED); return $this->doListing($project, $forceUpdate); } @@ -159,7 +159,7 @@ public function listing($project, $forceUpdate = false) */ public function getIdByName($project, $name) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNamesByProject()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNamesByProject()` instead.', E_USER_DEPRECATED); $arr = $this->doListing($project, false); diff --git a/src/Redmine/Api/IssuePriority.php b/src/Redmine/Api/IssuePriority.php index 6a6ca25b..0d0ddc1b 100644 --- a/src/Redmine/Api/IssuePriority.php +++ b/src/Redmine/Api/IssuePriority.php @@ -54,7 +54,7 @@ final public function list(array $params = []): array */ public function all(array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::list()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` instead.', E_USER_DEPRECATED); try { $this->issuePriorities = $this->list($params); diff --git a/src/Redmine/Api/IssueRelation.php b/src/Redmine/Api/IssueRelation.php index 36849c3e..b2bf7191 100644 --- a/src/Redmine/Api/IssueRelation.php +++ b/src/Redmine/Api/IssueRelation.php @@ -59,7 +59,7 @@ final public function listByIssueId(int $issueId, array $params = []): array */ public function all($issueId, array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::listByIssueId()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::listByIssueId()` instead.', E_USER_DEPRECATED); try { $this->relations = $this->listByIssueId($issueId, $params); diff --git a/src/Redmine/Api/IssueStatus.php b/src/Redmine/Api/IssueStatus.php index 293ed989..eb16454c 100644 --- a/src/Redmine/Api/IssueStatus.php +++ b/src/Redmine/Api/IssueStatus.php @@ -83,7 +83,7 @@ final public function listNames(): array */ public function all(array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::list()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` instead.', E_USER_DEPRECATED); try { $this->issueStatuses = $this->list($params); @@ -114,7 +114,7 @@ public function all(array $params = []) */ public function listing($forceUpdate = false) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED); return $this->doListing($forceUpdate); } @@ -131,7 +131,7 @@ public function listing($forceUpdate = false) */ public function getIdByName($name) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED); $arr = $this->doListing(false); diff --git a/src/Redmine/Api/Membership.php b/src/Redmine/Api/Membership.php index 81dc3de0..8affc4bb 100644 --- a/src/Redmine/Api/Membership.php +++ b/src/Redmine/Api/Membership.php @@ -69,7 +69,7 @@ final public function listByProject($projectIdentifier, array $params = []): arr */ public function all($project, array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::listByProject()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::listByProject()` instead.', E_USER_DEPRECATED); try { $this->memberships = $this->listByProject(strval($project), $params); diff --git a/src/Redmine/Api/News.php b/src/Redmine/Api/News.php index 629fdcb1..1ed30be6 100644 --- a/src/Redmine/Api/News.php +++ b/src/Redmine/Api/News.php @@ -84,7 +84,7 @@ final public function list(array $params = []): array */ public function all($project = null, array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::list()` or `' . __CLASS__ . '::listByProject()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` or `' . self::class . '::listByProject()` instead.', E_USER_DEPRECATED); try { if (null === $project) { diff --git a/src/Redmine/Api/Project.php b/src/Redmine/Api/Project.php index 50ed0c46..7be24dd3 100755 --- a/src/Redmine/Api/Project.php +++ b/src/Redmine/Api/Project.php @@ -103,7 +103,7 @@ final public function listNames(): array */ public function all(array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::list()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` instead.', E_USER_DEPRECATED); try { $this->projects = $this->list($params); @@ -136,7 +136,7 @@ public function all(array $params = []) */ public function listing($forceUpdate = false, $reverse = true, array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED); return $this->doListing($forceUpdate, $reverse, $params); } @@ -154,7 +154,7 @@ public function listing($forceUpdate = false, $reverse = true, array $params = [ */ public function getIdByName($name, array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED); $arr = $this->doListing(false, true, $params); diff --git a/src/Redmine/Api/Query.php b/src/Redmine/Api/Query.php index 35232c6a..089e5c9b 100644 --- a/src/Redmine/Api/Query.php +++ b/src/Redmine/Api/Query.php @@ -54,7 +54,7 @@ final public function list(array $params = []): array */ public function all(array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::list()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` instead.', E_USER_DEPRECATED); try { $this->query = $this->list($params); diff --git a/src/Redmine/Api/Role.php b/src/Redmine/Api/Role.php index 8e61cb85..7abc5643 100644 --- a/src/Redmine/Api/Role.php +++ b/src/Redmine/Api/Role.php @@ -84,7 +84,7 @@ final public function listNames(): array */ public function all(array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::list()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` instead.', E_USER_DEPRECATED); try { $this->roles = $this->list($params); @@ -115,7 +115,7 @@ public function all(array $params = []) */ public function listing($forceUpdate = false) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED); if (empty($this->roles) || $forceUpdate) { $this->roles = $this->list(); diff --git a/src/Redmine/Api/Search.php b/src/Redmine/Api/Search.php index 0b31e2a0..f2909d1d 100644 --- a/src/Redmine/Api/Search.php +++ b/src/Redmine/Api/Search.php @@ -54,7 +54,7 @@ final public function listByQuery(string $query, array $params = []): array */ public function search($query, array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::listByQuery()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::listByQuery()` instead.', E_USER_DEPRECATED); try { $this->results = $this->listByQuery($query, $params); diff --git a/src/Redmine/Api/TimeEntry.php b/src/Redmine/Api/TimeEntry.php index 5ad6e088..b070e87b 100644 --- a/src/Redmine/Api/TimeEntry.php +++ b/src/Redmine/Api/TimeEntry.php @@ -59,7 +59,7 @@ final public function list(array $params = []): array */ public function all(array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::list()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` instead.', E_USER_DEPRECATED); try { $this->timeEntries = $this->list($params); diff --git a/src/Redmine/Api/TimeEntryActivity.php b/src/Redmine/Api/TimeEntryActivity.php index 7cda0f09..a388a74c 100644 --- a/src/Redmine/Api/TimeEntryActivity.php +++ b/src/Redmine/Api/TimeEntryActivity.php @@ -78,7 +78,7 @@ final public function listNames(): array */ public function all(array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::list()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` instead.', E_USER_DEPRECATED); try { $this->timeEntryActivities = $this->list($params); @@ -109,7 +109,7 @@ public function all(array $params = []) */ public function listing($forceUpdate = false) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED); return $this->doListing((bool) $forceUpdate); } @@ -126,7 +126,7 @@ public function listing($forceUpdate = false) */ public function getIdByName($name) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED); $arr = $this->doListing(false); diff --git a/src/Redmine/Api/Tracker.php b/src/Redmine/Api/Tracker.php index 6d2c1ac1..6746a2ad 100644 --- a/src/Redmine/Api/Tracker.php +++ b/src/Redmine/Api/Tracker.php @@ -82,7 +82,7 @@ final public function listNames(): array */ public function all(array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::list()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` instead.', E_USER_DEPRECATED); try { $this->trackers = $this->list($params); @@ -113,7 +113,7 @@ public function all(array $params = []) */ public function listing($forceUpdate = false) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED); return $this->doListing($forceUpdate); } @@ -130,7 +130,7 @@ public function listing($forceUpdate = false) */ public function getIdByName($name) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED); $arr = $this->doListing(false); diff --git a/src/Redmine/Api/User.php b/src/Redmine/Api/User.php index dbec8396..a1393de6 100644 --- a/src/Redmine/Api/User.php +++ b/src/Redmine/Api/User.php @@ -102,7 +102,7 @@ final public function listLogins(): array */ public function all(array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::list()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` instead.', E_USER_DEPRECATED); try { $this->users = $this->list($params); @@ -134,7 +134,7 @@ public function all(array $params = []) */ public function listing($forceUpdate = false, array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listLogins()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listLogins()` instead.', E_USER_DEPRECATED); return $this->doListing($forceUpdate, $params); } @@ -166,7 +166,7 @@ public function getCurrentUser(array $params = []) */ public function getIdByUsername($username, array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listLogins()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listLogins()` instead.', E_USER_DEPRECATED); $arr = $this->doListing(false, $params); @@ -199,7 +199,7 @@ public function show($id, array $params = []) // set default ones $params['include'] = array_unique( array_merge( - isset($params['include']) ? $params['include'] : [], + $params['include'] ?? [], [ 'memberships', 'groups', diff --git a/src/Redmine/Api/Version.php b/src/Redmine/Api/Version.php index 5c355116..0e2942e6 100644 --- a/src/Redmine/Api/Version.php +++ b/src/Redmine/Api/Version.php @@ -109,7 +109,7 @@ final public function listNamesByProject($projectIdentifier): array */ public function all($project, array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::listByProject()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::listByProject()` instead.', E_USER_DEPRECATED); try { $this->versions = $this->listByProject(strval($project), $params); @@ -143,7 +143,7 @@ public function all($project, array $params = []) */ public function listing($project, $forceUpdate = false, $reverse = true, array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNamesByProject()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNamesByProject()` instead.', E_USER_DEPRECATED); return $this->doListing($project, $forceUpdate, $reverse, $params); } @@ -162,7 +162,7 @@ public function listing($project, $forceUpdate = false, $reverse = true, array $ */ public function getIdByName($project, $name, array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNamesByProject()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNamesByProject()` instead.', E_USER_DEPRECATED); $arr = $this->doListing($project, false, true, $params); diff --git a/src/Redmine/Api/Wiki.php b/src/Redmine/Api/Wiki.php index 224ec81f..e62d789c 100644 --- a/src/Redmine/Api/Wiki.php +++ b/src/Redmine/Api/Wiki.php @@ -69,7 +69,7 @@ final public function listByProject($projectIdentifier, array $params = []): arr */ public function all($project, array $params = []) { - @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::listByProject()` instead.', E_USER_DEPRECATED); + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::listByProject()` instead.', E_USER_DEPRECATED); try { $this->wikiPages = $this->listByProject(strval($project), $params); diff --git a/src/Redmine/Client/ClientApiTrait.php b/src/Redmine/Client/ClientApiTrait.php index 3c1ad4a3..41215670 100644 --- a/src/Redmine/Client/ClientApiTrait.php +++ b/src/Redmine/Client/ClientApiTrait.php @@ -21,26 +21,26 @@ trait ClientApiTrait * @var array */ private array $apiClassnames = [ - 'attachment' => 'Redmine\Api\Attachment', - 'group' => 'Redmine\Api\Group', - 'custom_fields' => 'Redmine\Api\CustomField', - 'issue' => 'Redmine\Api\Issue', - 'issue_category' => 'Redmine\Api\IssueCategory', - 'issue_priority' => 'Redmine\Api\IssuePriority', - 'issue_relation' => 'Redmine\Api\IssueRelation', - 'issue_status' => 'Redmine\Api\IssueStatus', - 'membership' => 'Redmine\Api\Membership', - 'news' => 'Redmine\Api\News', - 'project' => 'Redmine\Api\Project', - 'query' => 'Redmine\Api\Query', - 'role' => 'Redmine\Api\Role', - 'search' => 'Redmine\Api\Search', - 'time_entry' => 'Redmine\Api\TimeEntry', - 'time_entry_activity' => 'Redmine\Api\TimeEntryActivity', - 'tracker' => 'Redmine\Api\Tracker', - 'user' => 'Redmine\Api\User', - 'version' => 'Redmine\Api\Version', - 'wiki' => 'Redmine\Api\Wiki', + 'attachment' => \Redmine\Api\Attachment::class, + 'group' => \Redmine\Api\Group::class, + 'custom_fields' => \Redmine\Api\CustomField::class, + 'issue' => \Redmine\Api\Issue::class, + 'issue_category' => \Redmine\Api\IssueCategory::class, + 'issue_priority' => \Redmine\Api\IssuePriority::class, + 'issue_relation' => \Redmine\Api\IssueRelation::class, + 'issue_status' => \Redmine\Api\IssueStatus::class, + 'membership' => \Redmine\Api\Membership::class, + 'news' => \Redmine\Api\News::class, + 'project' => \Redmine\Api\Project::class, + 'query' => \Redmine\Api\Query::class, + 'role' => \Redmine\Api\Role::class, + 'search' => \Redmine\Api\Search::class, + 'time_entry' => \Redmine\Api\TimeEntry::class, + 'time_entry_activity' => \Redmine\Api\TimeEntryActivity::class, + 'tracker' => \Redmine\Api\Tracker::class, + 'user' => \Redmine\Api\User::class, + 'version' => \Redmine\Api\Version::class, + 'wiki' => \Redmine\Api\Wiki::class, ]; /** diff --git a/tests/Integration/IssueCategoryXmlTest.php b/tests/Integration/IssueCategoryXmlTest.php index 9b67f1a1..4b11e7d1 100644 --- a/tests/Integration/IssueCategoryXmlTest.php +++ b/tests/Integration/IssueCategoryXmlTest.php @@ -12,7 +12,7 @@ public function testCreateBlank(): void { /** @var \Redmine\Api\IssueCategory */ $api = MockClient::create()->getApi('issue_category'); - $this->assertInstanceOf('Redmine\Api\IssueCategory', $api); + $this->assertInstanceOf(\Redmine\Api\IssueCategory::class, $api); $this->expectException(MissingParameterException::class); $this->expectExceptionMessage('Theses parameters are mandatory: `name`'); diff --git a/tests/Integration/Psr18ClientRequestGenerationTest.php b/tests/Integration/Psr18ClientRequestGenerationTest.php index 36008986..a8f55947 100644 --- a/tests/Integration/Psr18ClientRequestGenerationTest.php +++ b/tests/Integration/Psr18ClientRequestGenerationTest.php @@ -65,9 +65,7 @@ public function testPsr18ClientCreatesCorrectRequests( }); $requestFactory = $this->createMock(RequestFactoryInterface::class); - $requestFactory->method('createRequest')->willReturnCallback(function ($method, $uri) { - return new Request($method, $uri); - }); + $requestFactory->method('createRequest')->willReturnCallback(fn($method, $uri) => new Request($method, $uri)); $streamFactory = new class implements StreamFactoryInterface { public function createStream(string $content = ''): StreamInterface diff --git a/tests/Integration/UserXmlTest.php b/tests/Integration/UserXmlTest.php index ea17370c..23a97a1b 100644 --- a/tests/Integration/UserXmlTest.php +++ b/tests/Integration/UserXmlTest.php @@ -12,7 +12,7 @@ public function testCreateBlank(): void { /** @var \Redmine\Api\User */ $api = MockClient::create()->getApi('user'); - $this->assertInstanceOf('Redmine\Api\User', $api); + $this->assertInstanceOf(\Redmine\Api\User::class, $api); $this->expectException(MissingParameterException::class); $this->expectExceptionMessage('Theses parameters are mandatory: `login`, `lastname`, `firstname`, `mail`'); diff --git a/tests/Unit/Client/NativeCurlClientTest.php b/tests/Unit/Client/NativeCurlClientTest.php index c229db48..4876cdc7 100644 --- a/tests/Unit/Client/NativeCurlClientTest.php +++ b/tests/Unit/Client/NativeCurlClientTest.php @@ -990,25 +990,25 @@ public function testGetApiShouldReturnApiInstance(string $apiName, string $class public static function getApiClassesProvider(): array { return [ - ['attachment', 'Redmine\Api\Attachment'], - ['group', 'Redmine\Api\Group'], - ['custom_fields', 'Redmine\Api\CustomField'], - ['issue', 'Redmine\Api\Issue'], - ['issue_category', 'Redmine\Api\IssueCategory'], - ['issue_priority', 'Redmine\Api\IssuePriority'], - ['issue_relation', 'Redmine\Api\IssueRelation'], - ['issue_status', 'Redmine\Api\IssueStatus'], - ['membership', 'Redmine\Api\Membership'], - ['news', 'Redmine\Api\News'], - ['project', 'Redmine\Api\Project'], - ['query', 'Redmine\Api\Query'], - ['role', 'Redmine\Api\Role'], - ['time_entry', 'Redmine\Api\TimeEntry'], - ['time_entry_activity', 'Redmine\Api\TimeEntryActivity'], - ['tracker', 'Redmine\Api\Tracker'], - ['user', 'Redmine\Api\User'], - ['version', 'Redmine\Api\Version'], - ['wiki', 'Redmine\Api\Wiki'], + ['attachment', \Redmine\Api\Attachment::class], + ['group', \Redmine\Api\Group::class], + ['custom_fields', \Redmine\Api\CustomField::class], + ['issue', \Redmine\Api\Issue::class], + ['issue_category', \Redmine\Api\IssueCategory::class], + ['issue_priority', \Redmine\Api\IssuePriority::class], + ['issue_relation', \Redmine\Api\IssueRelation::class], + ['issue_status', \Redmine\Api\IssueStatus::class], + ['membership', \Redmine\Api\Membership::class], + ['news', \Redmine\Api\News::class], + ['project', \Redmine\Api\Project::class], + ['query', \Redmine\Api\Query::class], + ['role', \Redmine\Api\Role::class], + ['time_entry', \Redmine\Api\TimeEntry::class], + ['time_entry_activity', \Redmine\Api\TimeEntryActivity::class], + ['tracker', \Redmine\Api\Tracker::class], + ['user', \Redmine\Api\User::class], + ['version', \Redmine\Api\Version::class], + ['wiki', \Redmine\Api\Wiki::class], ]; } diff --git a/tests/Unit/Client/Psr18ClientTest.php b/tests/Unit/Client/Psr18ClientTest.php index 472cf458..f76d2fc4 100644 --- a/tests/Unit/Client/Psr18ClientTest.php +++ b/tests/Unit/Client/Psr18ClientTest.php @@ -477,25 +477,25 @@ public function testGetApiShouldReturnApiInstance(string $apiName, string $class public static function getApiClassesProvider(): array { return [ - ['attachment', 'Redmine\Api\Attachment'], - ['group', 'Redmine\Api\Group'], - ['custom_fields', 'Redmine\Api\CustomField'], - ['issue', 'Redmine\Api\Issue'], - ['issue_category', 'Redmine\Api\IssueCategory'], - ['issue_priority', 'Redmine\Api\IssuePriority'], - ['issue_relation', 'Redmine\Api\IssueRelation'], - ['issue_status', 'Redmine\Api\IssueStatus'], - ['membership', 'Redmine\Api\Membership'], - ['news', 'Redmine\Api\News'], - ['project', 'Redmine\Api\Project'], - ['query', 'Redmine\Api\Query'], - ['role', 'Redmine\Api\Role'], - ['time_entry', 'Redmine\Api\TimeEntry'], - ['time_entry_activity', 'Redmine\Api\TimeEntryActivity'], - ['tracker', 'Redmine\Api\Tracker'], - ['user', 'Redmine\Api\User'], - ['version', 'Redmine\Api\Version'], - ['wiki', 'Redmine\Api\Wiki'], + ['attachment', \Redmine\Api\Attachment::class], + ['group', \Redmine\Api\Group::class], + ['custom_fields', \Redmine\Api\CustomField::class], + ['issue', \Redmine\Api\Issue::class], + ['issue_category', \Redmine\Api\IssueCategory::class], + ['issue_priority', \Redmine\Api\IssuePriority::class], + ['issue_relation', \Redmine\Api\IssueRelation::class], + ['issue_status', \Redmine\Api\IssueStatus::class], + ['membership', \Redmine\Api\Membership::class], + ['news', \Redmine\Api\News::class], + ['project', \Redmine\Api\Project::class], + ['query', \Redmine\Api\Query::class], + ['role', \Redmine\Api\Role::class], + ['time_entry', \Redmine\Api\TimeEntry::class], + ['time_entry_activity', \Redmine\Api\TimeEntryActivity::class], + ['tracker', \Redmine\Api\Tracker::class], + ['user', \Redmine\Api\User::class], + ['version', \Redmine\Api\Version::class], + ['wiki', \Redmine\Api\Wiki::class], ]; } From db15e3e7e7ed5e6d240dc60d04fc2f77a9010055 Mon Sep 17 00:00:00 2001 From: Artur Weigandt Date: Sat, 22 Nov 2025 08:37:54 +0100 Subject: [PATCH 4/5] refactor: fix code with dead code prepared sets --- .rector.php | 5 +- src/Redmine/Api/CustomField.php | 2 +- src/Redmine/Api/Group.php | 2 +- src/Redmine/Api/IssueStatus.php | 2 +- src/Redmine/Api/Project.php | 2 +- src/Redmine/Api/Role.php | 2 +- src/Redmine/Api/TimeEntryActivity.php | 2 +- src/Redmine/Api/Tracker.php | 2 +- src/Redmine/Api/User.php | 2 +- .../Exception/UnexpectedResponseException.php | 2 +- tests/Fixtures/MockClient.php | 8 +- tests/RedmineExtension/RedmineInstance.php | 2 +- tests/Unit/Api/CustomFieldTest.php | 6 -- .../Client/NativeCurlClient/RequestTest.php | 8 +- tests/Unit/Client/NativeCurlClientTest.php | 94 +++++++------------ tests/Unit/Client/Psr18ClientTest.php | 2 +- tests/Unit/Serializer/JsonSerializerTest.php | 4 +- 17 files changed, 60 insertions(+), 87 deletions(-) diff --git a/.rector.php b/.rector.php index 0e157272..0ed2ae66 100644 --- a/.rector.php +++ b/.rector.php @@ -12,7 +12,10 @@ // uncomment to reach your current PHP version //->withPhpSets() ->withPhp74Sets() + ->withPhpVersion(70400) ->withTypeCoverageLevel(1) - ->withDeadCodeLevel(0) ->withCodeQualityLevel(0) + ->withPreparedSets( + true + ) ; diff --git a/src/Redmine/Api/CustomField.php b/src/Redmine/Api/CustomField.php index 3f2a0faa..1d0d26e8 100644 --- a/src/Redmine/Api/CustomField.php +++ b/src/Redmine/Api/CustomField.php @@ -23,7 +23,7 @@ class CustomField extends AbstractApi /** * @var null|array */ - private $customFieldNames = null; + private $customFieldNames; /** * List custom fields. diff --git a/src/Redmine/Api/Group.php b/src/Redmine/Api/Group.php index d91eae4c..77c0a172 100644 --- a/src/Redmine/Api/Group.php +++ b/src/Redmine/Api/Group.php @@ -29,7 +29,7 @@ class Group extends AbstractApi /** * @var null|array */ - private $groupNames = null; + private $groupNames; /** * List groups. diff --git a/src/Redmine/Api/IssueStatus.php b/src/Redmine/Api/IssueStatus.php index eb16454c..82511fea 100644 --- a/src/Redmine/Api/IssueStatus.php +++ b/src/Redmine/Api/IssueStatus.php @@ -23,7 +23,7 @@ class IssueStatus extends AbstractApi /** * @var array */ - private $issueStatusNames = null; + private $issueStatusNames; /** * List issue statuses. diff --git a/src/Redmine/Api/Project.php b/src/Redmine/Api/Project.php index 7be24dd3..309063f9 100755 --- a/src/Redmine/Api/Project.php +++ b/src/Redmine/Api/Project.php @@ -30,7 +30,7 @@ class Project extends AbstractApi /** * @var null|array */ - private $projectNames = null; + private $projectNames; /** * List projects. diff --git a/src/Redmine/Api/Role.php b/src/Redmine/Api/Role.php index 7abc5643..48aa94dd 100644 --- a/src/Redmine/Api/Role.php +++ b/src/Redmine/Api/Role.php @@ -25,7 +25,7 @@ class Role extends AbstractApi /** * @var null|array */ - private $roleNames = null; + private $roleNames; /** * List roles. diff --git a/src/Redmine/Api/TimeEntryActivity.php b/src/Redmine/Api/TimeEntryActivity.php index a388a74c..5036ac1a 100644 --- a/src/Redmine/Api/TimeEntryActivity.php +++ b/src/Redmine/Api/TimeEntryActivity.php @@ -23,7 +23,7 @@ class TimeEntryActivity extends AbstractApi /** * @var null|array */ - private $timeEntryActivityNames = null; + private $timeEntryActivityNames; /** * List time entry activities. diff --git a/src/Redmine/Api/Tracker.php b/src/Redmine/Api/Tracker.php index 6746a2ad..8ff8bfee 100644 --- a/src/Redmine/Api/Tracker.php +++ b/src/Redmine/Api/Tracker.php @@ -23,7 +23,7 @@ class Tracker extends AbstractApi /** * @var null|array */ - private $trackerNames = null; + private $trackerNames; /** * List trackers. diff --git a/src/Redmine/Api/User.php b/src/Redmine/Api/User.php index a1393de6..be8f409e 100644 --- a/src/Redmine/Api/User.php +++ b/src/Redmine/Api/User.php @@ -29,7 +29,7 @@ class User extends AbstractApi /** * @var null|array */ - private $userLogins = null; + private $userLogins; /** * List users. diff --git a/src/Redmine/Exception/UnexpectedResponseException.php b/src/Redmine/Exception/UnexpectedResponseException.php index 12d65746..71b0835b 100644 --- a/src/Redmine/Exception/UnexpectedResponseException.php +++ b/src/Redmine/Exception/UnexpectedResponseException.php @@ -19,7 +19,7 @@ final class UnexpectedResponseException extends RuntimeException implements Redm /** * @var Response|null */ - private $response = null; + private $response; public static function create(Response $response, ?Throwable $prev = null): self { diff --git a/tests/Fixtures/MockClient.php b/tests/Fixtures/MockClient.php index 735e47d7..0a03b870 100644 --- a/tests/Fixtures/MockClient.php +++ b/tests/Fixtures/MockClient.php @@ -26,7 +26,7 @@ public static function create(): self * * @var mixed */ - public $runRequestReturnValue = null; + public $runRequestReturnValue; /** * Return value the mocked runRequest method should return. @@ -95,7 +95,7 @@ public function requestDelete(string $path): bool */ public function getLastResponseStatusCode(): int { - return (int) $this->responseCodeMock; + return $this->responseCodeMock; } /** @@ -103,7 +103,7 @@ public function getLastResponseStatusCode(): int */ public function getLastResponseContentType(): string { - return (string) $this->responseContentTypeMock; + return $this->responseContentTypeMock; } /** @@ -111,7 +111,7 @@ public function getLastResponseContentType(): string */ public function getLastResponseBody(): string { - return (string) $this->responseBodyMock; + return $this->responseBodyMock; } private function runRequest(string $path, string $method = 'GET', string $data = ''): bool diff --git a/tests/RedmineExtension/RedmineInstance.php b/tests/RedmineExtension/RedmineInstance.php index e5f52708..d3398b41 100644 --- a/tests/RedmineExtension/RedmineInstance.php +++ b/tests/RedmineExtension/RedmineInstance.php @@ -66,7 +66,7 @@ private function __construct(InstanceRegistration $tracer, RedmineVersion $versi $parts = explode('.', $version->asString()); $this->redmineUrl = 'http://redmine-' . intval($parts[0]) . '-' . intval($parts[1]) . ':3000'; - $this->apiKey = sha1($versionId . (string) time()); + $this->apiKey = sha1($versionId . time()); $this->runHealthChecks($version); diff --git a/tests/Unit/Api/CustomFieldTest.php b/tests/Unit/Api/CustomFieldTest.php index a713a7f9..e2b8b618 100644 --- a/tests/Unit/Api/CustomFieldTest.php +++ b/tests/Unit/Api/CustomFieldTest.php @@ -151,12 +151,6 @@ public function testAllCallsEndpointUntilOffsetIsHigherThanTotalCount(): void // Test values $response = '{"limit":"100","offset":"10","total_count":"5","items":[]}'; $allParameters = ['limit' => 250]; - $returnDataSet = [ - 'limit' => '100', - 'offset' => '10', - 'total_count' => '5', - 'items' => [], - ]; // Create the used mock objects $client = $this->createMock(Client::class); diff --git a/tests/Unit/Client/NativeCurlClient/RequestTest.php b/tests/Unit/Client/NativeCurlClient/RequestTest.php index 05c25177..10b9c6db 100644 --- a/tests/Unit/Client/NativeCurlClient/RequestTest.php +++ b/tests/Unit/Client/NativeCurlClient/RequestTest.php @@ -32,7 +32,7 @@ public function testRequestReturnsCorrectResponse($method, $data, $statusCode, $ $curlExec = $this->getFunctionMock($namespace, 'curl_exec'); $curlExec->expects($this->exactly(1))->willReturn($content); - $curlSetoptArray = $this->getFunctionMock($namespace, 'curl_setopt_array'); + $this->getFunctionMock($namespace, 'curl_setopt_array'); $curlGetinfo = $this->getFunctionMock($namespace, 'curl_getinfo'); $curlGetinfo->expects($this->exactly(2))->willReturnMap(([ @@ -43,7 +43,7 @@ public function testRequestReturnsCorrectResponse($method, $data, $statusCode, $ $curlErrno = $this->getFunctionMock($namespace, 'curl_errno'); $curlErrno->expects($this->exactly(1))->willReturn(CURLE_OK); - $curlClose = $this->getFunctionMock($namespace, 'curl_close'); + $this->getFunctionMock($namespace, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', @@ -105,7 +105,7 @@ public function testRequestWithUploadAndFilepathReturnsCorrectResponse(): void $curlExec = $this->getFunctionMock($namespace, 'curl_exec'); $curlExec->expects($this->exactly(1))->willReturn('{"upload":{}}'); - $curlSetoptArray = $this->getFunctionMock($namespace, 'curl_setopt_array'); + $this->getFunctionMock($namespace, 'curl_setopt_array'); $curlGetinfo = $this->getFunctionMock($namespace, 'curl_getinfo'); $curlGetinfo->expects($this->exactly(2))->willReturnMap(([ @@ -116,7 +116,7 @@ public function testRequestWithUploadAndFilepathReturnsCorrectResponse(): void $curlErrno = $this->getFunctionMock($namespace, 'curl_errno'); $curlErrno->expects($this->exactly(1))->willReturn(CURLE_OK); - $curlClose = $this->getFunctionMock($namespace, 'curl_close'); + $this->getFunctionMock($namespace, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', diff --git a/tests/Unit/Client/NativeCurlClientTest.php b/tests/Unit/Client/NativeCurlClientTest.php index 4876cdc7..a42398c0 100644 --- a/tests/Unit/Client/NativeCurlClientTest.php +++ b/tests/Unit/Client/NativeCurlClientTest.php @@ -204,7 +204,7 @@ public function testStartAndStopImpersonateUser(): void $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(3))->willReturn(0); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', @@ -259,7 +259,7 @@ public function testSetSslVersion(): void $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(3))->willReturn(0); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', @@ -315,7 +315,7 @@ public function testSetSslVerifypeer(): void $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(3))->willReturn(0); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', @@ -371,7 +371,7 @@ public function testSetSslVerifyhost(): void $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(3))->willReturn(0); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', @@ -428,7 +428,7 @@ public function testSetCustomHttpHeaders(): void $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(3))->willReturn(0); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', @@ -489,7 +489,7 @@ public function testSetCustomHost(): void $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(3))->willReturn(0); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', @@ -546,7 +546,7 @@ public function testSetPort(): void $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(3))->willReturn(0); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', @@ -600,7 +600,7 @@ public function testCustomPortWillSetFromSchema(): void $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(1))->willReturn(0); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'https://test.local', @@ -650,7 +650,7 @@ public function testCustomPortWillSetFromUrl(): void $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(1))->willReturn(0); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'http://test.local:3456', @@ -674,7 +674,7 @@ public function testRequestsReturnsCorrectContent($method, $data, $boolReturn, $ $curlExec = $this->getFunctionMock(self::__NAMESPACE__, 'curl_exec'); $curlExec->expects($this->exactly(1))->willReturn($content); - $curlSetoptArray = $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); $curlGetinfo = $this->getFunctionMock(self::__NAMESPACE__, 'curl_getinfo'); $curlGetinfo->expects($this->exactly(2))->willReturnMap(([ @@ -685,7 +685,7 @@ public function testRequestsReturnsCorrectContent($method, $data, $boolReturn, $ $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(1))->willReturn(CURLE_OK); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', @@ -726,23 +726,17 @@ public static function getRequestReponseData(): array public function testRequestGetTriggersDeprecationWarning(): void { - $curl = $this->createMock(stdClass::class); - - $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); - - $curlExec = $this->getFunctionMock(self::__NAMESPACE__, 'curl_exec'); - - $curlSetoptArray = $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); - - $curlGetinfo = $this->getFunctionMock(self::__NAMESPACE__, 'curl_getinfo'); - + $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_exec'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_getinfo'); $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(1))->willReturn(CURLE_COULDNT_CONNECT); $curlError = $this->getFunctionMock(self::__NAMESPACE__, 'curl_error'); $curlError->expects($this->exactly(1))->willReturn(''); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', @@ -771,23 +765,17 @@ function ($errno, $errstr): bool { public function testRequestPostTriggersDeprecationWarning(): void { - $curl = $this->createMock(stdClass::class); - - $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); - - $curlExec = $this->getFunctionMock(self::__NAMESPACE__, 'curl_exec'); - - $curlSetoptArray = $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); - - $curlGetinfo = $this->getFunctionMock(self::__NAMESPACE__, 'curl_getinfo'); - + $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_exec'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_getinfo'); $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(1))->willReturn(CURLE_COULDNT_CONNECT); $curlError = $this->getFunctionMock(self::__NAMESPACE__, 'curl_error'); $curlError->expects($this->exactly(1))->willReturn(''); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', @@ -816,23 +804,17 @@ function ($errno, $errstr): bool { public function testRequestPutTriggersDeprecationWarning(): void { - $curl = $this->createMock(stdClass::class); - - $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); - - $curlExec = $this->getFunctionMock(self::__NAMESPACE__, 'curl_exec'); - - $curlSetoptArray = $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); - - $curlGetinfo = $this->getFunctionMock(self::__NAMESPACE__, 'curl_getinfo'); - + $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_exec'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_getinfo'); $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(1))->willReturn(CURLE_COULDNT_CONNECT); $curlError = $this->getFunctionMock(self::__NAMESPACE__, 'curl_error'); $curlError->expects($this->exactly(1))->willReturn(''); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', @@ -861,23 +843,17 @@ function ($errno, $errstr): bool { public function testRequestDeleteTriggersDeprecationWarning(): void { - $curl = $this->createMock(stdClass::class); - - $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); - - $curlExec = $this->getFunctionMock(self::__NAMESPACE__, 'curl_exec'); - - $curlSetoptArray = $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); - - $curlGetinfo = $this->getFunctionMock(self::__NAMESPACE__, 'curl_getinfo'); - + $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_exec'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_getinfo'); $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(1))->willReturn(CURLE_COULDNT_CONNECT); $curlError = $this->getFunctionMock(self::__NAMESPACE__, 'curl_error'); $curlError->expects($this->exactly(1))->willReturn(''); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', @@ -918,7 +894,7 @@ public function testHandlingOfResponseWithoutContent(): void $curlExec = $this->getFunctionMock(self::__NAMESPACE__, 'curl_exec'); $curlExec->expects($this->exactly(1))->willReturn(''); - $curlSetoptArray = $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); $curlGetinfo = $this->getFunctionMock(self::__NAMESPACE__, 'curl_getinfo'); $curlGetinfo->expects($this->exactly(2))->willReturnMap(([ @@ -929,7 +905,7 @@ public function testHandlingOfResponseWithoutContent(): void $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(1))->willReturn(CURLE_OK); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', @@ -952,7 +928,7 @@ public function testCurlErrorThrowsException(): void $curlExec = $this->getFunctionMock(self::__NAMESPACE__, 'curl_exec'); $curlExec->expects($this->exactly(1))->willReturn(false); - $curlSetoptArray = $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); $curlErrno->expects($this->exactly(1))->willReturn(CURLE_URL_MALFORMAT); @@ -960,7 +936,7 @@ public function testCurlErrorThrowsException(): void $curlError = $this->getFunctionMock(self::__NAMESPACE__, 'curl_error'); $curlError->expects($this->exactly(1))->willReturn('cURL error 3: malformed'); - $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); $client = new NativeCurlClient( 'http://test.local', diff --git a/tests/Unit/Client/Psr18ClientTest.php b/tests/Unit/Client/Psr18ClientTest.php index f76d2fc4..db74e867 100644 --- a/tests/Unit/Client/Psr18ClientTest.php +++ b/tests/Unit/Client/Psr18ClientTest.php @@ -504,7 +504,7 @@ public function testCreateWithoutFactoryThrowsException(): void $this->expectException(Exception::class); $this->expectExceptionMessage('Redmine\Client\Psr18Client::__construct(): Argument #2 ($requestFactory) must be of type Psr\Http\Message\RequestFactoryInterface'); - $client = new Psr18Client( + new Psr18Client( $this->createMock(ClientInterface::class), /** @phpstan-ignore-next-line We are providing an invalid parameter to test the exception */ new stdClass(), diff --git a/tests/Unit/Serializer/JsonSerializerTest.php b/tests/Unit/Serializer/JsonSerializerTest.php index 81f7df7c..b6aa6fec 100644 --- a/tests/Unit/Serializer/JsonSerializerTest.php +++ b/tests/Unit/Serializer/JsonSerializerTest.php @@ -93,7 +93,7 @@ public function testCreateFromStringWithInvalidStringThrowsException(string $mes $this->expectException(SerializerException::class); $this->expectExceptionMessage($message); - $serializer = JsonSerializer::createFromString($data); + JsonSerializer::createFromString($data); } public static function getNormalizedToEncodedData(): array @@ -210,6 +210,6 @@ public function testCreateFromArrayWithInvalidDataThrowsException(string $messag $this->expectException(SerializerException::class); $this->expectExceptionMessage($message); - $serializer = JsonSerializer::createFromArray($data); + JsonSerializer::createFromArray($data); } } From 72dbf347091173bbd5f29f359e86f44cc740a8d2 Mon Sep 17 00:00:00 2001 From: Artur Weigandt Date: Sat, 22 Nov 2025 08:44:34 +0100 Subject: [PATCH 5/5] refactor: fix code with code quality prepared sets --- .rector.php | 2 +- src/Redmine/Api/AbstractApi.php | 4 ++-- src/Redmine/Api/CustomField.php | 4 ++-- src/Redmine/Api/Group.php | 4 ++-- src/Redmine/Api/Issue.php | 2 +- src/Redmine/Api/IssueCategory.php | 4 ++-- src/Redmine/Api/IssuePriority.php | 2 +- src/Redmine/Api/IssueRelation.php | 2 +- src/Redmine/Api/IssueStatus.php | 4 ++-- src/Redmine/Api/Membership.php | 2 +- src/Redmine/Api/News.php | 8 ++------ src/Redmine/Api/Project.php | 4 ++-- src/Redmine/Api/Query.php | 2 +- src/Redmine/Api/Role.php | 4 ++-- src/Redmine/Api/Search.php | 2 +- src/Redmine/Api/TimeEntry.php | 2 +- src/Redmine/Api/TimeEntryActivity.php | 4 ++-- src/Redmine/Api/Tracker.php | 4 ++-- src/Redmine/Api/User.php | 4 ++-- src/Redmine/Api/Version.php | 4 ++-- src/Redmine/Api/Wiki.php | 2 +- src/Redmine/Client/NativeCurlClient.php | 12 +++++------ src/Redmine/Client/Psr18Client.php | 6 +++--- .../Exception/UnexpectedResponseException.php | 2 +- src/Redmine/Http/HttpFactory.php | 4 ++-- src/Redmine/Serializer/PathSerializer.php | 2 +- tests/Behat/Bootstrap/FeatureContext.php | 12 +++++------ tests/Fixtures/AssertingHttpClient.php | 4 ++-- tests/RedmineExtension/BehatHookTracer.php | 20 +++++++++---------- 29 files changed, 63 insertions(+), 69 deletions(-) diff --git a/.rector.php b/.rector.php index 0ed2ae66..9f7292da 100644 --- a/.rector.php +++ b/.rector.php @@ -14,8 +14,8 @@ ->withPhp74Sets() ->withPhpVersion(70400) ->withTypeCoverageLevel(1) - ->withCodeQualityLevel(0) ->withPreparedSets( + true, true ) ; diff --git a/src/Redmine/Api/AbstractApi.php b/src/Redmine/Api/AbstractApi.php index 211bfa86..881053fc 100644 --- a/src/Redmine/Api/AbstractApi.php +++ b/src/Redmine/Api/AbstractApi.php @@ -300,7 +300,7 @@ protected function retrieveAll($endpoint, array $params = []) */ protected function retrieveData(string $endpoint, array $params = []): array { - if (empty($params)) { + if ($params === []) { $this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeRequest( 'GET', strval($endpoint), @@ -366,7 +366,7 @@ protected function retrieveData(string $endpoint, array $params = []): array $offset += $realLimit; if ( - empty($newDataSet) + $newDataSet === [] || !isset($newDataSet['limit']) || ( isset($newDataSet['offset']) diff --git a/src/Redmine/Api/CustomField.php b/src/Redmine/Api/CustomField.php index 1d0d26e8..4e6a34be 100644 --- a/src/Redmine/Api/CustomField.php +++ b/src/Redmine/Api/CustomField.php @@ -92,7 +92,7 @@ public function all(array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } @@ -151,7 +151,7 @@ public function getIdByName($name, array $params = []) */ private function doListing(bool $forceUpdate, array $params): array { - if (empty($this->customFields) || $forceUpdate) { + if ($this->customFields === [] || $forceUpdate) { $this->customFields = $this->list($params); } diff --git a/src/Redmine/Api/Group.php b/src/Redmine/Api/Group.php index 77c0a172..954a4cc9 100644 --- a/src/Redmine/Api/Group.php +++ b/src/Redmine/Api/Group.php @@ -94,7 +94,7 @@ public function all(array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } @@ -118,7 +118,7 @@ public function listing($forceUpdate = false) { @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED); - if (empty($this->groups) || $forceUpdate) { + if ($this->groups === [] || $forceUpdate) { $this->groups = $this->list(); } $ret = []; diff --git a/src/Redmine/Api/Issue.php b/src/Redmine/Api/Issue.php index cefb612b..267f1a63 100644 --- a/src/Redmine/Api/Issue.php +++ b/src/Redmine/Api/Issue.php @@ -135,7 +135,7 @@ public function all(array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } diff --git a/src/Redmine/Api/IssueCategory.php b/src/Redmine/Api/IssueCategory.php index 96ca4901..443f1b94 100644 --- a/src/Redmine/Api/IssueCategory.php +++ b/src/Redmine/Api/IssueCategory.php @@ -120,7 +120,7 @@ public function all($project, array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } @@ -296,7 +296,7 @@ public function remove($id, array $params = []) */ private function doListing($projectIdentifier, bool $forceUpdate): array { - if (true === $forceUpdate || empty($this->issueCategories)) { + if ($forceUpdate || $this->issueCategories === []) { $this->issueCategories = $this->listByProject($projectIdentifier); } diff --git a/src/Redmine/Api/IssuePriority.php b/src/Redmine/Api/IssuePriority.php index 0d0ddc1b..167a590b 100644 --- a/src/Redmine/Api/IssuePriority.php +++ b/src/Redmine/Api/IssuePriority.php @@ -63,7 +63,7 @@ public function all(array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } diff --git a/src/Redmine/Api/IssueRelation.php b/src/Redmine/Api/IssueRelation.php index b2bf7191..33cdd415 100644 --- a/src/Redmine/Api/IssueRelation.php +++ b/src/Redmine/Api/IssueRelation.php @@ -68,7 +68,7 @@ public function all($issueId, array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } diff --git a/src/Redmine/Api/IssueStatus.php b/src/Redmine/Api/IssueStatus.php index 82511fea..dff5e438 100644 --- a/src/Redmine/Api/IssueStatus.php +++ b/src/Redmine/Api/IssueStatus.php @@ -92,7 +92,7 @@ public function all(array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } @@ -147,7 +147,7 @@ public function getIdByName($name) */ private function doListing(bool $forceUpdate): array { - if (empty($this->issueStatuses) || $forceUpdate) { + if ($this->issueStatuses === [] || $forceUpdate) { $this->issueStatuses = $this->list(); } diff --git a/src/Redmine/Api/Membership.php b/src/Redmine/Api/Membership.php index 8affc4bb..65f83220 100644 --- a/src/Redmine/Api/Membership.php +++ b/src/Redmine/Api/Membership.php @@ -78,7 +78,7 @@ public function all($project, array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } diff --git a/src/Redmine/Api/News.php b/src/Redmine/Api/News.php index 1ed30be6..f1473125 100644 --- a/src/Redmine/Api/News.php +++ b/src/Redmine/Api/News.php @@ -87,17 +87,13 @@ public function all($project = null, array $params = []) @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` or `' . self::class . '::listByProject()` instead.', E_USER_DEPRECATED); try { - if (null === $project) { - $this->news = $this->list($params); - } else { - $this->news = $this->listByProject(strval($project), $params); - } + $this->news = null === $project ? $this->list($params) : $this->listByProject(strval($project), $params); } catch (Exception $e) { if ($this->getLastResponse()->getContent() === '') { return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } diff --git a/src/Redmine/Api/Project.php b/src/Redmine/Api/Project.php index 309063f9..e1e78e84 100755 --- a/src/Redmine/Api/Project.php +++ b/src/Redmine/Api/Project.php @@ -112,7 +112,7 @@ public function all(array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } @@ -460,7 +460,7 @@ public function remove($id) */ private function doListing(bool $forceUpdate, bool $reverse, array $params): array { - if (true === $forceUpdate || empty($this->projects)) { + if ($forceUpdate || $this->projects === []) { $this->projects = $this->list($params); } diff --git a/src/Redmine/Api/Query.php b/src/Redmine/Api/Query.php index 089e5c9b..7997b06d 100644 --- a/src/Redmine/Api/Query.php +++ b/src/Redmine/Api/Query.php @@ -63,7 +63,7 @@ public function all(array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } diff --git a/src/Redmine/Api/Role.php b/src/Redmine/Api/Role.php index 48aa94dd..b1c85235 100644 --- a/src/Redmine/Api/Role.php +++ b/src/Redmine/Api/Role.php @@ -93,7 +93,7 @@ public function all(array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } @@ -117,7 +117,7 @@ public function listing($forceUpdate = false) { @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED); - if (empty($this->roles) || $forceUpdate) { + if ($this->roles === [] || $forceUpdate) { $this->roles = $this->list(); } $ret = []; diff --git a/src/Redmine/Api/Search.php b/src/Redmine/Api/Search.php index f2909d1d..6d36ed7e 100644 --- a/src/Redmine/Api/Search.php +++ b/src/Redmine/Api/Search.php @@ -63,7 +63,7 @@ public function search($query, array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } diff --git a/src/Redmine/Api/TimeEntry.php b/src/Redmine/Api/TimeEntry.php index b070e87b..65b39ef4 100644 --- a/src/Redmine/Api/TimeEntry.php +++ b/src/Redmine/Api/TimeEntry.php @@ -68,7 +68,7 @@ public function all(array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } diff --git a/src/Redmine/Api/TimeEntryActivity.php b/src/Redmine/Api/TimeEntryActivity.php index 5036ac1a..5bd2a69c 100644 --- a/src/Redmine/Api/TimeEntryActivity.php +++ b/src/Redmine/Api/TimeEntryActivity.php @@ -87,7 +87,7 @@ public function all(array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } @@ -142,7 +142,7 @@ public function getIdByName($name) */ private function doListing(bool $forceUpdate): array { - if (empty($this->timeEntryActivities) || $forceUpdate) { + if ($this->timeEntryActivities === [] || $forceUpdate) { $this->timeEntryActivities = $this->list(); } diff --git a/src/Redmine/Api/Tracker.php b/src/Redmine/Api/Tracker.php index 8ff8bfee..36cdf415 100644 --- a/src/Redmine/Api/Tracker.php +++ b/src/Redmine/Api/Tracker.php @@ -91,7 +91,7 @@ public function all(array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } @@ -146,7 +146,7 @@ public function getIdByName($name) */ private function doListing(bool $forceUpdate): array { - if (empty($this->trackers) || $forceUpdate) { + if ($this->trackers === [] || $forceUpdate) { $this->trackers = $this->list(); } diff --git a/src/Redmine/Api/User.php b/src/Redmine/Api/User.php index be8f409e..a3d4639a 100644 --- a/src/Redmine/Api/User.php +++ b/src/Redmine/Api/User.php @@ -111,7 +111,7 @@ public function all(array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } @@ -329,7 +329,7 @@ public function remove($id) */ private function doListing(bool $forceUpdate, array $params): array { - if (empty($this->users) || $forceUpdate) { + if ($this->users === [] || $forceUpdate) { $this->users = $this->list($params); } diff --git a/src/Redmine/Api/Version.php b/src/Redmine/Api/Version.php index 0e2942e6..aa7f83e8 100644 --- a/src/Redmine/Api/Version.php +++ b/src/Redmine/Api/Version.php @@ -118,7 +118,7 @@ public function all($project, array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } @@ -345,7 +345,7 @@ public function remove($id) */ private function doListing($projectIdentifier, bool $forceUpdate, bool $reverse, array $params): array { - if (true === $forceUpdate || empty($this->versions)) { + if ($forceUpdate || $this->versions === []) { $this->versions = $this->listByProject($projectIdentifier, $params); } diff --git a/src/Redmine/Api/Wiki.php b/src/Redmine/Api/Wiki.php index e62d789c..24fba406 100644 --- a/src/Redmine/Api/Wiki.php +++ b/src/Redmine/Api/Wiki.php @@ -78,7 +78,7 @@ public function all($project, array $params = []) return false; } - if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) { + if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) { $e = $e->getPrevious(); } diff --git a/src/Redmine/Client/NativeCurlClient.php b/src/Redmine/Client/NativeCurlClient.php index 6dfb2c06..a98d0038 100644 --- a/src/Redmine/Client/NativeCurlClient.php +++ b/src/Redmine/Client/NativeCurlClient.php @@ -410,13 +410,11 @@ private function createHttpHeader(string $path, string $contentType = ''): array // @see https://www.redmine.org/projects/redmine/wiki/Rest_api#Authentication if (null === $this->password && !array_key_exists(strtolower('X-Redmine-API-Key'), $this->httpHeadersNames)) { $httpHeaders[] = 'X-Redmine-API-Key: ' . $this->apikeyOrUsername; - } else { - if (!array_key_exists(strtolower('Authorization'), $this->httpHeadersNames)) { - // Setting Header "Authorization: Basic base64" is the same as - // $this->setCurlOption(CURLOPT_USERPWD, "$username:$password") - // @see https://stackoverflow.com/a/26285941 - $httpHeaders[] = 'Authorization: Basic ' . base64_encode($this->apikeyOrUsername . ':' . $this->password); - } + } elseif (!array_key_exists(strtolower('Authorization'), $this->httpHeadersNames)) { + // Setting Header "Authorization: Basic base64" is the same as + // $this->setCurlOption(CURLOPT_USERPWD, "$username:$password") + // @see https://stackoverflow.com/a/26285941 + $httpHeaders[] = 'Authorization: Basic ' . base64_encode($this->apikeyOrUsername . ':' . $this->password); } // prepare custom headers diff --git a/src/Redmine/Client/Psr18Client.php b/src/Redmine/Client/Psr18Client.php index 454c807c..dc5c5ffa 100644 --- a/src/Redmine/Client/Psr18Client.php +++ b/src/Redmine/Client/Psr18Client.php @@ -201,7 +201,7 @@ public function getLastResponseStatusCode(): int { @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED); - if (null === $this->lastResponse) { + if (!$this->lastResponse instanceof \Psr\Http\Message\ResponseInterface) { return 0; } @@ -218,7 +218,7 @@ public function getLastResponseContentType(): string { @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED); - if (null === $this->lastResponse) { + if (!$this->lastResponse instanceof \Psr\Http\Message\ResponseInterface) { return ''; } @@ -235,7 +235,7 @@ public function getLastResponseBody(): string { @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED); - if (null === $this->lastResponse) { + if (!$this->lastResponse instanceof \Psr\Http\Message\ResponseInterface) { return ''; } diff --git a/src/Redmine/Exception/UnexpectedResponseException.php b/src/Redmine/Exception/UnexpectedResponseException.php index 71b0835b..75ed2a38 100644 --- a/src/Redmine/Exception/UnexpectedResponseException.php +++ b/src/Redmine/Exception/UnexpectedResponseException.php @@ -25,7 +25,7 @@ public static function create(Response $response, ?Throwable $prev = null): self { $e = new self( 'The Redmine server replied with an unexpected response.', - ($prev !== null) ? $prev->getCode() : 1, + ($prev instanceof \Throwable) ? $prev->getCode() : 1, $prev, ); diff --git a/src/Redmine/Http/HttpFactory.php b/src/Redmine/Http/HttpFactory.php index b7cc4478..7d9c6130 100644 --- a/src/Redmine/Http/HttpFactory.php +++ b/src/Redmine/Http/HttpFactory.php @@ -80,11 +80,11 @@ public function getContent(): string public static function makeJsonRequest(string $method, string $path, string $content = ''): Request { - return static::makeRequest($method, $path, 'application/json', $content); + return self::makeRequest($method, $path, 'application/json', $content); } public static function makeXmlRequest(string $method, string $path, string $content = ''): Request { - return static::makeRequest($method, $path, 'application/xml', $content); + return self::makeRequest($method, $path, 'application/xml', $content); } } diff --git a/src/Redmine/Serializer/PathSerializer.php b/src/Redmine/Serializer/PathSerializer.php index c0191472..9926b6fb 100644 --- a/src/Redmine/Serializer/PathSerializer.php +++ b/src/Redmine/Serializer/PathSerializer.php @@ -37,7 +37,7 @@ public function getPath(): string { $queryString = ''; - if (!empty($this->queryParams)) { + if ($this->queryParams !== []) { $queryString = '?' . \http_build_query($this->queryParams); // @see #154: replace every encoded array (`foo[0]=`, `foo[1]=`, etc with `foo[]=`) diff --git a/tests/Behat/Bootstrap/FeatureContext.php b/tests/Behat/Bootstrap/FeatureContext.php index 48af4c9f..8b015cbc 100644 --- a/tests/Behat/Bootstrap/FeatureContext.php +++ b/tests/Behat/Bootstrap/FeatureContext.php @@ -47,8 +47,8 @@ final class FeatureContext implements Context */ public static function prepare(BeforeSuiteScope $scope) { - static::$tracer = new BehatHookTracer(); - static::$tracer->hook($scope); + self::$tracer = new BehatHookTracer(); + self::$tracer->hook($scope); } /** @@ -56,7 +56,7 @@ public static function prepare(BeforeSuiteScope $scope) */ public static function reset(AfterScenarioScope $scope) { - static::$tracer->hook($scope); + self::$tracer->hook($scope); } /** @@ -64,8 +64,8 @@ public static function reset(AfterScenarioScope $scope) */ public static function clean(AfterSuiteScope $scope) { - static::$tracer->hook($scope); - static::$tracer = null; + self::$tracer->hook($scope); + self::$tracer = null; } private RedmineInstance $redmine; @@ -89,7 +89,7 @@ public function __construct(string $redmineVersion, string $rootPath) throw new InvalidArgumentException('Redmine ' . $redmineVersion . ' is not supported.'); } - $this->redmine = static::$tracer::getRedmineInstance($version, $rootPath); + $this->redmine = self::$tracer::getRedmineInstance($version, $rootPath); } /** diff --git a/tests/Fixtures/AssertingHttpClient.php b/tests/Fixtures/AssertingHttpClient.php index cbafd365..1267d746 100644 --- a/tests/Fixtures/AssertingHttpClient.php +++ b/tests/Fixtures/AssertingHttpClient.php @@ -62,7 +62,7 @@ private function assertRequestData( $responseContentType = $contentType; } - array_push($this->fifoStack, [ + $this->fifoStack[] = [ 'method' => $method, 'path' => $path, 'contentType' => $contentType, @@ -70,7 +70,7 @@ private function assertRequestData( 'responseCode' => $responseCode, 'responseContentType' => $responseContentType, 'responseContent' => $responseContent, - ]); + ]; } public function request(Request $request): Response diff --git a/tests/RedmineExtension/BehatHookTracer.php b/tests/RedmineExtension/BehatHookTracer.php index 04215442..75f422cf 100644 --- a/tests/RedmineExtension/BehatHookTracer.php +++ b/tests/RedmineExtension/BehatHookTracer.php @@ -24,45 +24,45 @@ final class BehatHookTracer implements InstanceRegistration public static function getRedmineInstance(RedmineVersion $redmineVersion, string $rootPath): RedmineInstance { - if (static::$tracer === null) { + if (!self::$tracer instanceof \Redmine\Tests\RedmineExtension\BehatHookTracer) { throw new RuntimeException('You can only get a Redmine instance while a Behat Suite is running.'); } - if (! array_key_exists($redmineVersion->asId(), static::$instances)) { - RedmineInstance::create(static::$tracer, $redmineVersion, $rootPath); + if (! array_key_exists($redmineVersion->asId(), self::$instances)) { + RedmineInstance::create(self::$tracer, $redmineVersion, $rootPath); } - return static::$instances[$redmineVersion->asId()]; + return self::$instances[$redmineVersion->asId()]; } public function registerInstance(RedmineInstance $instance): void { - static::$instances[$instance->getVersionId()] = $instance; + self::$instances[$instance->getVersionId()] = $instance; } public function deregisterInstance(RedmineInstance $instance): void { - unset(static::$instances[$instance->getVersionId()]); + unset(self::$instances[$instance->getVersionId()]); } public function hook(HookScope $event): void { if ($event instanceof BeforeSuiteScope) { - static::$tracer = $this; + self::$tracer = $this; } if ($event instanceof AfterScenarioScope) { - foreach (static::$instances as $instance) { + foreach (self::$instances as $instance) { $instance->reset($this); } } if ($event instanceof AfterSuiteScope) { - foreach (static::$instances as $instance) { + foreach (self::$instances as $instance) { $instance->shutdown($this); } - static::$tracer = null; + self::$tracer = null; } } }