Skip to content

Commit 335afd0

Browse files
authored
Merge pull request #8 from artemeon/chore/phpstan-level-8
2 parents 6c0ce09 + 7e60009 commit 335afd0

10 files changed

Lines changed: 34 additions & 14 deletions

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 6
2+
level: 8
33
paths:
44
- src
55
- tests

src/ConfluencePageContentDownloader.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ public function downloadPageContent(ConfluencePage $page, bool $withAttachments
4747
return;
4848
}
4949

50-
$attachments = $this->contentEndpoint->findChildAttachments($page->getId());
50+
$pageId = $page->getId();
51+
if ($pageId === null) {
52+
return;
53+
}
54+
55+
$attachments = $this->contentEndpoint->findChildAttachments($pageId);
5156
foreach ($attachments as $attachment) {
5257
$this->downloadEndpoint->downloadAttachment($attachment);
5358
}
@@ -64,7 +69,7 @@ private function repairPageContent(ConfluencePage $page): ConfluencePage
6469
$domDocument->loadHTML($page->getContent());
6570
if (!$domDocument->validate()) {
6671
$pageContent = '';
67-
foreach ($domDocument->getElementsByTagName('body')->item(0)->childNodes as $child) {
72+
foreach ($domDocument->getElementsByTagName('body')->item(0)->childNodes ?? [] as $child) {
6873
$pageContent .= $domDocument->saveHTML($child);
6974
}
7075

src/Endpoint/Download.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Artemeon\Confluence\Endpoint\Dto\ConfluenceAttachment;
88
use Artemeon\Confluence\Endpoint\Dto\ConfluencePage;
9+
use DateTime;
910
use GuzzleHttp\Client;
1011

1112
class Download
@@ -70,10 +71,15 @@ private function shouldAttachmentBeUpdated(ConfluenceAttachment $attachment): bo
7071
{
7172
$filepath = $this->getAttachmentFilePath($attachment);
7273

74+
$lastUpdated = $attachment->getLastUpdated();
75+
if (!$lastUpdated instanceof DateTime) {
76+
return true;
77+
}
78+
7379
if (file_exists($filepath)) {
7480
$filemtime = filemtime($filepath);
7581
if (is_int($filemtime)) {
76-
return $filemtime < $attachment->getLastUpdated()->getTimestamp();
82+
return $filemtime < $lastUpdated->getTimestamp();
7783
}
7884
}
7985

src/Endpoint/Dto/ConfluencePage.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,15 @@ public function getMetadata(): ?array
118118
*/
119119
public function getLabels(): array
120120
{
121+
$metadata = $this->getMetadata();
122+
123+
if ($metadata === null || !array_key_exists('labels', $metadata)) {
124+
return [];
125+
}
126+
121127
$labels = [];
122128

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

src/MacroReplacer/AdfPanelReplacer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ function ($match) {
2929
$haystack
3030
);
3131

32+
if ($result === null) {
33+
return $haystack;
34+
}
35+
3236
$result = preg_replace(
3337
'/<ac:adf-extension[^>]*>(.*?)<\/ac:adf-extension>/is',
3438
'$1',
3539
$result
3640
);
3741

38-
return $result;
42+
return $result ?? $haystack;
3943
}
4044
}

src/MacroReplacer/GenericPanelReplacer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ function ($match) {
3434
);
3535
},
3636
$haystack
37-
);
37+
) ?? $haystack;
3838
}
3939
}

src/MacroReplacer/ImageAndVideoMacroReplacer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ function ($match) {
4545
}
4646
},
4747
$haystack
48-
);
48+
) ?? $haystack;
4949
}
5050
}

src/MacroReplacer/LayoutSectionMacroReplacer.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ function ($match) {
1616
return '<div data-macro-type="'.$macroType.'">'.$macroContent.'</div>';
1717
},
1818
$haystack
19-
);
20-
19+
) ?? $haystack;
2120

2221
return preg_replace_callback(
2322
'/<ac:layout-cell>(.*?)<\/ac:layout-cell>/is',
@@ -26,6 +25,6 @@ function ($match) {
2625
return '<div>'.$macroContent.'</div>';
2726
},
2827
$haystack
29-
);
28+
) ?? $haystack;
3029
}
3130
}

src/MacroReplacer/OtherMacroRemover.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class OtherMacroRemover implements MacroReplacerInterface
1111
{
1212
public function replace(string $haystack): string
1313
{
14-
$haystack = preg_replace('/<ac:[^>]+>.*?<\/ac:[^>]+>/is', '', $haystack);
15-
return preg_replace('/<\/ac:([a-zA-Z0-9]+)>/', '', $haystack);
14+
$haystack = preg_replace('/<ac:[^>]+>.*?<\/ac:[^>]+>/is', '', $haystack) ?? $haystack;
15+
return preg_replace('/<\/ac:([a-zA-Z0-9]+)>/', '', $haystack) ?? $haystack;
1616
}
1717
}

src/MacroReplacer/StructuredMacroReplacer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ function ($match) {
2424
return sprintf('<div class="documentation-panel-%s"><div>%s</div></div>', $macroName, $macroContent);
2525
},
2626
$haystack
27-
);
27+
) ?? $haystack;
2828
}
2929
}

0 commit comments

Comments
 (0)