Skip to content

Commit 07aab33

Browse files
committed
♻️ reduced Cognitive Complexity
1 parent 71a6694 commit 07aab33

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

classes/Feed.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ public function stringFromSnippet(): Feed
5050
return $this;
5151
}
5252

53-
// cache miss, load items now
53+
// cache miss, load items and dynamic options now
5454
$this->loadItems();
55+
$this->dynamicOptions();
5556

5657
// render snippet with items in options
5758
$this->string = trim(strval(snippet(A::get($this->options, 'snippet'), $this->options, true)));
@@ -96,8 +97,14 @@ private function loadItems(): void
9697
$items = $items->sortBy($this->options['datefield'], 'desc');
9798
}
9899
$this->options['items'] = $items;
100+
}
101+
102+
private function dynamicOptions(): void
103+
{
99104
$this->options['link'] = url($this->options['link']);
100105

106+
/** @var Pages $items */
107+
$items = $this->options['items'];
101108
if ($items->count()) {
102109
$modified = $items->first()->modified($this->options['dateformat'], 'date');
103110
$this->options['modified'] = $modified;
@@ -116,19 +123,20 @@ public function response(): Response
116123
$snippet = A::get($this->options, 'snippet');
117124
$mime = Mime::fromExtension(A::get($this->options, 'mime', ''));
118125

126+
$response = null;
119127
if ($mime !== null) {
120-
return new Response($this->string, $mime);
128+
$response = new Response($this->string, $mime);
121129
} elseif ($snippet === 'feed/sitemap' && Feed::isXml($this->string)) {
122-
return new Response($this->string, 'xml');
130+
$response = new Response($this->string, 'xml');
123131
} elseif ($snippet === 'feed/atom' && Feed::isXml($this->string)) {
124-
return new Response($this->string, 'xml');
132+
$response = new Response($this->string, 'xml');
125133
} elseif ($snippet === 'feed/json' && Feed::isJson($this->string)) {
126-
return new Response($this->string, 'json');
134+
$response = new Response($this->string, 'json');
127135
} elseif ($snippet === 'feed/rss' && Feed::isXml($this->string)) {
128-
return new Response($this->string, 'rss');
136+
$response = new Response($this->string, 'rss');
129137
}
130138

131-
return new Response('Error: Feed Response', null, 500);
139+
return $response ?? new Response('Error: Feed Response', null, 500);
132140
}
133141

134142
public static function feed(Pages|Closure $pages, array $options = []): Response

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bnomei/kirby3-feed",
33
"type": "kirby-plugin",
4-
"version": "5.0.0",
4+
"version": "5.0.1",
55
"description": "Generate a Atom/JSON/RSS-Feed and XML-Sitemap from Pages-Collections",
66
"license": "MIT",
77
"authors": [

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/composer/installed.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php return array(
22
'root' => array(
33
'name' => 'bnomei/kirby3-feed',
4-
'pretty_version' => '5.0.0',
5-
'version' => '5.0.0.0',
4+
'pretty_version' => '5.0.1',
5+
'version' => '5.0.1.0',
66
'reference' => null,
77
'type' => 'kirby-plugin',
88
'install_path' => __DIR__ . '/../../',
@@ -11,8 +11,8 @@
1111
),
1212
'versions' => array(
1313
'bnomei/kirby3-feed' => array(
14-
'pretty_version' => '5.0.0',
15-
'version' => '5.0.0.0',
14+
'pretty_version' => '5.0.1',
15+
'version' => '5.0.1.0',
1616
'reference' => null,
1717
'type' => 'kirby-plugin',
1818
'install_path' => __DIR__ . '/../../',

0 commit comments

Comments
 (0)