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.

SafeUrlsServiceProvider   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Test Coverage

Coverage 91.18%

Importance

Changes 14
Bugs 7 Features 0
Metric Value
eloc 26
c 14
b 7
f 0
dl 0
loc 106
ccs 31
cts 34
cp 0.9118
rs 10
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 9 1
A register() 0 8 1
A mergeConfigFrom() 0 4 1
A provides() 0 3 1
A bootForConsole() 0 9 1
A mergeConfig() 0 17 5
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 36
    public function boot()
28
    {
29 36
        $this->publishes([
30 36
            __DIR__.'/../config/safe-urls.php' => config_path('safe-urls.php'),
31
        ]);
32
33
        // use the vendor configuration file as fallback
34 36
        $this->mergeConfigFrom(
35 36
            __DIR__.'/../config/safe-urls.php', 'safe-urls'
36
        );
37 36
    }
38
39
    /**
40
     * Register any package services.
41
     *
42
     * @return void
43
     */
44 36
    public function register()
45
    {
46
        // Register the service the package provides.
47
        $this->app->singleton('safe-urls', function () {
48
            return new SafeUrls();
49 36
        });
50
51 36
        $this->app->alias(SafeUrls::class, 'safe-urls');
52 36
    }
53
54
    /**
55
     * Get the services provided by the provider.
56
     *
57
     * @return array
58
     */
59 1
    public function provides()
60
    {
61 1
        return ['safe-urls'];
62
    }
63
64
    /**
65
     * Console-specific booting.
66
     *
67
     * @return void
68
     */
69 1
    public function bootForConsole()
70
    {
71
        // Publishing the configuration file.
72 1
        $this->publishes([
73 1
            __DIR__.'/../config/safe-urls.php' => config_path('safe-urls.php'),
74 1
        ], 'safe-urls');
75
76
        // Registering package commands.
77 1
        $this->commands(['safe-urls']);
78 1
    }
79
80
    /**
81
     * Merge the given configuration with the existing configuration.
82
     *
83
     * @param string $path
84
     * @param string $key
85
     *
86
     * @return void
87
     */
88 36
    protected function mergeConfigFrom($path, $key)
89
    {
90 36
        $config = $this->app['config']->get($key, []);
91 36
        $this->app['config']->set($key, $this->mergeConfig($config, require $path));
92 36
    }
93
94
    /**
95
     * Merges the configs together and takes multi-dimensional arrays into account.
96
     *
97
     * @param array $original
98
     * @param array $merging
99
     *
100
     * @return array
101
     */
102 36
    protected function mergeConfig(array $original, array $merging)
103
    {
104 36
        $array = array_merge($original, $merging);
105 36
        foreach ($original as $key => $value) {
106 1
            if (!is_array($value)) {
107 1
                continue;
108
            }
109 1
            if (!Arr::exists($merging, $key)) {
110
                continue;
111
            }
112 1
            if (is_numeric($key)) {
113
                continue;
114
            }
115 1
            $array[$key] = $this->mergeConfig($value, $merging[$key]);
116
        }
117
118 36
        return $array;
119
    }
120
}
121