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 more phpstan level 6 errors
  • Loading branch information
Art4 committed Oct 8, 2024
commit 9b8b71f5f0c036cf778499238f999428431e5a8e
2 changes: 1 addition & 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 Down
3 changes: 3 additions & 0 deletions src/Redmine/Client/ClientApiTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*/
trait ClientApiTrait
{
/**
* @var array<Api>
*/
private array $apiInstances = [];

private array $apiClassnames = [
Expand Down
17 changes: 17 additions & 0 deletions src/Redmine/Client/NativeCurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,20 @@ final class NativeCurlClient implements Client, HttpClient
private int $lastResponseStatusCode = 0;
private string $lastResponseContentType = '';
private string $lastResponseBody = '';

/**
* @var array<int,mixed>
*/
private array $curlOptions = [];

/**
* @var array<string>
*/
private array $httpHeaders = [];

/**
* @var array<string>
*/
private array $httpHeadersNames = [];
private ?int $port = null;

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

/**
* Set multiple HTTP headers.
*
* @param array<mixed> $headers
*/
private function setHttpHeaders(array $headers): void
{
Expand Down Expand Up @@ -339,6 +353,9 @@ private function createCurl(string $method, string $path, string $body = '', str
return $curl;
}

/**
* @return array<string>
*/
private function createHttpHeader(string $path, string $contentType = ''): array
{
// Additional request headers
Expand Down
14 changes: 7 additions & 7 deletions src/Redmine/Http/HttpFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ final class HttpFactory
public static function makeResponse(int $statusCode, string $contentType, string $content): Response
{
return new class ($statusCode, $contentType, $content) implements Response {
private $statusCode;
private $contentType;
private $body;
private int $statusCode;
private string $contentType;
private string $body;

public function __construct(int $statusCode, string $contentType, string $body)
{
Expand Down Expand Up @@ -45,10 +45,10 @@ public function getContent(): string
public static function makeRequest(string $method, string $path, string $contentType = '', string $content = ''): Request
{
return new class ($method, $path, $contentType, $content) implements Request {
private $method;
private $path;
private $contentType;
private $content;
private string $method;
private string $path;
private string $contentType;
private string $content;

public function __construct(string $method, string $path, string $contentType, string $content)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Redmine/Serializer/JsonSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public static function createFromString(string $data): self
}

/**
* @param array<mixed> $data
*
* @throws SerializerException if $data could not be serialized to JSON
*/
public static function createFromArray(array $data): self
Expand Down Expand Up @@ -77,6 +79,9 @@ private function decode(string $encoded): void
}
}

/**
* @param array<mixed> $normalized
*/
private function encode(array $normalized): void
{
$this->normalized = $normalized;
Expand Down
6 changes: 6 additions & 0 deletions src/Redmine/Serializer/PathSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*/
final class PathSerializer implements Stringable
{
/**
* @param array<string> $queryParams
*/
public static function create(string $path, array $queryParams = []): self
{
$serializer = new self();
Expand All @@ -20,6 +23,9 @@ public static function create(string $path, array $queryParams = []): self

private string $path;

/**
* @var array<string>
*/
private array $queryParams;

private function __construct()
Expand Down
20 changes: 17 additions & 3 deletions src/Redmine/Serializer/XmlSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public static function createFromString(string $data): self
}

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

/**
* @param array<mixed> $normalized
*
* @throws SerializerException
*/
private function denormalize(array $normalized): void
{
$this->normalized = $normalized;
Expand Down Expand Up @@ -136,7 +143,10 @@ private function denormalize(array $normalized): void
$this->encoded = $this->deserialized->asXml();
}

private function createXmlElement(string $rootElementName, $params): SimpleXMLElement
/**
* @param array<mixed> $params
*/
private function createXmlElement(string $rootElementName, array $params): SimpleXMLElement
{
$value = '';
if (! is_array($params)) {
Expand All @@ -154,6 +164,10 @@ private function createXmlElement(string $rootElementName, $params): SimpleXMLEl
return $xml;
}

/**
* @param string|int $k
* @param mixed $v
*/
private function addChildToXmlElement(SimpleXMLElement $xml, $k, $v): void
{
$specialParams = [
Expand Down Expand Up @@ -196,8 +210,8 @@ private function addChildToXmlElement(SimpleXMLElement $xml, $k, $v): void
/**
* Attaches Custom Fields to XML element.
*
* @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 SimpleXMLElement $xml XML Element the custom fields are attached to
* @param array<array<string>> $fields array of fields to attach, each field needs name, id and value set
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_api#Working-with-custom-fields
*/
Expand Down
10 changes: 9 additions & 1 deletion tests/Unit/Serializer/XmlSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ public function testCreateFromArrayEncodesToExpectedString(array $data, $expecte
$this->assertXmlStringEqualsXmlString($expected, $serializer->__toString());
}

/**
* @return array<string,mixed>
*/
public static function getNormalizedToEncodedData(): array
{
return [
Expand Down Expand Up @@ -298,6 +301,8 @@ public static function getNormalizedToEncodedData(): array

/**
* @dataProvider getInvalidSerializedData
*
* @param array<int,mixed> $data
*/
#[DataProvider('getInvalidSerializedData')]
public function testCreateFromArrayWithInvalidDataThrowsException(string $message, array $data): void
Expand All @@ -308,9 +313,12 @@ public function testCreateFromArrayWithInvalidDataThrowsException(string $messag
XmlSerializer::createFromArray($data);
}

/**
* @return array<string,mixed>
*/
public static function getInvalidSerializedData(): array
{
return[
return [
'invalid element name as start tag' => [
'Could not create XML from array: "StartTag: invalid element name' . "\n" . '", "Extra content at the end of the document' . "\n" . '"',
['0' => ['foobar']],
Expand Down
Loading