Skip to content

Commit 9b8b71f

Browse files
committed
Fix more phpstan level 6 errors
1 parent 8df2277 commit 9b8b71f

File tree

8 files changed

+65
-12
lines changed

8 files changed

+65
-12
lines changed

.phpstan.neon

Lines changed: 1 addition & 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/

src/Redmine/Client/ClientApiTrait.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
*/
1313
trait ClientApiTrait
1414
{
15+
/**
16+
* @var array<Api>
17+
*/
1518
private array $apiInstances = [];
1619

1720
private array $apiClassnames = [

src/Redmine/Client/NativeCurlClient.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,20 @@ final class NativeCurlClient implements Client, HttpClient
2424
private int $lastResponseStatusCode = 0;
2525
private string $lastResponseContentType = '';
2626
private string $lastResponseBody = '';
27+
28+
/**
29+
* @var array<int,mixed>
30+
*/
2731
private array $curlOptions = [];
32+
33+
/**
34+
* @var array<string>
35+
*/
2836
private array $httpHeaders = [];
37+
38+
/**
39+
* @var array<string>
40+
*/
2941
private array $httpHeadersNames = [];
3042
private ?int $port = null;
3143

@@ -194,6 +206,8 @@ public function unsetCurlOption(int $option): void
194206

195207
/**
196208
* Set multiple HTTP headers.
209+
*
210+
* @param array<mixed> $headers
197211
*/
198212
private function setHttpHeaders(array $headers): void
199213
{
@@ -339,6 +353,9 @@ private function createCurl(string $method, string $path, string $body = '', str
339353
return $curl;
340354
}
341355

356+
/**
357+
* @return array<string>
358+
*/
342359
private function createHttpHeader(string $path, string $contentType = ''): array
343360
{
344361
// Additional request headers

src/Redmine/Http/HttpFactory.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ final class HttpFactory
1414
public static function makeResponse(int $statusCode, string $contentType, string $content): Response
1515
{
1616
return new class ($statusCode, $contentType, $content) implements Response {
17-
private $statusCode;
18-
private $contentType;
19-
private $body;
17+
private int $statusCode;
18+
private string $contentType;
19+
private string $body;
2020

2121
public function __construct(int $statusCode, string $contentType, string $body)
2222
{
@@ -45,10 +45,10 @@ public function getContent(): string
4545
public static function makeRequest(string $method, string $path, string $contentType = '', string $content = ''): Request
4646
{
4747
return new class ($method, $path, $contentType, $content) implements Request {
48-
private $method;
49-
private $path;
50-
private $contentType;
51-
private $content;
48+
private string $method;
49+
private string $path;
50+
private string $contentType;
51+
private string $content;
5252

5353
public function __construct(string $method, string $path, string $contentType, string $content)
5454
{

src/Redmine/Serializer/JsonSerializer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public static function createFromString(string $data): self
2323
}
2424

2525
/**
26+
* @param array<mixed> $data
27+
*
2628
* @throws SerializerException if $data could not be serialized to JSON
2729
*/
2830
public static function createFromArray(array $data): self
@@ -77,6 +79,9 @@ private function decode(string $encoded): void
7779
}
7880
}
7981

82+
/**
83+
* @param array<mixed> $normalized
84+
*/
8085
private function encode(array $normalized): void
8186
{
8287
$this->normalized = $normalized;

src/Redmine/Serializer/PathSerializer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010
final class PathSerializer implements Stringable
1111
{
12+
/**
13+
* @param array<string> $queryParams
14+
*/
1215
public static function create(string $path, array $queryParams = []): self
1316
{
1417
$serializer = new self();
@@ -20,6 +23,9 @@ public static function create(string $path, array $queryParams = []): self
2023

2124
private string $path;
2225

26+
/**
27+
* @var array<string>
28+
*/
2329
private array $queryParams;
2430

2531
private function __construct()

src/Redmine/Serializer/XmlSerializer.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public static function createFromString(string $data): self
2525
}
2626

2727
/**
28+
* @param array<string,mixed> $data
29+
*
2830
* @throws SerializerException if $data could not be serialized to XML
2931
*/
3032
public static function createFromArray(array $data): self
@@ -105,6 +107,11 @@ private function normalize(SimpleXMLElement $deserialized): void
105107
$this->normalized = JsonSerializer::createFromString($serialized)->getNormalized();
106108
}
107109

110+
/**
111+
* @param array<mixed> $normalized
112+
*
113+
* @throws SerializerException
114+
*/
108115
private function denormalize(array $normalized): void
109116
{
110117
$this->normalized = $normalized;
@@ -136,7 +143,10 @@ private function denormalize(array $normalized): void
136143
$this->encoded = $this->deserialized->asXml();
137144
}
138145

139-
private function createXmlElement(string $rootElementName, $params): SimpleXMLElement
146+
/**
147+
* @param array<mixed> $params
148+
*/
149+
private function createXmlElement(string $rootElementName, array $params): SimpleXMLElement
140150
{
141151
$value = '';
142152
if (! is_array($params)) {
@@ -154,6 +164,10 @@ private function createXmlElement(string $rootElementName, $params): SimpleXMLEl
154164
return $xml;
155165
}
156166

167+
/**
168+
* @param string|int $k
169+
* @param mixed $v
170+
*/
157171
private function addChildToXmlElement(SimpleXMLElement $xml, $k, $v): void
158172
{
159173
$specialParams = [
@@ -196,8 +210,8 @@ private function addChildToXmlElement(SimpleXMLElement $xml, $k, $v): void
196210
/**
197211
* Attaches Custom Fields to XML element.
198212
*
199-
* @param SimpleXMLElement $xml XML Element the custom fields are attached to
200-
* @param array $fields array of fields to attach, each field needs name, id and value set
213+
* @param SimpleXMLElement $xml XML Element the custom fields are attached to
214+
* @param array<array<string>> $fields array of fields to attach, each field needs name, id and value set
201215
*
202216
* @see http://www.redmine.org/projects/redmine/wiki/Rest_api#Working-with-custom-fields
203217
*/

tests/Unit/Serializer/XmlSerializerTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ public function testCreateFromArrayEncodesToExpectedString(array $data, $expecte
122122
$this->assertXmlStringEqualsXmlString($expected, $serializer->__toString());
123123
}
124124

125+
/**
126+
* @return array<string,mixed>
127+
*/
125128
public static function getNormalizedToEncodedData(): array
126129
{
127130
return [
@@ -298,6 +301,8 @@ public static function getNormalizedToEncodedData(): array
298301

299302
/**
300303
* @dataProvider getInvalidSerializedData
304+
*
305+
* @param array<int,mixed> $data
301306
*/
302307
#[DataProvider('getInvalidSerializedData')]
303308
public function testCreateFromArrayWithInvalidDataThrowsException(string $message, array $data): void
@@ -308,9 +313,12 @@ public function testCreateFromArrayWithInvalidDataThrowsException(string $messag
308313
XmlSerializer::createFromArray($data);
309314
}
310315

316+
/**
317+
* @return array<string,mixed>
318+
*/
311319
public static function getInvalidSerializedData(): array
312320
{
313-
return[
321+
return [
314322
'invalid element name as start tag' => [
315323
'Could not create XML from array: "StartTag: invalid element name' . "\n" . '", "Extra content at the end of the document' . "\n" . '"',
316324
['0' => ['foobar']],

0 commit comments

Comments
 (0)