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

Feed   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A feed() 0 23 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