Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPStan level 5 #376

Merged
merged 10 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 4
level: 5

paths:
- src/
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/kbsali/php-redmine-api/compare/v2.5.0...v2.x)

### Fixed

- Parameter types for IDs were fixed in API for attachments, groups, issues, project, users and versions.

## [v2.5.0](https://github.com/kbsali/php-redmine-api/compare/v2.4.0...v2.5.0) - 2024-02-05

### Added
Expand Down
10 changes: 5 additions & 5 deletions src/Redmine/Api/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ class Attachment extends AbstractApi
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Attachments
*
* @param string $id the attachment number
* @param int $id the attachment number
*
* @return array information about the attachment
*/
public function show($id)
{
return $this->get('/attachments/' . urlencode($id) . '.json');
return $this->get('/attachments/' . urlencode(strval($id)) . '.json');
}

/**
* Get attachment content as a binary file.
*
* @param string $id the attachment number
* @param int $id the attachment number
*
* @return string the attachment content
*/
public function download($id)
{
return $this->get('/attachments/download/' . urlencode($id), false);
return $this->get('/attachments/download/' . urlencode(strval($id)), false);
}

/**
Expand Down Expand Up @@ -70,6 +70,6 @@ public function upload($attachment, $params = [])
*/
public function remove($id)
{
return $this->delete('/attachments/' . $id . '.xml');
return $this->delete('/attachments/' . urlencode(strval($id)) . '.xml');
}
}
2 changes: 1 addition & 1 deletion src/Redmine/Api/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function update(int $id, array $params = [])
public function show($id, array $params = [])
{
return $this->get(
PathSerializer::create('/groups/' . urlencode($id) . '.json', $params)->getPath()
PathSerializer::create('/groups/' . urlencode(strval($id)) . '.json', $params)->getPath()
);
}

Expand Down
32 changes: 16 additions & 16 deletions src/Redmine/Api/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function all(array $params = [])
* available $params :
* include: fetch associated data (optional). Possible values: children, attachments, relations, changesets and journals
*
* @param string $id the issue id
* @param int $id the issue id
* @param array $params extra associated data
*
* @return array information about the issue
Expand All @@ -141,7 +141,7 @@ public function show($id, array $params = [])
}

return $this->get(
PathSerializer::create('/issues/' . urlencode($id) . '.json', $params)->getPath()
PathSerializer::create('/issues/' . urlencode(strval($id)) . '.json', $params)->getPath()
);
}

Expand Down Expand Up @@ -186,7 +186,7 @@ public function create(array $params = [])
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Updating-an-issue
*
* @param string $id the issue number
* @param int $id the issue number
*
* @return string|SimpleXMLElement|false
*/
Expand All @@ -213,34 +213,34 @@ public function update($id, array $params)
}

return $this->put(
'/issues/' . $id . '.xml',
'/issues/' . urlencode(strval($id)) . '.xml',
XmlSerializer::createFromArray(['issue' => $sanitizedParams])->getEncoded()
);
}

/**
* @param int $id
* @param string $watcherUserId
* @param int $id
* @param int $watcherUserId
*
* @return false|string
*/
public function addWatcher($id, $watcherUserId)
{
return $this->post(
'/issues/' . $id . '/watchers.xml',
XmlSerializer::createFromArray(['user_id' => $watcherUserId])->getEncoded()
'/issues/' . urlencode(strval($id)) . '/watchers.xml',
XmlSerializer::createFromArray(['user_id' => urlencode(strval($watcherUserId))])->getEncoded()
);
}

/**
* @param int $id
* @param string $watcherUserId
* @param int $id
* @param int $watcherUserId
*
* @return false|\SimpleXMLElement|string
*/
public function removeWatcher($id, $watcherUserId)
{
return $this->delete('/issues/' . $id . '/watchers/' . $watcherUserId . '.xml');
return $this->delete('/issues/' . urlencode(strval($id)) . '/watchers/' . urlencode(strval($watcherUserId)) . '.xml');
}

/**
Expand Down Expand Up @@ -330,7 +330,7 @@ private function cleanParams(array $params = [])
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Updating-an-issue
*
* @param string $id the issue number
* @param int $id the issue number
* @param array $attachment ['token' => '...', 'filename' => '...', 'content_type' => '...']
*
* @return bool|string
Expand All @@ -345,7 +345,7 @@ public function attach($id, array $attachment)
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Updating-an-issue
*
* @param string $id the issue number
* @param int $id the issue number
* @param array $attachments [
* ['token' => '...', 'filename' => '...', 'content_type' => '...'],
* ['token' => '...', 'filename' => '...', 'content_type' => '...']
Expand All @@ -361,21 +361,21 @@ public function attachMany($id, array $attachments)
];

return $this->put(
'/issues/' . $id . '.json',
'/issues/' . urlencode(strval($id)) . '.json',
JsonSerializer::createFromArray(['issue' => $params])->getEncoded()
);
}

/**
* Remove a issue by issue number.
*
* @param string $id the issue number
* @param int $id the issue number
*
* @return false|\SimpleXMLElement|string
*/
public function remove($id)
{
return $this->delete('/issues/' . $id . '.xml');
return $this->delete('/issues/' . urlencode(strval($id)) . '.xml');
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Redmine/Api/IssueCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ public function getIdByName($project, $name)
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_IssueCategories#GET-2
*
* @param string $id the issue category id
* @param int $id the issue category id
*
* @return array information about the category
*/
public function show($id)
{
return $this->get('/issue_categories/' . urlencode($id) . '.json');
return $this->get('/issue_categories/' . urlencode(strval($id)) . '.json');
}

/**
Expand Down Expand Up @@ -171,7 +171,7 @@ public function create($project, array $params = [])
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_IssueCategories#PUT
*
* @param string $id the issue category id
* @param int $id the issue category id
*
* @return string|false
*/
Expand All @@ -184,7 +184,7 @@ public function update($id, array $params)
$params = $this->sanitizeParams($defaults, $params);

return $this->put(
'/issue_categories/' . $id . '.xml',
'/issue_categories/' . urlencode(strval($id)) . '.xml',
XmlSerializer::createFromArray(['issue_category' => $params])->getEncoded()
);
}
Expand All @@ -204,7 +204,7 @@ public function update($id, array $params)
public function remove($id, array $params = [])
{
return $this->delete(
PathSerializer::create('/issue_categories/' . $id . '.xml', $params)->getPath()
PathSerializer::create('/issue_categories/' . urlencode(strval($id)) . '.xml', $params)->getPath()
);
}
}
4 changes: 2 additions & 2 deletions src/Redmine/Api/IssueRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function all($issueId, array $params = [])
*/
public function show($id)
{
$ret = $this->get('/relations/' . urlencode($id) . '.json');
$ret = $this->get('/relations/' . urlencode(strval($id)) . '.json');
if (false === $ret) {
return [];
}
Expand Down Expand Up @@ -126,7 +126,7 @@ public function create($issueId, array $params = [])
$params = $this->sanitizeParams($defaults, $params);

$response = $this->post(
'/issues/' . urlencode($issueId) . '/relations.json',
'/issues/' . urlencode(strval($issueId)) . '/relations.json',
JsonSerializer::createFromArray(['relation' => $params])->getEncoded()
);

Expand Down
12 changes: 6 additions & 6 deletions src/Redmine/Api/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ public function getIdByName($name, array $params = [])
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Projects#Showing-a-project
*
* @param string $id the project id
* @param array $params available parameters:
* include: fetch associated data (optional). Possible values: trackers, issue_categories, enabled_modules (since 2.6.0)
* @param string|int $id project id or identifier
* @param array $params available parameters:
* include: fetch associated data (optional). Possible values: trackers, issue_categories, enabled_modules (since 2.6.0)
*
* @return array information about the project
*/
Expand All @@ -133,7 +133,7 @@ public function show($id, array $params = [])
}

return $this->get(
PathSerializer::create('/projects/' . urlencode($id) . '.json', $params)->getPath()
PathSerializer::create('/projects/' . urlencode(strval($id)) . '.json', $params)->getPath()
);
}

Expand Down Expand Up @@ -175,7 +175,7 @@ public function create(array $params = [])
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Projects
*
* @param string $id the project id
* @param string|int $id project id or identifier
*
* @return string|false
*/
Expand All @@ -190,7 +190,7 @@ public function update($id, array $params)
$params = $this->sanitizeParams($defaults, $params);

return $this->put(
'/projects/' . $id . '.xml',
'/projects/' . urlencode(strval($id)) . '.xml',
XmlSerializer::createFromArray(['project' => $params])->getEncoded()
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Redmine/Api/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ public function listing($forceUpdate = false)
*/
public function show($id)
{
return $this->get('/roles/' . urlencode($id) . '.json');
return $this->get('/roles/' . urlencode(strval($id)) . '.json');
}
}
4 changes: 2 additions & 2 deletions src/Redmine/Api/TimeEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ public function all(array $params = [])
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_TimeEntries
*
* @param string $id the time entry id
* @param int $id the time entry id
*
* @return array information about the time entry
*/
public function show($id)
{
return $this->get('/time_entries/' . urlencode($id) . '.json');
return $this->get('/time_entries/' . urlencode(strval($id)) . '.json');
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Redmine/Api/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public function getIdByUsername($username, array $params = [])
* - api_key: the API key of the user, visible for admins and for yourself (added in 2.3.0)
* - status: a numeric id representing the status of the user, visible for admins only (added in 2.4.0)
*
* @param string $id the user id
* @param array $params extra associated data
* @param int|string $id the user id or `current` for retrieving the user whose credentials are used
* @param array $params extra associated data
*
* @return array information about the user
*/
Expand All @@ -159,7 +159,7 @@ public function show($id, array $params = [])
$params['include'] = implode(',', $params['include']);

return $this->get(
PathSerializer::create('/users/' . urlencode($id) . '.json', $params)->getPath()
PathSerializer::create('/users/' . urlencode(strval($id)) . '.json', $params)->getPath()
);
}

Expand Down Expand Up @@ -205,7 +205,7 @@ public function create(array $params = [])
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Users#PUT
*
* @param string $id the user id
* @param int $id the user id
*
* @return string|false
*/
Expand All @@ -222,7 +222,7 @@ public function update($id, array $params)
$params = $this->sanitizeParams($defaults, $params);

return $this->put(
'/users/' . $id . '.xml',
'/users/' . urlencode(strval($id)) . '.xml',
XmlSerializer::createFromArray(['user' => $params])->getEncoded()
);
}
Expand Down
Loading
Loading