Skip to content

Commit 3e7af86

Browse files
freekmurzesebastiandedeyne
authored andcommitted
Code review (spatie#60)
* nitpicks * Apply fixes from StyleCI (spatie#59) * cs
1 parent e61cda9 commit 3e7af86

File tree

7 files changed

+24
-29
lines changed

7 files changed

+24
-29
lines changed

src/Exceptions/InvalidFeedItem.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class InvalidFeedItem extends Exception
99
{
1010
/** @var \Spatie\Feed\FeedItem|null */
11-
protected $subject;
11+
public $subject;
1212

1313
public static function notFeedable($subject)
1414
{
@@ -25,11 +25,6 @@ public static function missingField(FeedItem $subject, $field)
2525
return (new static("Field `{$field}` is required"))->withSubject($subject);
2626
}
2727

28-
public function getSubject()
29-
{
30-
return $this->subject;
31-
}
32-
3328
protected function withSubject()
3429
{
3530
$this->subject;

src/Feed.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Spatie\Feed;
44

55
use Illuminate\Http\Response;
6+
use Illuminate\Support\Collection;
67
use Spatie\Feed\Exceptions\InvalidFeedItem;
78
use Illuminate\Contracts\Support\Responsable;
89

@@ -25,7 +26,7 @@ public function __construct($title, $url, $resolver)
2526
$this->items = $this->resolveItems($resolver);
2627
}
2728

28-
public function toResponse($request)
29+
public function toResponse($request): Response
2930
{
3031
$meta = [
3132
'id' => url($this->url),
@@ -44,7 +45,7 @@ public function toResponse($request)
4445
]);
4546
}
4647

47-
protected function resolveItems($resolver)
48+
protected function resolveItems($resolver): Collection
4849
{
4950
$resolver = array_wrap($resolver);
5051

@@ -57,7 +58,7 @@ protected function resolveItems($resolver)
5758
});
5859
}
5960

60-
protected function castToFeedItem($feedable)
61+
protected function castToFeedItem($feedable): FeedItem
6162
{
6263
if (is_array($feedable)) {
6364
$feedable = new FeedItem($feedable);
@@ -84,7 +85,7 @@ protected function castToFeedItem($feedable)
8485
return $feedItem;
8586
}
8687

87-
protected function lastUpdated()
88+
protected function lastUpdated(): string
8889
{
8990
if ($this->items->isEmpty()) {
9091
return '';

src/Feedable.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
interface Feedable
66
{
77
/**
8-
* @return \Spatie\Feed\FeedItem
8+
* @return array|\Spatie\Feed\FeedItem
99
*/
1010
public function toFeedItem();
1111
}

src/Http/FeedController.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ public function __invoke()
1414

1515
$feed = $feeds[$name] ?? null;
1616

17-
if (! $feed) {
18-
abort(404);
19-
}
17+
abort_unless($feed, 404);
2018

2119
return new Feed($feed['title'], request()->url(), $feed['items']);
2220
}

tests/DummyRepository.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Spatie\Feed\Test;
44

5+
use Illuminate\Support\Collection;
6+
57
class DummyRepository
68
{
79
/** @var \Illuminate\Support\Collection */
@@ -18,7 +20,7 @@ public function __construct()
1820
]);
1921
}
2022

21-
public function getAll()
23+
public function getAll(): Collection
2224
{
2325
return $this->items;
2426
}

tests/FeedTest.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@
44

55
class FeedTest extends TestCase
66
{
7+
/** @var array */
78
protected $feedNames = ['feed1', 'feed2', 'feed3'];
89

910
/** @test */
1011
public function all_feeds_are_available_on_their_registered_routes()
1112
{
1213
collect($this->feedNames)->each(function (string $feedName) {
13-
$response = $this->call('GET', "/feedBaseUrl/{$feedName}");
14-
15-
$this->assertEquals(200, $response->getStatusCode());
14+
$this->get("/feedBaseUrl/{$feedName}")->assertStatus(200);
1615
});
1716
}
1817

1918
/** @test */
2019
public function all_feed_items_have_expected_data()
2120
{
2221
collect($this->feedNames)->each(function (string $feedName) {
23-
$generatedFeedContent = $this->call('GET', "/feedBaseUrl/{$feedName}")->getContent();
22+
$generatedFeedContent = $this->get("/feedBaseUrl/{$feedName}")->getContent();
2423

2524
$this->assertMatchesSnapshot($generatedFeedContent);
2625
});
@@ -29,7 +28,7 @@ public function all_feed_items_have_expected_data()
2928
/** @test */
3029
public function it_can_render_all_feed_links_via_a_view()
3130
{
32-
$feedLinksHtml = $this->call('GET', '/test-route')->getContent();
31+
$feedLinksHtml = $this->get('/test-route')->getContent();
3332

3433
$this->assertMatchesSnapshot($feedLinksHtml);
3534
}

tests/TestCase.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ protected function getEnvironmentSetUp($app)
3333
{
3434
$feed = [
3535
[
36-
'items' => 'Spatie\Feed\Test\DummyRepository@getAll',
37-
'url' => '/feed1',
38-
'title' => 'Feed 1',
36+
'items' => 'Spatie\Feed\Test\DummyRepository@getAll',
37+
'url' => '/feed1',
38+
'title' => 'Feed 1',
3939
'description' => 'This is feed 1 from the unit tests',
4040
],
4141
[
42-
'items' => 'Spatie\Feed\Test\DummyRepository@getAll',
43-
'url' => '/feed2',
44-
'title' => 'Feed 2',
42+
'items' => 'Spatie\Feed\Test\DummyRepository@getAll',
43+
'url' => '/feed2',
44+
'title' => 'Feed 2',
4545
'description' => 'This is feed 2 from the unit tests',
4646
],
4747
[
48-
'items' => ['Spatie\Feed\Test\DummyRepository@getAllWithArguments', 'first'],
49-
'url' => '/feed3',
50-
'title' => 'Feed 3',
48+
'items' => ['Spatie\Feed\Test\DummyRepository@getAllWithArguments', 'first'],
49+
'url' => '/feed3',
50+
'title' => 'Feed 3',
5151
'description' => 'This is feed 3 from the unit tests',
5252
],
5353
];

0 commit comments

Comments
 (0)