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
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 6
level: 8
paths:
- src
- tests
Expand Down
9 changes: 7 additions & 2 deletions src/ConfluencePageContentDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ public function downloadPageContent(ConfluencePage $page, bool $withAttachments
return;
}

$attachments = $this->contentEndpoint->findChildAttachments($page->getId());
$pageId = $page->getId();
if ($pageId === null) {
return;
}

$attachments = $this->contentEndpoint->findChildAttachments($pageId);
foreach ($attachments as $attachment) {
$this->downloadEndpoint->downloadAttachment($attachment);
}
Expand All @@ -64,7 +69,7 @@ private function repairPageContent(ConfluencePage $page): ConfluencePage
$domDocument->loadHTML($page->getContent());
if (!$domDocument->validate()) {
$pageContent = '';
foreach ($domDocument->getElementsByTagName('body')->item(0)->childNodes as $child) {
foreach ($domDocument->getElementsByTagName('body')->item(0)->childNodes ?? [] as $child) {
$pageContent .= $domDocument->saveHTML($child);
}

Expand Down
8 changes: 7 additions & 1 deletion src/Endpoint/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Artemeon\Confluence\Endpoint\Dto\ConfluenceAttachment;
use Artemeon\Confluence\Endpoint\Dto\ConfluencePage;
use DateTime;
use GuzzleHttp\Client;

class Download
Expand Down Expand Up @@ -70,10 +71,15 @@ private function shouldAttachmentBeUpdated(ConfluenceAttachment $attachment): bo
{
$filepath = $this->getAttachmentFilePath($attachment);

$lastUpdated = $attachment->getLastUpdated();
if (!$lastUpdated instanceof DateTime) {
return true;
}

if (file_exists($filepath)) {
$filemtime = filemtime($filepath);
if (is_int($filemtime)) {
return $filemtime < $attachment->getLastUpdated()->getTimestamp();
return $filemtime < $lastUpdated->getTimestamp();
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/Endpoint/Dto/ConfluencePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,15 @@ public function getMetadata(): ?array
*/
public function getLabels(): array
{
$metadata = $this->getMetadata();

if ($metadata === null || !array_key_exists('labels', $metadata)) {
return [];
}

$labels = [];

foreach ($this->getMetadata()['labels']['results'] as $labelData) {
foreach ($metadata['labels']['results'] as $labelData) {
$labels[] = new ConfluenceLabel($labelData['id'], $labelData['name'], $labelData['prefix'], $labelData['label']);
}

Expand Down
6 changes: 5 additions & 1 deletion src/MacroReplacer/AdfPanelReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ function ($match) {
$haystack
);

if ($result === null) {
return $haystack;
}

$result = preg_replace(
'/<ac:adf-extension[^>]*>(.*?)<\/ac:adf-extension>/is',
'$1',
$result
);

return $result;
return $result ?? $haystack;
}
}
2 changes: 1 addition & 1 deletion src/MacroReplacer/GenericPanelReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ function ($match) {
);
},
$haystack
);
) ?? $haystack;
}
}
2 changes: 1 addition & 1 deletion src/MacroReplacer/ImageAndVideoMacroReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ function ($match) {
}
},
$haystack
);
) ?? $haystack;
}
}
5 changes: 2 additions & 3 deletions src/MacroReplacer/LayoutSectionMacroReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ function ($match) {
return '<div data-macro-type="'.$macroType.'">'.$macroContent.'</div>';
},
$haystack
);

) ?? $haystack;

return preg_replace_callback(
'/<ac:layout-cell>(.*?)<\/ac:layout-cell>/is',
Expand All @@ -26,6 +25,6 @@ function ($match) {
return '<div>'.$macroContent.'</div>';
},
$haystack
);
) ?? $haystack;
}
}
4 changes: 2 additions & 2 deletions src/MacroReplacer/OtherMacroRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OtherMacroRemover implements MacroReplacerInterface
{
public function replace(string $haystack): string
{
$haystack = preg_replace('/<ac:[^>]+>.*?<\/ac:[^>]+>/is', '', $haystack);
return preg_replace('/<\/ac:([a-zA-Z0-9]+)>/', '', $haystack);
$haystack = preg_replace('/<ac:[^>]+>.*?<\/ac:[^>]+>/is', '', $haystack) ?? $haystack;
return preg_replace('/<\/ac:([a-zA-Z0-9]+)>/', '', $haystack) ?? $haystack;
}
}
2 changes: 1 addition & 1 deletion src/MacroReplacer/StructuredMacroReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ function ($match) {
return sprintf('<div class="documentation-panel-%s"><div>%s</div></div>', $macroName, $macroContent);
},
$haystack
);
) ?? $haystack;
}
}