Skip to content

Commit acb5589

Browse files
authored
Merge pull request #425 from Art4/phpstan-level-6
Phpstan level 6
2 parents 5dbf37a + 7871ae1 commit acb5589

File tree

164 files changed

+894
-680
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+894
-680
lines changed

.php-cs-fixer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
return $config->setRules([
1212
'@PER-CS2.0' => true,
1313
'@PER-CS2.0:risky' => true,
14+
'@PHPUnit100Migration:risky' => true,
1415
'array_syntax' => ['syntax' => 'short'],
1516
'linebreak_after_opening_tag' => true,
1617
'ordered_imports' => true,

.phpstan.neon

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 5
2+
level: 6
33

44
paths:
55
- src/
@@ -9,3 +9,17 @@ parameters:
99
- vendor
1010

1111
treatPhpDocTypesAsCertain: false
12+
13+
ignoreErrors:
14+
-
15+
# Ignore missing or imprecise parameter types for methods in tests
16+
message: '(^Method .+ has parameter .+ with no.* type specified.*\.$)'
17+
path: tests
18+
-
19+
# Ignore imprecise return types for methods in tests
20+
message: '(^Method .+ return type has no.* type specified.+\.$)'
21+
path: tests
22+
-
23+
# Ignore missing return types for methods in tests
24+
message: '(^Method .+ has no return type specified\.$)'
25+
path: tests

src/Redmine/Api/AbstractApi.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function lastCallFailed()
108108
* @param string $path
109109
* @param bool $decodeIfJson
110110
*
111-
* @return string|array|SimpleXMLElement|false
111+
* @return string|array<mixed>|SimpleXMLElement|false
112112
*/
113113
protected function get($path, $decodeIfJson = true)
114114
{
@@ -245,7 +245,10 @@ protected function isNotNull($var)
245245
}
246246

247247
/**
248-
* @return array
248+
* @param array<mixed> $defaults
249+
* @param array<mixed> $params
250+
*
251+
* @return array<mixed>
249252
*/
250253
protected function sanitizeParams(array $defaults, array $params)
251254
{
@@ -262,10 +265,10 @@ protected function sanitizeParams(array $defaults, array $params)
262265
* @deprecated v2.2.0 Use `retrieveData()` instead
263266
* @see AbstractApi::retrieveData()
264267
*
265-
* @param string $endpoint API end point
266-
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
268+
* @param string $endpoint API end point
269+
* @param array<mixed> $params optional parameters to be passed to the api (offset, limit, ...)
267270
*
268-
* @return array|string|false elements found or error message or false
271+
* @return array<mixed>|string|false elements found or error message or false
269272
*/
270273
protected function retrieveAll($endpoint, array $params = [])
271274
{
@@ -288,12 +291,12 @@ protected function retrieveAll($endpoint, array $params = [])
288291
* Retrieves as many elements as you want of a given endpoint (even if the
289292
* total number of elements is greater than 100).
290293
*
291-
* @param string $endpoint API end point
292-
* @param array $params optional query parameters to be passed to the api (offset, limit, ...)
294+
* @param string $endpoint API end point
295+
* @param array<mixed> $params optional query parameters to be passed to the api (offset, limit, ...)
293296
*
294297
* @throws SerializerException if response body could not be converted into array
295298
*
296-
* @return array elements found
299+
* @return array<mixed> elements found
297300
*/
298301
protected function retrieveData(string $endpoint, array $params = []): array
299302
{
@@ -364,7 +367,7 @@ protected function retrieveData(string $endpoint, array $params = []): array
364367
* @see \Redmine\Serializer\XmlSerializer::createFromArray()
365368
*
366369
* @param SimpleXMLElement $xml XML Element the custom fields are attached to
367-
* @param array $fields array of fields to attach, each field needs name, id and value set
370+
* @param array<mixed> $fields array of fields to attach, each field needs name, id and value set
368371
*
369372
* @return SimpleXMLElement $xml
370373
*
@@ -411,6 +414,8 @@ protected function attachCustomFieldXML(SimpleXMLElement $xml, array $fields)
411414
* returns the last response body as array.
412415
*
413416
* @throws SerializerException if response body could not be converted into array
417+
*
418+
* @return array<mixed>
414419
*/
415420
private function getResponseAsArray(Response $response): array
416421
{
@@ -435,7 +440,7 @@ private function getResponseAsArray(Response $response): array
435440
private function handleClient(Client $client): HttpClient
436441
{
437442
return new class ($client) implements HttpClient {
438-
private $client;
443+
private Client $client;
439444

440445
public function __construct(Client $client)
441446
{

src/Redmine/Api/Attachment.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Redmine\Http\HttpFactory;
88
use Redmine\Serializer\JsonSerializer;
99
use Redmine\Serializer\PathSerializer;
10-
use SimpleXMLElement;
1110

1211
/**
1312
* Attachment details.
@@ -25,7 +24,7 @@ class Attachment extends AbstractApi
2524
*
2625
* @param int $id the attachment number
2726
*
28-
* @return array|false|string information about the attachment as array or false|string on error
27+
* @return array<mixed>|false|string information about the attachment as array or false|string on error
2928
*/
3029
public function show($id)
3130
{
@@ -52,10 +51,10 @@ public function show($id)
5251
*
5352
* @see https://www.redmine.org/projects/redmine/wiki/Rest_Attachments#PATCH
5453
*
55-
* @param int $id the attachment id
56-
* @param array $params available $params:
57-
* - filename: filename of the attachment
58-
* - description: new description of the attachment
54+
* @param int $id the attachment id
55+
* @param array<mixed> $params available $params:
56+
* - filename: filename of the attachment
57+
* - description: new description of the attachment
5958
*
6059
* @throws SerializerException if $params contains invalid values
6160
* @throws UnexpectedResponseException if the Redmine server delivers an unexpected response
@@ -108,8 +107,8 @@ public function download($id)
108107
* available $params :
109108
* - filename: filename of the attachment
110109
*
111-
* @param string $attachment the attachment content
112-
* @param array $params optional parameters to be passed to the api
110+
* @param string $attachment the attachment content
111+
* @param array<mixed> $params optional parameters to be passed to the api
113112
*
114113
* @return string information about the attachment
115114
*/

src/Redmine/Api/CustomField.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,26 @@
1515
*/
1616
class CustomField extends AbstractApi
1717
{
18+
/**
19+
* @var array<mixed>
20+
*/
1821
private $customFields = [];
1922

23+
/**
24+
* @var null|array<int,string>
25+
*/
2026
private $customFieldNames = null;
2127

2228
/**
2329
* List custom fields.
2430
*
2531
* @see http://www.redmine.org/projects/redmine/wiki/Rest_CustomFields#GET
2632
*
27-
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
33+
* @param array<mixed> $params optional parameters to be passed to the api (offset, limit, ...)
2834
*
2935
* @throws UnexpectedResponseException if response body could not be converted into array
3036
*
31-
* @return array list of custom fields found
37+
* @return array<mixed> list of custom fields found
3238
*/
3339
final public function list(array $params = []): array
3440
{
@@ -71,9 +77,9 @@ final public function listNames(): array
7177
*
7278
* @see http://www.redmine.org/projects/redmine/wiki/Rest_CustomFields#GET
7379
*
74-
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
80+
* @param array<mixed> $params optional parameters to be passed to the api (offset, limit, ...)
7581
*
76-
* @return array|string|false list of custom fields found or error message or false
82+
* @return array<mixed>|string|false list of custom fields found or error message or false
7783
*/
7884
public function all(array $params = [])
7985
{
@@ -102,10 +108,10 @@ public function all(array $params = [])
102108
* @deprecated v2.7.0 Use listNames() instead.
103109
* @see CustomField::listNames()
104110
*
105-
* @param bool $forceUpdate to force the update of the custom fields var
106-
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
111+
* @param bool $forceUpdate to force the update of the custom fields var
112+
* @param array<mixed> $params optional parameters to be passed to the api (offset, limit, ...)
107113
*
108-
* @return array list of custom fields (id => name)
114+
* @return array<string,int> list of custom fields (name => id)
109115
*/
110116
public function listing($forceUpdate = false, array $params = [])
111117
{
@@ -120,8 +126,8 @@ public function listing($forceUpdate = false, array $params = [])
120126
* @deprecated v2.7.0 Use listNames() instead.
121127
* @see CustomField::listNames()
122128
*
123-
* @param string|int $name customer field name
124-
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
129+
* @param string|int $name customer field name
130+
* @param array<mixed> $params optional parameters to be passed to the api (offset, limit, ...)
125131
*
126132
* @return int|false
127133
*/
@@ -138,7 +144,12 @@ public function getIdByName($name, array $params = [])
138144
return $arr[(string) $name];
139145
}
140146

141-
private function doListing(bool $forceUpdate, array $params)
147+
/**
148+
* @param array<mixed> $params
149+
*
150+
* @return array<mixed>
151+
*/
152+
private function doListing(bool $forceUpdate, array $params): array
142153
{
143154
if (empty($this->customFields) || $forceUpdate) {
144155
$this->customFields = $this->list($params);

src/Redmine/Api/Group.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,26 @@
2121
*/
2222
class Group extends AbstractApi
2323
{
24+
/**
25+
* @var array<mixed>
26+
*/
2427
private $groups = [];
2528

29+
/**
30+
* @var null|array<int,string>
31+
*/
2632
private $groupNames = null;
2733

2834
/**
2935
* List groups.
3036
*
3137
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Groups#GET
3238
*
33-
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
39+
* @param array<mixed> $params optional parameters to be passed to the api (offset, limit, ...)
3440
*
3541
* @throws UnexpectedResponseException if response body could not be converted into array
3642
*
37-
* @return array list of groups found
43+
* @return array<mixed> list of groups found
3844
*/
3945
final public function list(array $params = []): array
4046
{
@@ -73,9 +79,9 @@ final public function listNames(): array
7379
*
7480
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Groups#GET
7581
*
76-
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
82+
* @param array<mixed> $params optional parameters to be passed to the api (offset, limit, ...)
7783
*
78-
* @return array|string|false list of groups found or error message or false
84+
* @return array<mixed>|string|false list of groups found or error message or false
7985
*/
8086
public function all(array $params = [])
8187
{
@@ -106,7 +112,7 @@ public function all(array $params = [])
106112
*
107113
* @param bool $forceUpdate to force the update of the groups var
108114
*
109-
* @return array list of groups (id => name)
115+
* @return array<string,int> list of groups (name => id)
110116
*/
111117
public function listing($forceUpdate = false)
112118
{
@@ -128,7 +134,7 @@ public function listing($forceUpdate = false)
128134
*
129135
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Groups#POST
130136
*
131-
* @param array $params the new group data
137+
* @param array<mixed> $params the new group data
132138
*
133139
* @throws MissingParameterException Missing mandatory parameters
134140
*
@@ -170,7 +176,8 @@ public function create(array $params = [])
170176
*
171177
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Groups#PUT
172178
*
173-
* @param int $id the group id
179+
* @param int $id the group id
180+
* @param array<mixed> $params
174181
*
175182
* @return string empty string
176183
*/
@@ -198,10 +205,10 @@ public function update(int $id, array $params = [])
198205
* available $params :
199206
* - include: a coma separated list of associations to include in the response: users,memberships
200207
*
201-
* @param int $id the group id
202-
* @param array $params params to pass to url
208+
* @param int $id the group id
209+
* @param array<mixed> $params params to pass to url
203210
*
204-
* @return array|false|string information about the group as array or false|string on error
211+
* @return array<mixed>|false|string information about the group as array or false|string on error
205212
*/
206213
public function show($id, array $params = [])
207214
{

0 commit comments

Comments
 (0)