GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b592f6...d63ed1 )
by Rob
03:19
created

SafeUrlsServiceProvider   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Importance

Changes 4
Bugs 2 Features 0
Metric Value
eloc 25
c 4
b 2
f 0
dl 0
loc 100
rs 10
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 5 1
A provides() 0 3 1
A bootForConsole() 0 9 1
A mergeConfig() 0 16 5
A boot() 0 9 1
A mergeConfigFrom() 0 4 1
1
<?php
2
3
namespace RattfieldNz\SafeUrls;
4
5
use Illuminate\Support\Arr;
6
use Illuminate\Support\ServiceProvider;
7
8
/**
9
 * Class SafeUrlsServiceProvider.
10
 *
11
 * @author Rob Attfield <[email protected]> <https://github.com/rattfieldnz>
12
 */
13
class SafeUrlsServiceProvider extends ServiceProvider
14
{
15
    /**
16
     * Indicates if loading of the provider is deferred.
17
     *
18
     * @var bool
19
     */
20
    protected $defer = false;
21
22
    /**
23
     * Perform post-registration booting of services.
24
     *
25
     * @return void
26
     */
27
    public function boot()
28
    {
29
        $this->publishes([
30
            __DIR__.'/../config/safe-urls.php' => config_path('safe-urls.php'),
31
        ]);
32
33
        // use the vendor configuration file as fallback
34
        $this->mergeConfigFrom(
35
            __DIR__.'/../config/safe-urls.php', 'safe-urls'
36
        );
37
    }
38
39
    /**
40
     * Register any package services.
41
     *
42
     * @return void
43
     */
44
    public function register()
45
    {
46
        // Register the service the package provides.
47
        $this->app->singleton('safe-urls', function () {
48
            return new SafeUrls();
49
        });
50
    }
51
52
    /**
53
     * Get the services provided by the provider.
54
     *
55
     * @return array
56
     */
57
    public function provides()
58
    {
59
        return ['safe-urls'];
60
    }
61
62
    /**
63
     * Console-specific booting.
64
     *
65
     * @return void
66
     */
67
    protected function bootForConsole()
68
    {
69
        // Publishing the configuration file.
70
        $this->publishes([
71
            __DIR__.'/../config/safe-urls.php' => config_path('SafeUrls.php'),
72
        ], 'safe-urls');
73
74
        // Registering package commands.
75
        $this->commands(['safe-urls']);
76
    }
77
78
    /**
79
     * Merge the given configuration with the existing configuration.
80
     *
81
     * @param  string  $path
82
     * @param  string  $key
83
     * @return void
84
     */
85
    protected function mergeConfigFrom($path, $key)
86
    {
87
        $config = $this->app['config']->get($key, []);
88
        $this->app['config']->set($key, $this->mergeConfig($config, require $path));
89
    }
90
    /**
91
     * Merges the configs together and takes multi-dimensional arrays into account.
92
     *
93
     * @param  array  $original
94
     * @param  array  $merging
95
     * @return array
96
     */
97
    protected function mergeConfig(array $original, array $merging)
98
    {
99
        $array = array_merge($original, $merging);
100
        foreach ($original as $key => $value) {
101
            if (! is_array($value)) {
102
                continue;
103
            }
104
            if (! Arr::exists($merging, $key)) {
105
                continue;
106
            }
107
            if (is_numeric($key)) {
108
                continue;
109
            }
110
            $array[$key] = $this->mergeConfig($value, $merging[$key]);
111
        }
112
        return $array;
113
    }
114
}
115