Passed
Push — main ( 4834b9...990a94 )
by Usama
03:51
created

CommentifyServiceProvider   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 8
Bugs 2 Features 2
Metric Value
eloc 49
c 8
b 2
f 2
dl 0
loc 93
rs 10
wmc 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 9 1
B boot() 0 73 9
1
<?php
2
3
namespace Usamamuneerchaudhary\Commentify\Providers;
4
5
6
use Illuminate\Support\Facades\Gate;
7
use Illuminate\Support\ServiceProvider;
8
use Livewire\Livewire;
9
use Usamamuneerchaudhary\Commentify\Http\Livewire\Comment;
10
use Usamamuneerchaudhary\Commentify\Http\Livewire\Comments;
11
use Usamamuneerchaudhary\Commentify\Http\Livewire\Like;
12
use Usamamuneerchaudhary\Commentify\Policies\CommentPolicy;
13
14
class CommentifyServiceProvider extends ServiceProvider
15
{
16
    /**
17
     * @return void
18
     */
19
    public function register(): void
20
    {
21
        $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

21
        $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...
22
            return new CommentPolicy;
23
        });
24
25
        Gate::policy(\Usamamuneerchaudhary\Commentify\Models\Comment::class, CommentPolicy::class);
26
27
        $this->app->register(MarkdownServiceProvider::class);
28
    }
29
30
31
    /**
32
     * @return void
33
     */
34
    public function boot(): void
35
    {
36
        if ($this->app->runningInConsole()) {
37
            // Publish config file
38
            $this->publishes([
39
                __DIR__ . '/../../config/commentify.php' => config_path('commentify.php'),
40
            ], 'commentify-config');
41
42
            $this->publishes([
43
                __DIR__ . '/../../tailwind.config.js' => base_path('tailwind.config.js'),
44
            ], 'commentify-tailwind-config');
45
46
            // Publish Tailwind views
47
            $this->publishes([
48
                __DIR__ . '/../../resources/views/tailwind' => resource_path('views/vendor/commentify'),
49
            ], 'commentify-tailwind-views');
50
51
            // Publish Bootstrap views
52
            $this->publishes([
53
                __DIR__ . '/../../resources/views/bootstrap' => resource_path('views/vendor/commentify'),
54
            ], 'commentify-bootstrap-views');
55
56
            // Publish Filament views
57
            $this->publishes([
58
                __DIR__ . '/../../resources/views/filament' => resource_path('views/vendor/commentify'),
59
            ], 'commentify-filament-views');
60
61
            // Publish language files
62
            $this->publishes([
63
                __DIR__ . '/../../lang' => resource_path('../lang/vendor/commentify'),
64
            ], 'commentify-lang');
65
66
        }
67
68
        $migrationPath = realpath(__DIR__ . '/../../database/migrations');
69
        if ($migrationPath && is_dir($migrationPath)) {
70
            $this->loadMigrationsFrom($migrationPath);
71
        }
72
73
        // Load views based on CSS framework
74
        $config = $this->app->make('config');
75
        $framework = $config->get('commentify.css_framework', 'tailwind');
76
77
        // Validate framework value
78
        if (!in_array($framework, ['tailwind', 'bootstrap'])) {
79
            $framework = 'tailwind';
80
        }
81
82
        $frameworkPath = __DIR__ . '/../../resources/views/' . $framework;
83
84
        if (is_dir($frameworkPath)) {
85
            $this->loadViewsFrom($frameworkPath, 'commentify');
86
        } else {
87
            // Fallback to tailwind if framework directory doesn't exist
88
            $this->loadViewsFrom(__DIR__ . '/../../resources/views/tailwind', 'commentify');
89
        }
90
91
        $filamentPath = __DIR__ . '/../../resources/views/filament';
92
        $filamentPathTailwind = __DIR__ . '/../../resources/views/tailwind/filament';
93
        $filamentPathBootstrap = __DIR__ . '/../../resources/views/bootstrap/filament';
94
95
        if (is_dir($filamentPath)) {
96
            $this->loadViewsFrom($filamentPath, 'commentify');
97
        } elseif (is_dir($filamentPathTailwind)) {
98
            $this->loadViewsFrom($filamentPathTailwind, 'commentify');
99
        } elseif (is_dir($filamentPathBootstrap)) {
100
            $this->loadViewsFrom($filamentPathBootstrap, 'commentify');
101
        }
102
103
        $this->loadTranslationsFrom(__DIR__ . '/../../lang', 'commentify');
104
        Livewire::component('comments', Comments::class);
105
        Livewire::component('comment', Comment::class);
106
        Livewire::component('like', Like::class);
107
    }
108
}
109