FeedServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 3
dl 0
loc 49
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
A registerRouteMacro() 0 12 2
A registerLinksComposer() 0 6 1
A boot() 0 14 1
A feeds() 0 4 1
1
<?php
2
3
namespace Spatie\Feed;
4
5
use Illuminate\Support\Facades\View;
6
use Illuminate\Support\ServiceProvider;
7
use Spatie\Feed\Helpers\Path;
8
use Spatie\Feed\Http\FeedController;
9
10
class FeedServiceProvider extends ServiceProvider
11
{
12
    public function boot()
13
    {
14
        $this->publishes([
15
            __DIR__.'/../config/feed.php' => config_path('feed.php'),
16
        ], 'config');
17
18
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'feed');
19
20
        $this->publishes([
21
            __DIR__.'/../resources/views' => resource_path('views/vendor/feed'),
22
        ], 'views');
23
24
        $this->registerLinksComposer();
25
    }
26
27
    public function register()
28
    {
29
        $this->mergeConfigFrom(__DIR__.'/../config/feed.php', 'feed');
30
31
        $this->registerRouteMacro();
32
    }
33
34
    protected function registerRouteMacro()
35
    {
36
        $router = $this->app['router'];
37
38
        $router->macro('feeds', function ($baseUrl = '') use ($router) {
39
            foreach (config('feed.feeds') as $name => $configuration) {
40
                $url = Path::merge($baseUrl, $configuration['url']);
41
42
                $router->get($url, '\\'.FeedController::class)->name("feeds.{$name}");
43
            }
44
        });
45
    }
46
47
    public function registerLinksComposer()
48
    {
49
        View::composer('feed::links', function ($view) {
50
            $view->with('feeds', $this->feeds());
51
        });
52
    }
53
54
    protected function feeds()
55
    {
56
        return collect(config('feed.feeds'));
57
    }
58
}
59