ArticlesServiceProvider   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 1 Features 0
Metric Value
c 4
b 1
f 0
dl 0
loc 69
rs 10
wmc 11
lcom 1
cbo 2

9 Methods

Rating   Name   Duplication   Size   Complexity  
A loadCommands() 0 12 2
A defineWebRoutes() 0 4 1
A defineApiRoutes() 0 4 1
A registerEloquentFactoriesFrom() 0 4 1
A register() 0 7 2
A boot() 0 8 1
A defineRoutes() 0 5 1
A loadViews() 0 4 1
A loadMigrations() 0 4 1
1
<?php
2
3
namespace Ergare17\Articles\Providers;
4
5
use Ergare17\Articles\Console\Commands\CreateArticleCommand;
6
use Ergare17\Articles\Console\Commands\DeleteArticleCommand;
7
use Ergare17\Articles\Console\Commands\EditArticleCommand;
8
use Ergare17\Articles\Console\Commands\ListArticlesCommand;
9
use Ergare17\Articles\Console\Commands\ShowArticleCommand;
10
use Illuminate\Support\ServiceProvider;
11
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
12
13
class ArticlesServiceProvider extends ServiceProvider
14
{
15
    public function register()
16
    {
17
        if (!defined('ARTICLES_PATH')) {
18
            define('ARTICLES_PATH', realpath(__DIR__.'/../../'));
19
        }
20
        $this->registerEloquentFactoriesFrom(ARTICLES_PATH . '/database/factories');
21
    }
22
23
    public function boot()
24
    {
25
//        dump('Booting Articles package');
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
26
        $this->defineRoutes();
27
        $this->loadViews();
28
        $this->loadMigrations();
29
        $this->loadCommands();
30
    }
31
32
    protected function loadCommands()
33
    {
34
        if ($this->app->runningInConsole()) {
35
            $this->commands([
36
                CreateArticleCommand::class,
37
                ListArticlesCommand::class,
38
                DeleteArticleCommand::class,
39
                ShowArticleCommand::class,
40
                EditArticleCommand::class,
41
            ]);
42
        }
43
    }
44
45
    public function defineRoutes()
46
    {
47
        $this->defineWebRoutes();
48
        $this->defineApiRoutes();
49
    }
50
51
    public function defineWebRoutes()
52
    {
53
        require ARTICLES_PATH.'/routes/web.php';
54
    }
55
56
    public function defineApiRoutes()
57
    {
58
        require ARTICLES_PATH.'/routes/api.php';
59
    }
60
61
    private function loadViews()
62
    {
63
        $this->loadViewsFrom(ARTICLES_PATH.'/resources/views', 'articles');
64
    }
65
66
    private function loadMigrations()
67
    {
68
        $this->loadMigrationsFrom(ARTICLES_PATH.'/database/migrations');
69
    }
70
71
    /**
72
     * Register factories.
73
     *
74
     * @param  string  $path
75
     * @return void
76
     */
77
    protected function registerEloquentFactoriesFrom($path)
78
    {
79
        $this->app->make(EloquentFactory::class)->load($path);
80
    }
81
}
82