Skip to content

Commit

Permalink
Merge pull request #425 from Art4/phpstan-level-6
Browse files Browse the repository at this point in the history
Phpstan level 6
  • Loading branch information
Art4 authored Oct 8, 2024
2 parents 5dbf37a + 7871ae1 commit acb5589
Show file tree
Hide file tree
Showing 164 changed files with 894 additions and 680 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
return $config->setRules([
'@PER-CS2.0' => true,
'@PER-CS2.0:risky' => true,
'@PHPUnit100Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'linebreak_after_opening_tag' => true,
'ordered_imports' => true,
Expand Down
16 changes: 15 additions & 1 deletion .phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 5
level: 6

paths:
- src/
Expand All @@ -9,3 +9,17 @@ parameters:
- vendor

treatPhpDocTypesAsCertain: false

ignoreErrors:
-
# Ignore missing or imprecise parameter types for methods in tests
message: '(^Method .+ has parameter .+ with no.* type specified.*\.$)'
path: tests
-
# Ignore imprecise return types for methods in tests
message: '(^Method .+ return type has no.* type specified.+\.$)'
path: tests
-
# Ignore missing return types for methods in tests
message: '(^Method .+ has no return type specified\.$)'
path: tests
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
Loading

0 comments on commit acb5589

Please sign in to comment.