CommentifyServiceProvider::boot()   B
last analyzed

Complexity

Conditions 11
Paths 120

Size

Total Lines 78
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 10
Bugs 2 Features 3
Metric Value
cc 11
eloc 46
c 10
b 2
f 3
nc 120
nop 0
dl 0
loc 78
rs 7.15

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Usamamuneerchaudhary\Commentify\Providers;
4
5
use Illuminate\Support\Facades\Gate;
6
use Illuminate\Support\ServiceProvider;
7
use Livewire\Livewire;
8
use Usamamuneerchaudhary\Commentify\Http\Livewire\Comment;
9
use Usamamuneerchaudhary\Commentify\Http\Livewire\Comments;
10
use Usamamuneerchaudhary\Commentify\Http\Livewire\Like;
11
use Usamamuneerchaudhary\Commentify\Policies\CommentPolicy;
12
13
class CommentifyServiceProvider extends ServiceProvider
14
{
15
    public function register(): void
16
    {
17
        $this->app->bind(CommentPolicy::class, function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

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

17
        $this->app->bind(CommentPolicy::class, function (/** @scrutinizer ignore-unused */ $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
            return new CommentPolicy;
19
        });
20
21
        Gate::policy(\Usamamuneerchaudhary\Commentify\Models\Comment::class, CommentPolicy::class);
22
23
        $this->app->register(MarkdownServiceProvider::class);
24
    }
25
26
    public function boot(): void
27
    {
28
        if ($this->app->runningInConsole()) {
29
            // Publish config file
30
            $this->publishes([
31
                __DIR__.'/../../config/commentify.php' => config_path('commentify.php'),
32
            ], 'commentify-config');
33
34
            $this->publishes([
35
                __DIR__.'/../../tailwind.config.js' => base_path('tailwind.config.js'),
36
            ], 'commentify-tailwind-config');
37
38
            // Publish Tailwind views
39
            $this->publishes([
40
                __DIR__.'/../../resources/views/tailwind' => resource_path('views/vendor/commentify'),
41
            ], 'commentify-tailwind-views');
42
43
            // Publish Bootstrap views
44
            $this->publishes([
45
                __DIR__.'/../../resources/views/bootstrap' => resource_path('views/vendor/commentify'),
46
            ], 'commentify-bootstrap-views');
47
48
            // Only register Filament views for publishing if Filament is installed
49
            if (class_exists(\Filament\Facades\Filament::class)) {
0 ignored issues
show
Bug introduced by
The type Filament\Facades\Filament was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
50
                $this->publishes([
51
                    __DIR__.'/../../resources/views/filament' => resource_path('views/vendor/commentify'),
52
                ], 'commentify-filament-views');
53
            }
54
55
            // Publish language files
56
            $this->publishes([
57
                __DIR__.'/../../lang' => resource_path('../lang/vendor/commentify'),
58
            ], 'commentify-lang');
59
60
        }
61
62
        $migrationPath = realpath(__DIR__.'/../../database/migrations');
63
        if ($migrationPath && is_dir($migrationPath)) {
64
            $this->loadMigrationsFrom($migrationPath);
65
        }
66
67
        // Load views based on CSS framework
68
        $config = $this->app->make('config');
69
        $framework = $config->get('commentify.css_framework', 'tailwind');
70
71
        // Validate framework value
72
        if (! in_array($framework, ['tailwind', 'bootstrap'])) {
73
            $framework = 'tailwind';
74
        }
75
76
        $frameworkPath = __DIR__.'/../../resources/views/'.$framework;
77
78
        if (is_dir($frameworkPath)) {
79
            $this->loadViewsFrom($frameworkPath, 'commentify');
80
        } else {
81
            // Fallback to tailwind if framework directory doesn't exist
82
            $this->loadViewsFrom(__DIR__.'/../../resources/views/tailwind', 'commentify');
83
        }
84
85
        // Only load Filament views if Filament is installed
86
        if (class_exists(\Filament\Facades\Filament::class)) {
87
            $filamentPath = __DIR__.'/../../resources/views/filament';
88
            $filamentPathTailwind = __DIR__.'/../../resources/views/tailwind/filament';
89
            $filamentPathBootstrap = __DIR__.'/../../resources/views/bootstrap/filament';
90
91
            if (is_dir($filamentPath)) {
92
                $this->loadViewsFrom($filamentPath, 'commentify');
93
            } elseif (is_dir($filamentPathTailwind)) {
94
                $this->loadViewsFrom($filamentPathTailwind, 'commentify');
95
            } elseif (is_dir($filamentPathBootstrap)) {
96
                $this->loadViewsFrom($filamentPathBootstrap, 'commentify');
97
            }
98
        }
99
100
        $this->loadTranslationsFrom(__DIR__.'/../../lang', 'commentify');
101
        Livewire::component('comments', Comments::class);
102
        Livewire::component('comment', Comment::class);
103
        Livewire::component('like', Like::class);
104
    }
105
}
106