diff --git a/composer.json b/composer.json index 282657c..9efe953 100755 --- a/composer.json +++ b/composer.json @@ -7,16 +7,14 @@ "phpstan": "php ./vendor/bin/phpstan analyse --memory-limit=4G" }, "require": { - "php": ">=8.1", + "php": ">=8.2", "guzzlehttp/guzzle": "~7.4", "ext-json": "*", "ext-mbstring": "*" }, "require-dev": { - "phpunit/phpunit": "^8.0", - "phpstan/phpstan": "^1.10", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan-phpunit": "^1.3" + "phpstan/phpstan": "^2.1.36", + "phpstan/extension-installer": "^1.3" }, "autoload": { "psr-4": { @@ -29,6 +27,7 @@ } }, "config": { + "process-timeout": 0, "allow-plugins": { "phpstan/extension-installer": true } diff --git a/phpstan.neon b/phpstan.neon index 50cc461..5049591 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,8 +1,6 @@ -includes: - - phar://phpstan.phar/conf/bleedingEdge.neon - parameters: - level: 5 + level: 6 paths: - src - tests + treatPhpDocTypesAsCertain: false diff --git a/src/ConfluencePageContentDownloader.php b/src/ConfluencePageContentDownloader.php index 60026b7..bab5da8 100755 --- a/src/ConfluencePageContentDownloader.php +++ b/src/ConfluencePageContentDownloader.php @@ -13,10 +13,16 @@ class ConfluencePageContentDownloader { + /** + * @var MacroReplacerInterface[] + */ private array $macroReplacers; private Content $contentEndpoint; private Download $downloadEndpoint; + /** + * @param MacroReplacerInterface[] $macroReplacers + */ public function __construct(Content $contentEndpoint, Download $downloadEndpoint, array $macroReplacers = []) { $this->macroReplacers = $macroReplacers; diff --git a/src/Endpoint/Auth.php b/src/Endpoint/Auth.php index da3631d..94c4f47 100755 --- a/src/Endpoint/Auth.php +++ b/src/Endpoint/Auth.php @@ -15,6 +15,9 @@ public function __construct(string $username, string $apiToken) $this->apiToken = $apiToken; } + /** + * @return array{auth:array{string,string}} + */ public function getAuthenticationArray(): array { return ['auth' => [$this->username, $this->apiToken]]; diff --git a/src/Endpoint/Content.php b/src/Endpoint/Content.php index b8911c1..a9b4bd0 100755 --- a/src/Endpoint/Content.php +++ b/src/Endpoint/Content.php @@ -89,6 +89,8 @@ public function findPageContent(string $pageId): ConfluencePage /** * Use descendants.attachment in the Content API to get attachments + * + * @return list */ public function findChildAttachments(string $pageId): array { @@ -101,17 +103,17 @@ public function findChildAttachments(string $pageId): array ], $this->auth->getAuthenticationArray()) ); - if ($response->getStatusCode() === 200) { - $attachmentsData = json_decode($response->getBody()->getContents(), true); - $attachments = []; + if ($response->getStatusCode() !== 200) { + throw new Exception('Fehler beim Abrufen der Attachments. HTTP-Statuscode: ' . $response->getStatusCode()); + } - foreach ($attachmentsData['results'] as $attachmentRawData) { - $attachments[] = new ConfluenceAttachment($attachmentRawData); - } + $attachmentsData = json_decode($response->getBody()->getContents(), true); + $attachments = []; - return $attachments; - } else { - throw new Exception('Fehler beim Abrufen der Attachments. HTTP-Statuscode: ' . $response->getStatusCode()); + foreach ($attachmentsData['results'] as $attachmentRawData) { + $attachments[] = new ConfluenceAttachment($attachmentRawData); } + + return $attachments; } } diff --git a/src/Endpoint/Download.php b/src/Endpoint/Download.php index d2366e2..56cfb30 100755 --- a/src/Endpoint/Download.php +++ b/src/Endpoint/Download.php @@ -30,7 +30,7 @@ private function checkDownloadFolder(): bool return true; } - public function downloadPageContent(ConfluencePage $confluencePage, string $fileName) + public function downloadPageContent(ConfluencePage $confluencePage, string $fileName): void { if (!$this->checkDownloadFolder()) { echo 'Error: The download folder does not exist or could not be created.'; diff --git a/src/Endpoint/Dto/ConfluenceAttachment.php b/src/Endpoint/Dto/ConfluenceAttachment.php index 2841d1f..ae5b0f1 100755 --- a/src/Endpoint/Dto/ConfluenceAttachment.php +++ b/src/Endpoint/Dto/ConfluenceAttachment.php @@ -8,16 +8,22 @@ class ConfluenceAttachment { - private array $rawData; - private string $title; private ?DateTime $lastUpdated; - public function __construct(array $rawData) + /** + * @param array{ + * title: string, + * history?: array{ + * lastUpdated?: array{ + * when?: string|null, + * }, + * }, + * } $rawData + */ + public function __construct(private array $rawData) { - $this->rawData = $rawData; - $this->title = $rawData['title']; $this->lastUpdated = isset($rawData['history']['lastUpdated']['when']) ? new DateTime($rawData['history']['lastUpdated']['when']) : null; } diff --git a/src/Endpoint/Dto/ConfluencePage.php b/src/Endpoint/Dto/ConfluencePage.php index 4f3e39b..fd5a5d6 100755 --- a/src/Endpoint/Dto/ConfluencePage.php +++ b/src/Endpoint/Dto/ConfluencePage.php @@ -12,19 +12,30 @@ class ConfluencePage private ?string $type; private ?string $status; private ?string $title; + /** + * @var array|null + */ private ?array $space; + /** + * @var array|null + */ private ?array $version; + /** + * @var array|null + */ private ?array $body; + /** + * @var array|null + */ private ?array $metadata; private ?DateTime $lastUpdated; - - private array $rawData; private string $content; - public function __construct(array $rawData) + /** + * @param array $rawData + */ + public function __construct(private array $rawData) { - $this->rawData = $rawData; - $this->id = $rawData['id'] ?? null; $this->type = $rawData['type'] ?? null; $this->status = $rawData['status'] ?? null; @@ -56,16 +67,25 @@ public function getTitle(): ?string return $this->title; } + /** + * @return array|null + */ public function getSpace(): ?array { return $this->space; } + /** + * @return array|null + */ public function getVersion(): ?array { return $this->version; } + /** + * @return array|null + */ public function getBody(): ?array { return $this->body; @@ -85,12 +105,19 @@ public function setContent(string $content): void $this->content = $content; } + /** + * @return array|null + */ public function getMetadata(): ?array { return $this->metadata; } - public function getLabels(): array { + /** + * @return list + */ + public function getLabels(): array + { $labels = []; foreach ($this->getMetadata()['labels']['results'] as $labelData) { @@ -105,6 +132,9 @@ public function getLastUpdated(): ?DateTime return $this->lastUpdated; } + /** + * @return array + */ public function getRawData(): array { return $this->rawData;