Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -29,6 +27,7 @@
}
},
"config": {
"process-timeout": 0,
"allow-plugins": {
"phpstan/extension-installer": true
}
Expand Down
6 changes: 2 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
includes:
- phar://phpstan.phar/conf/bleedingEdge.neon

parameters:
level: 5
level: 6
paths:
- src
- tests
treatPhpDocTypesAsCertain: false
6 changes: 6 additions & 0 deletions src/ConfluencePageContentDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/Endpoint/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand Down
20 changes: 11 additions & 9 deletions src/Endpoint/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public function findPageContent(string $pageId): ConfluencePage

/**
* Use descendants.attachment in the Content API to get attachments
*
* @return list<ConfluenceAttachment>
*/
public function findChildAttachments(string $pageId): array
{
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Endpoint/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down
16 changes: 11 additions & 5 deletions src/Endpoint/Dto/ConfluenceAttachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
42 changes: 36 additions & 6 deletions src/Endpoint/Dto/ConfluencePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,30 @@ class ConfluencePage
private ?string $type;
private ?string $status;
private ?string $title;
/**
* @var array<array-key,mixed>|null
*/
private ?array $space;
/**
* @var array<array-key,mixed>|null
*/
private ?array $version;
/**
* @var array<array-key,mixed>|null
*/
private ?array $body;
/**
* @var array<array-key,mixed>|null
*/
private ?array $metadata;
private ?DateTime $lastUpdated;

private array $rawData;
private string $content;

public function __construct(array $rawData)
/**
* @param array<array-key,mixed> $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;
Expand Down Expand Up @@ -56,16 +67,25 @@ public function getTitle(): ?string
return $this->title;
}

/**
* @return array<array-key,mixed>|null
*/
public function getSpace(): ?array
{
return $this->space;
}

/**
* @return array<array-key,mixed>|null
*/
public function getVersion(): ?array
{
return $this->version;
}

/**
* @return array<array-key,mixed>|null
*/
public function getBody(): ?array
{
return $this->body;
Expand All @@ -85,12 +105,19 @@ public function setContent(string $content): void
$this->content = $content;
}

/**
* @return array<array-key,mixed>|null
*/
public function getMetadata(): ?array
{
return $this->metadata;
}

public function getLabels(): array {
/**
* @return list<ConfluenceLabel>
*/
public function getLabels(): array
{
$labels = [];

foreach ($this->getMetadata()['labels']['results'] as $labelData) {
Expand All @@ -105,6 +132,9 @@ public function getLastUpdated(): ?DateTime
return $this->lastUpdated;
}

/**
* @return array<array-key, mixed>
*/
public function getRawData(): array
{
return $this->rawData;
Expand Down