Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix all PHPStan level 6 errors in src folder
  • Loading branch information
Art4 committed Oct 8, 2024
commit cfcaaa0a911c546a2dc3342f5ae977a87ee39fd7
25 changes: 15 additions & 10 deletions src/Redmine/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function lastCallFailed()
* @param string $path
* @param bool $decodeIfJson
*
* @return string|array|SimpleXMLElement|false
* @return string|array<mixed>|SimpleXMLElement|false
*/
protected function get($path, $decodeIfJson = true)
{
Expand Down Expand Up @@ -245,7 +245,10 @@ protected function isNotNull($var)
}

/**
* @return array
* @param array<mixed> $defaults
* @param array<mixed> $params
*
* @return array<mixed>
*/
protected function sanitizeParams(array $defaults, array $params)
{
Expand All @@ -262,10 +265,10 @@ protected function sanitizeParams(array $defaults, array $params)
* @deprecated v2.2.0 Use `retrieveData()` instead
* @see AbstractApi::retrieveData()
*
* @param string $endpoint API end point
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
* @param string $endpoint API end point
* @param array<mixed> $params optional parameters to be passed to the api (offset, limit, ...)
*
* @return array|string|false elements found or error message or false
* @return array<mixed>|string|false elements found or error message or false
*/
protected function retrieveAll($endpoint, array $params = [])
{
Expand All @@ -288,12 +291,12 @@ protected function retrieveAll($endpoint, array $params = [])
* Retrieves as many elements as you want of a given endpoint (even if the
* total number of elements is greater than 100).
*
* @param string $endpoint API end point
* @param array $params optional query parameters to be passed to the api (offset, limit, ...)
* @param string $endpoint API end point
* @param array<mixed> $params optional query parameters to be passed to the api (offset, limit, ...)
*
* @throws SerializerException if response body could not be converted into array
*
* @return array elements found
* @return array<mixed> elements found
*/
protected function retrieveData(string $endpoint, array $params = []): array
{
Expand Down Expand Up @@ -364,7 +367,7 @@ protected function retrieveData(string $endpoint, array $params = []): array
* @see \Redmine\Serializer\XmlSerializer::createFromArray()
*
* @param SimpleXMLElement $xml XML Element the custom fields are attached to
* @param array $fields array of fields to attach, each field needs name, id and value set
* @param array<mixed> $fields array of fields to attach, each field needs name, id and value set
*
* @return SimpleXMLElement $xml
*
Expand Down Expand Up @@ -411,6 +414,8 @@ protected function attachCustomFieldXML(SimpleXMLElement $xml, array $fields)
* returns the last response body as array.
*
* @throws SerializerException if response body could not be converted into array
*
* @return array<mixed>
*/
private function getResponseAsArray(Response $response): array
{
Expand All @@ -435,7 +440,7 @@ private function getResponseAsArray(Response $response): array
private function handleClient(Client $client): HttpClient
{
return new class ($client) implements HttpClient {
private $client;
private Client $client;

public function __construct(Client $client)
{
Expand Down
15 changes: 7 additions & 8 deletions src/Redmine/Api/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Redmine\Http\HttpFactory;
use Redmine\Serializer\JsonSerializer;
use Redmine\Serializer\PathSerializer;
use SimpleXMLElement;

/**
* Attachment details.
Expand All @@ -25,7 +24,7 @@ class Attachment extends AbstractApi
*
* @param int $id the attachment number
*
* @return array|false|string information about the attachment as array or false|string on error
* @return array<mixed>|false|string information about the attachment as array or false|string on error
*/
public function show($id)
{
Expand All @@ -52,10 +51,10 @@ public function show($id)
*
* @see https://www.redmine.org/projects/redmine/wiki/Rest_Attachments#PATCH
*
* @param int $id the attachment id
* @param array $params available $params:
* - filename: filename of the attachment
* - description: new description of the attachment
* @param int $id the attachment id
* @param array<mixed> $params available $params:
* - filename: filename of the attachment
* - description: new description of the attachment
*
* @throws SerializerException if $params contains invalid values
* @throws UnexpectedResponseException if the Redmine server delivers an unexpected response
Expand Down Expand Up @@ -108,8 +107,8 @@ public function download($id)
* available $params :
* - filename: filename of the attachment
*
* @param string $attachment the attachment content
* @param array $params optional parameters to be passed to the api
* @param string $attachment the attachment content
* @param array<mixed> $params optional parameters to be passed to the api
*
* @return string information about the attachment
*/
Expand Down
31 changes: 21 additions & 10 deletions src/Redmine/Api/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@
*/
class CustomField extends AbstractApi
{
/**
* @var array<mixed>
*/
private $customFields = [];

/**
* @var null|array<int,string>
*/
private $customFieldNames = null;

/**
* List custom fields.
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_CustomFields#GET
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
* @param array<mixed> $params optional parameters to be passed to the api (offset, limit, ...)
*
* @throws UnexpectedResponseException if response body could not be converted into array
*
* @return array list of custom fields found
* @return array<mixed> list of custom fields found
*/
final public function list(array $params = []): array
{
Expand Down Expand Up @@ -71,9 +77,9 @@ final public function listNames(): array
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_CustomFields#GET
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
* @param array<mixed> $params optional parameters to be passed to the api (offset, limit, ...)
*
* @return array|string|false list of custom fields found or error message or false
* @return array<mixed>|string|false list of custom fields found or error message or false
*/
public function all(array $params = [])
{
Expand Down Expand Up @@ -102,10 +108,10 @@ public function all(array $params = [])
* @deprecated v2.7.0 Use listNames() instead.
* @see CustomField::listNames()
*
* @param bool $forceUpdate to force the update of the custom fields var
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
* @param bool $forceUpdate to force the update of the custom fields var
* @param array<mixed> $params optional parameters to be passed to the api (offset, limit, ...)
*
* @return array list of custom fields (id => name)
* @return array<string,int> list of custom fields (name => id)
*/
public function listing($forceUpdate = false, array $params = [])
{
Expand All @@ -120,8 +126,8 @@ public function listing($forceUpdate = false, array $params = [])
* @deprecated v2.7.0 Use listNames() instead.
* @see CustomField::listNames()
*
* @param string|int $name customer field name
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
* @param string|int $name customer field name
* @param array<mixed> $params optional parameters to be passed to the api (offset, limit, ...)
*
* @return int|false
*/
Expand All @@ -138,7 +144,12 @@ public function getIdByName($name, array $params = [])
return $arr[(string) $name];
}

private function doListing(bool $forceUpdate, array $params)
/**
* @param array<mixed> $params
*
* @return array<mixed>
*/
private function doListing(bool $forceUpdate, array $params): array
{
if (empty($this->customFields) || $forceUpdate) {
$this->customFields = $this->list($params);
Expand Down
27 changes: 17 additions & 10 deletions src/Redmine/Api/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,26 @@
*/
class Group extends AbstractApi
{
/**
* @var array<mixed>
*/
private $groups = [];

/**
* @var null|array<int,string>
*/
private $groupNames = null;

/**
* List groups.
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Groups#GET
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
* @param array<mixed> $params optional parameters to be passed to the api (offset, limit, ...)
*
* @throws UnexpectedResponseException if response body could not be converted into array
*
* @return array list of groups found
* @return array<mixed> list of groups found
*/
final public function list(array $params = []): array
{
Expand Down Expand Up @@ -73,9 +79,9 @@ final public function listNames(): array
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Groups#GET
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
* @param array<mixed> $params optional parameters to be passed to the api (offset, limit, ...)
*
* @return array|string|false list of groups found or error message or false
* @return array<mixed>|string|false list of groups found or error message or false
*/
public function all(array $params = [])
{
Expand Down Expand Up @@ -106,7 +112,7 @@ public function all(array $params = [])
*
* @param bool $forceUpdate to force the update of the groups var
*
* @return array list of groups (id => name)
* @return array<string,int> list of groups (name => id)
*/
public function listing($forceUpdate = false)
{
Expand All @@ -128,7 +134,7 @@ public function listing($forceUpdate = false)
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Groups#POST
*
* @param array $params the new group data
* @param array<mixed> $params the new group data
*
* @throws MissingParameterException Missing mandatory parameters
*
Expand Down Expand Up @@ -170,7 +176,8 @@ public function create(array $params = [])
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Groups#PUT
*
* @param int $id the group id
* @param int $id the group id
* @param array<mixed> $params
*
* @return string empty string
*/
Expand Down Expand Up @@ -198,10 +205,10 @@ public function update(int $id, array $params = [])
* available $params :
* - include: a coma separated list of associations to include in the response: users,memberships
*
* @param int $id the group id
* @param array $params params to pass to url
* @param int $id the group id
* @param array<mixed> $params params to pass to url
*
* @return array|false|string information about the group as array or false|string on error
* @return array<mixed>|false|string information about the group as array or false|string on error
*/
public function show($id, array $params = [])
{
Expand Down
39 changes: 21 additions & 18 deletions src/Redmine/Api/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ class Issue extends AbstractApi
* - cf_x: get issues with the given value for custom field with an ID of x. (Custom field must have 'used as a filter' checked.)
* - query_id : id of the previously saved query
*
* @param array $params the additional parameters (cf available $params above)
* @param array<mixed> $params the additional parameters (cf available $params above)
*
* @throws UnexpectedResponseException if response body could not be converted into array
*
* @return array list of issues found
* @return array<mixed> list of issues found
*/
final public function list(array $params = []): array
{
Expand Down Expand Up @@ -120,9 +120,9 @@ final public function list(array $params = []): array
* - cf_x: get issues with the given value for custom field with an ID of x. (Custom field must have 'used as a filter' checked.)
* - query_id : id of the previously saved query
*
* @param array $params the additional parameters (cf available $params above)
* @param array<mixed> $params the additional parameters (cf available $params above)
*
* @return array|string|false list of issues found or error message or false
* @return array<mixed>|string|false list of issues found or error message or false
*/
public function all(array $params = [])
{
Expand Down Expand Up @@ -150,10 +150,10 @@ public function all(array $params = [])
* available $params :
* include: fetch associated data (optional). Possible values: children, attachments, relations, changesets and journals
*
* @param int $id the issue id
* @param array $params extra associated data
* @param int $id the issue id
* @param array<mixed> $params extra associated data
*
* @return array|false|string information about the issue as array or false|string on error
* @return array<mixed>|false|string information about the issue as array or false|string on error
*/
public function show($id, array $params = [])
{
Expand Down Expand Up @@ -185,7 +185,7 @@ public function show($id, array $params = [])
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Creating-an-issue
*
* @param array $params the new issue data
* @param array<mixed> $params the new issue data
*
* @return string|SimpleXMLElement|false
*/
Expand Down Expand Up @@ -234,7 +234,8 @@ public function create(array $params = [])
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Updating-an-issue
*
* @param int $id the issue number
* @param int $id the issue number
* @param array<mixed> $params
*
* @return string|SimpleXMLElement|false
*/
Expand Down Expand Up @@ -341,9 +342,11 @@ public function addNoteToIssue($id, $note, $privateNote = false)
/**
* Transforms literal identifiers to integer ids.
*
* @return array
* @param array<mixed> $params
*
* @return array<mixed>
*/
private function cleanParams(array $params = [])
private function cleanParams(array $params = []): array
{
if (isset($params['project'])) {
$projectApi = $this->getProjectApi();
Expand Down Expand Up @@ -420,8 +423,8 @@ private function cleanParams(array $params = [])
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Updating-an-issue
*
* @param int $id the issue number
* @param array $attachment ['token' => '...', 'filename' => '...', 'content_type' => '...']
* @param int $id the issue number
* @param array<mixed> $attachment ['token' => '...', 'filename' => '...', 'content_type' => '...']
*
* @return bool|string
*/
Expand All @@ -435,11 +438,11 @@ public function attach($id, array $attachment)
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Updating-an-issue
*
* @param int $id the issue number
* @param array $attachments [
* ['token' => '...', 'filename' => '...', 'content_type' => '...'],
* ['token' => '...', 'filename' => '...', 'content_type' => '...']
* ]
* @param int $id the issue number
* @param array<mixed> $attachments [
* ['token' => '...', 'filename' => '...', 'content_type' => '...'],
* ['token' => '...', 'filename' => '...', 'content_type' => '...']
* ]
*
* @return bool|string
*/
Expand Down
Loading