Skip to content

Commit

Permalink
Reach PHPStan level 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Sep 21, 2023
1 parent ab055d6 commit 23c82bb
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 2
level: 3

paths:
- src/
Expand Down
2 changes: 1 addition & 1 deletion src/Redmine/Api/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function listing($forceUpdate = false)
*
* @throws MissingParameterException Missing mandatory parameters
*
* @return \SimpleXMLElement
* @return string|false
*/
public function create(array $params = [])
{
Expand Down
9 changes: 8 additions & 1 deletion src/Redmine/Api/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function show($id, array $params = [])
*
* @param array $params the new issue data
*
* @return \SimpleXMLElement
* @return string|false
*/
public function create(array $params = [])
{
Expand Down Expand Up @@ -174,6 +174,7 @@ public function removeWatcher($id, $watcherUserId)
*/
public function setIssueStatus($id, $status)
{
/** @var IssueStatus */
$api = $this->client->getApi('issue_status');

return $this->update($id, [
Expand Down Expand Up @@ -204,31 +205,37 @@ public function addNoteToIssue($id, $note, $privateNote = false)
private function cleanParams(array $params = [])
{
if (isset($params['project'])) {
/** @var Project */
$apiProject = $this->client->getApi('project');
$params['project_id'] = $apiProject->getIdByName($params['project']);
unset($params['project']);
if (isset($params['category'])) {
/** @var IssueCategory */
$apiIssueCategory = $this->client->getApi('issue_category');
$params['category_id'] = $apiIssueCategory->getIdByName($params['project_id'], $params['category']);
unset($params['category']);
}
}
if (isset($params['status'])) {
/** @var IssueStatus */
$apiIssueStatus = $this->client->getApi('issue_status');
$params['status_id'] = $apiIssueStatus->getIdByName($params['status']);
unset($params['status']);
}
if (isset($params['tracker'])) {
/** @var Tracker */
$apiTracker = $this->client->getApi('tracker');
$params['tracker_id'] = $apiTracker->getIdByName($params['tracker']);
unset($params['tracker']);
}
if (isset($params['assigned_to'])) {
/** @var User */
$apiUser = $this->client->getApi('user');
$params['assigned_to_id'] = $apiUser->getIdByUsername($params['assigned_to']);
unset($params['assigned_to']);
}
if (isset($params['author'])) {
/** @var User */
$apiUser = $this->client->getApi('user');
$params['author_id'] = $apiUser->getIdByUsername($params['author']);
unset($params['author']);
Expand Down
2 changes: 1 addition & 1 deletion src/Redmine/Api/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function removeMember($projectId, $userId, array $params = [])
{
$memberships = $this->all($projectId, $params);
if (!isset($memberships['memberships']) || !is_array($memberships['memberships'])) {
return;
return false;
}
$removed = false;
foreach ($memberships['memberships'] as $membership) {
Expand Down
2 changes: 1 addition & 1 deletion src/Redmine/Api/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function show($id, array $params = [])
*
* @throws MissingParameterException
*
* @return \SimpleXMLElement
* @return string|false
*/
public function create(array $params = [])
{
Expand Down
3 changes: 1 addition & 2 deletions src/Redmine/Client/NativeCurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Redmine\Client;

use Redmine\Api;
use Redmine\Exception\ClientException;

/**
Expand Down Expand Up @@ -246,7 +245,7 @@ private function request(string $method, string $path, string $body = ''): bool
/**
* Prepare the request by setting the cURL options.
*
* @return resource a cURL handle on success, <b>FALSE</b> on errors
* @return resource|\CurlHandle a cURL handle on success, <b>FALSE</b> on errors
*/
private function createCurl(string $method, string $path, string $body = '')

Check failure on line 250 in src/Redmine/Client/NativeCurlClient.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 7.4 on ubuntu-latest)

Method Redmine\Client\NativeCurlClient::createCurl() has invalid return type CurlHandle.
{
Expand Down
6 changes: 5 additions & 1 deletion tests/Integration/GroupXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function setup(): void

public function testCreateBlank()
{
/** @var \Redmine\Api\Group */
$api = $this->client->getApi('group');
$this->assertInstanceOf('Redmine\Api\Group', $api);

Expand All @@ -34,7 +35,9 @@ public function testCreateBlank()

public function testCreateComplex()
{
$res = $this->client->getApi('group')->create([
/** @var \Redmine\Api\Group */
$api = $this->client->getApi('group');
$res = $api->create([
'name' => 'Developers',
'user_ids' => [3, 5],
]);
Expand All @@ -54,6 +57,7 @@ public function testCreateComplex()

public function testUpdateNotImplemented()
{
/** @var \Redmine\Api\Group */
$api = $this->client->getApi('group');
$this->assertInstanceOf('Redmine\Api\Group', $api);

Expand Down
3 changes: 3 additions & 0 deletions tests/Integration/IssueCategoryXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function setup(): void

public function testCreateBlank()
{
/** @var \Redmine\Api\IssueCategory */
$api = $this->client->getApi('issue_category');
$this->assertInstanceOf('Redmine\Api\IssueCategory', $api);

Expand All @@ -33,6 +34,7 @@ public function testCreateBlank()

public function testCreateComplex()
{
/** @var \Redmine\Api\IssueCategory */
$api = $this->client->getApi('issue_category');
$res = $api->create('otherProject', [
'name' => 'test category',
Expand All @@ -48,6 +50,7 @@ public function testCreateComplex()

public function testUpdate()
{
/** @var \Redmine\Api\IssueCategory */
$api = $this->client->getApi('issue_category');
$res = $api->update(1, [
'name' => 'new category name',
Expand Down
6 changes: 6 additions & 0 deletions tests/Integration/IssueXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function setup(): void

public function testCreateBlank()
{
/** @var \Redmine\Api\Issue */
$api = $this->client->getApi('issue');
$this->assertInstanceOf('Redmine\Api\Issue', $api);

Expand All @@ -34,6 +35,7 @@ public function testCreateBlank()

public function testCreateComplexWithUpload()
{
/** @var \Redmine\Api\Issue */
$api = $this->client->getApi('issue');
$res = $api->create([
'project_id' => 'myproject',
Expand Down Expand Up @@ -69,6 +71,7 @@ public function testCreateComplexWithUpload()

public function testCreateComplex()
{
/** @var \Redmine\Api\Issue */
$api = $this->client->getApi('issue');
$res = $api->create([
'project_id' => 'test',
Expand Down Expand Up @@ -113,6 +116,7 @@ public function testCreateComplex()

public function testCreateComplexWithLineBreakInDescription()
{
/** @var \Redmine\Api\Issue */
$api = $this->client->getApi('issue');
$res = $api->create([
'project_id' => 'test',
Expand Down Expand Up @@ -158,6 +162,7 @@ public function testCreateComplexWithLineBreakInDescription()

public function testUpdateIssue()
{
/** @var \Redmine\Api\Issue */
$api = $this->client->getApi('issue');
$res = $api->update(1, [
'subject' => 'test note (xml) 1',
Expand Down Expand Up @@ -187,6 +192,7 @@ public function testUpdateIssue()

public function testAddNoteToIssue()
{
/** @var \Redmine\Api\Issue */
$api = $this->client->getApi('issue');
$res = $api->addNoteToIssue(1, 'some comment');
$res = json_decode($res, true);
Expand Down
3 changes: 3 additions & 0 deletions tests/Integration/MembershipXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function setup(): void

public function testCreateBlank()
{
/** @var \Redmine\Api\Membership */
$api = $this->client->getApi('membership');
$this->assertInstanceOf('Redmine\Api\Membership', $api);

Expand All @@ -33,6 +34,7 @@ public function testCreateBlank()

public function testCreateComplex()
{
/** @var \Redmine\Api\Membership */
$api = $this->client->getApi('membership');
$res = $api->create('otherProject', [
'user_id' => 1,
Expand All @@ -53,6 +55,7 @@ public function testCreateComplex()

public function testUpdate()
{
/** @var \Redmine\Api\Membership */
$api = $this->client->getApi('membership');
$res = $api->update(1, [
'role_ids' => [1, 2],
Expand Down
4 changes: 4 additions & 0 deletions tests/Integration/ProjectXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function setup(): void

public function testCreateBlank()
{
/** @var \Redmine\Api\Project */
$api = $this->client->getApi('project');
$this->assertInstanceOf('Redmine\Api\Project', $api);

Expand All @@ -33,6 +34,7 @@ public function testCreateBlank()

public function testCreateComplex()
{
/** @var \Redmine\Api\Project */
$api = $this->client->getApi('project');
$res = $api->create([
'name' => 'some name',
Expand Down Expand Up @@ -67,6 +69,7 @@ public function testCreateComplex()

public function testCreateComplexWithTrackerIds()
{
/** @var \Redmine\Api\Project */
$api = $this->client->getApi('project');
$res = $api->create([
'name' => 'some name',
Expand All @@ -92,6 +95,7 @@ public function testCreateComplexWithTrackerIds()

public function testUpdate()
{
/** @var \Redmine\Api\Project */
$api = $this->client->getApi('project');
$res = $api->update(1, [
'name' => 'different name',
Expand Down
Loading

0 comments on commit 23c82bb

Please sign in to comment.