Completed
Push — master ( 27ad61...cd4f57 )
by Jolita
02:21
created

Feed::feed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 23
rs 9.0856
cc 1
eloc 15
nc 1
nop 1
1
<?php
2
3
namespace Spatie\Feed;
4
5
use Illuminate\Contracts\Foundation\Application;
6
use Illuminate\Http\Response as HttpResponse;
7
use Illuminate\Support\Facades\Response;
8
9
class Feed
10
{
11
    protected $app;
12
13
    public function __construct(Application $app)
14
    {
15
        $this->app = $app;
16
    }
17
18
    public function feed($feed) : HttpResponse
19
    {
20
        $data = [];
21
        $items = explode('@', $feed['items']);
22
        $method = $items[1];
23
24
        $data['items'] = $this->app->make($items[0])->$method()->map(function (FeedItem $item) {
25
            return $item->getFeedData();
26
        });
27
28
        $data['meta'] = [
29
            'link' => $feed['url'],
30
            'description' => $feed['description'],
31
            'title' => $feed['title'],
32
            'updated' => collect($data['items'])->sortBy('updated')->last()['updated']->format('Y-m-d H:i:s')
33
        ];
34
35
        return Response::view(
36
            'laravel-feed::feed',
37
            $data, 200,
38
            ['Content-Type' => 'application/atom+xml; chartset=UTF-8']
39
        );
40
    }
41
}
42