BlogCoreServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 2
c 3
b 1
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace CSlant\Blog\Core\Providers;
4
5
use Illuminate\Support\ServiceProvider;
6
7
class BlogCoreServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * Bootstrap services.
11
     *
12
     * @return void
13
     */
14
    public function boot(): void
15
    {
16
        $this->registerAssetLoading();
17
18
        $this->registerAssetPublishing();
19
    }
20
21
    /**
22
     * Register services.
23
     *
24
     * @return void
25
     */
26
    public function register(): void
27
    {
28
        $this->registerConfigs();
29
30
        $this->registerCommands();
31
    }
32
33
    /**
34
     * Get the services provided by the provider.
35
     *
36
     * @return null|array<string>
37
     */
38
    public function provides(): ?array
39
    {
40
        return ['blog-core'];
41
    }
42
43
    /**
44
     * @return void
45
     */
46
    protected function registerCommands(): void
47
    {
48
        $this->commands([
49
            \CSlant\Blog\Core\Commands\ListProvidersCommand::class,
50
            \CSlant\Blog\Core\Commands\CheckSqlModeCommand::class,
51
        ]);
52
    }
53
54
    /**
55
     * @return void
56
     */
57
    protected function registerAssetPublishing(): void
58
    {
59
        $configPath = __DIR__.'/../../config/blog-core.php';
60
        $this->publishes([
61
            $configPath => config_path('blog-core.php'),
62
        ], 'config');
63
64
        $this->publishes([
65
            __DIR__.'/../../lang' => resource_path('lang/packages/blog-core'),
66
        ], 'lang');
67
    }
68
69
    /**
70
     * @return void
71
     */
72
    protected function registerAssetLoading(): void
73
    {
74
        $routePath = __DIR__.'/../../routes/blog-core.php';
75
        if (file_exists($routePath)) {
76
            $this->loadRoutesFrom($routePath);
77
        }
78
79
        $this->loadTranslationsFrom(__DIR__.'/../../lang', 'blog-core');
80
    }
81
82
    /**
83
     * Register configs.
84
     *
85
     * @return void
86
     */
87
    protected function registerConfigs(): void
88
    {
89
        $configDir = __DIR__.'/../../config';
90
        $files = scandir($configDir);
91
92
        if ($files === false) {
93
            return;
94
        }
95
96
        foreach ($files as $file) {
97
            if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
98
                $configName = pathinfo($file, PATHINFO_FILENAME);
99
                $configPath = $configDir.'/'.$file;
100
101
                if (file_exists(config_path($configName.'.php'))) {
0 ignored issues
show
Bug introduced by
Are you sure $configName of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

101
                if (file_exists(config_path(/** @scrutinizer ignore-type */ $configName.'.php'))) {
Loading history...
102
                    config()->set($configName, array_merge(
0 ignored issues
show
Bug introduced by
The call to config() has too few arguments starting with string. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

102
                    /** @scrutinizer ignore-call */ 
103
                    config()->set($configName, array_merge(

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
103
                        is_array(config($configName)) ? config($configName) : [],
0 ignored issues
show
Bug introduced by
It seems like $configName can also be of type array; however, parameter $string of config() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

103
                        is_array(config(/** @scrutinizer ignore-type */ $configName)) ? config($configName) : [],
Loading history...
104
                        require $configPath
105
                    ));
106
                } else {
107
                    $this->mergeConfigFrom($configPath, $configName);
0 ignored issues
show
Bug introduced by
It seems like $configName can also be of type array; however, parameter $key of Illuminate\Support\Servi...ider::mergeConfigFrom() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

107
                    $this->mergeConfigFrom($configPath, /** @scrutinizer ignore-type */ $configName);
Loading history...
108
                }
109
            }
110
        }
111
    }
112
}
113