Completed
Push — master ( 423a77...7e6e45 )
by Christopher
13:19
created

FriendsServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 96.3%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 7
c 3
b 1
f 0
lcom 1
cbo 1
dl 0
loc 72
rs 10
ccs 26
cts 27
cp 0.963

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A publishConfig() 0 7 1
A publishMigration() 0 15 3
A register() 0 4 1
A mergeConfig() 0 6 1
1
<?php
2
/**
3
 * This file is part of Friends.
4
 *
5
 * (c) Christopher Lass <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Arubacao\Friends;
11
12
use Illuminate\Support\ServiceProvider;
13
14
class FriendsServiceProvider extends ServiceProvider
15
{
16
    /**
17
     * Indicates if loading of the provider is deferred.
18
     *
19
     * @var bool
20
     */
21
    protected $defer = false;
22
23
    /**
24
     * Bootstrap the application events.
25
     *
26
     * @return void
27
     */
28 26
    public function boot()
29
    {
30 26
        $this->publishConfig();
31 26
        $this->publishMigration();
32 26
    }
33
34
    /**
35
     * Publish Friends configuration.
36
     */
37 26
    protected function publishConfig()
38
    {
39
        // Publish config files
40 26
        $this->publishes([
41 26
            __DIR__.'/../config/friends.php' => config_path('friends.php'),
42 26
        ]);
43 26
    }
44
45
    /**
46
     * Publish Friends migration.
47
     */
48 26
    protected function publishMigration()
49
    {
50 26
        if (class_exists('CreateFriendsTable')) {
51 25
            return;
52
        }
53
54 1
        $published_migration = glob(database_path('/migrations/*_create_friends_table.php'));
55 1
        if (count($published_migration) != 0) {
56
            return;
57
        }
58
59 1
        $stub = __DIR__.'/../database/migrations/2016_06_18_000000_create_friends_table.php';
60 1
        $target = database_path('/migrations/'.date('Y_m_d_His').'_create_friends_table.php');
61 1
        $this->publishes([$stub => $target], 'migrations');
62 1
    }
63
64
    /**
65
     * Register the service provider.
66
     *
67
     * @return void
68
     */
69 26
    public function register()
70
    {
71 26
        $this->mergeConfig();
72 26
    }
73
74
    /**
75
     * Merges user's and friends's configs.
76
     *
77
     * @return void
78
     */
79 26
    protected function mergeConfig()
80
    {
81 26
        $this->mergeConfigFrom(
82 26
            __DIR__.'/../config/friends.php', 'friends'
83 26
        );
84 26
    }
85
}
86