CommentifySettings::mount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Usamamuneerchaudhary\Commentify\Filament\Pages;
4
5
use Filament\Forms;
0 ignored issues
show
Bug introduced by
The type Filament\Forms 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...
6
use Filament\Forms\Concerns\InteractsWithForms;
0 ignored issues
show
Bug introduced by
The type Filament\Forms\Concerns\InteractsWithForms 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...
7
use Filament\Forms\Contracts\HasForms;
0 ignored issues
show
Bug introduced by
The type Filament\Forms\Contracts\HasForms 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...
8
use Filament\Forms\Form;
0 ignored issues
show
Bug introduced by
The type Filament\Forms\Form 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...
9
use Filament\Notifications\Notification;
0 ignored issues
show
Bug introduced by
The type Filament\Notifications\Notification 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...
10
use Filament\Pages\Page;
0 ignored issues
show
Bug introduced by
The type Filament\Pages\Page 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...
11
use Filament\Schemas\Components\Section;
0 ignored issues
show
Bug introduced by
The type Filament\Schemas\Components\Section 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...
12
use Filament\Schemas\Schema;
0 ignored issues
show
Bug introduced by
The type Filament\Schemas\Schema 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...
13
14
class CommentifySettings extends Page implements HasForms
15
{
16
    use InteractsWithForms;
17
18
    protected static string|null|\BackedEnum $navigationIcon = 'heroicon-o-cog-6-tooth';
0 ignored issues
show
Bug introduced by
The type BackedEnum 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...
19
20
21
    protected static string|null|\UnitEnum $navigationGroup = 'Commentify';
0 ignored issues
show
Bug introduced by
The type UnitEnum 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...
22
23
    protected static ?int $navigationSort = 10;
24
25
    public ?array $data = [];
26
27
    public static function getNavigationLabel(): string
28
    {
29
        return 'Commentify Settings';
30
    }
31
32
    public function getView(): string
33
    {
34
        return 'commentify::pages.settings';
35
    }
36
37
    public function form(Schema $schema): Schema
38
    {
39
        return $schema
40
            ->schema([
41
                Section::make('General Settings')
42
                    ->schema([
43
                        Forms\Components\Select::make('css_framework')
0 ignored issues
show
Bug introduced by
The type Filament\Forms\Components\Select 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...
44
                            ->label('CSS Framework')
45
                            ->options([
46
                                'tailwind' => 'Tailwind CSS',
47
                                'bootstrap' => 'Bootstrap',
48
                            ])
49
                            ->default('tailwind')
50
                            ->required()
51
                            ->helperText('Choose the CSS framework for comment components'),
52
                        Forms\Components\TextInput::make('users_route_prefix')
0 ignored issues
show
Bug introduced by
The type Filament\Forms\Components\TextInput 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...
53
                            ->label('Users Route Prefix')
54
                            ->default('users')
55
                            ->required(),
56
                        Forms\Components\TextInput::make('pagination_count')
57
                            ->label('Comments Per Page')
58
                            ->numeric()
59
                            ->default(10)
60
                            ->required(),
61
                        Forms\Components\Toggle::make('comment_nesting')
0 ignored issues
show
Bug introduced by
The type Filament\Forms\Components\Toggle 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...
62
                            ->label('Enable Comment Nesting')
63
                            ->default(true),
64
                        Forms\Components\Toggle::make('read_only')
65
                            ->label('Read Only Mode')
66
                            ->helperText('Disable all commenting functionality')
67
                            ->default(false),
68
                    ]),
69
                Section::make('Sorting & Display')
70
                    ->schema([
71
                        Forms\Components\Select::make('default_sort')
72
                            ->label('Default Sort Order')
73
                            ->options([
74
                                'newest' => 'Newest First',
75
                                'oldest' => 'Oldest First',
76
                                'most_liked' => 'Most Liked',
77
                                'most_replied' => 'Most Replied',
78
                            ])
79
                            ->default('newest')
80
                            ->required(),
81
                        Forms\Components\Toggle::make('enable_sorting')
82
                            ->label('Enable Sorting')
83
                            ->default(true),
84
                    ]),
85
                Section::make('Moderation')
86
                    ->schema([
87
                        Forms\Components\Toggle::make('enable_reporting')
88
                            ->label('Enable Comment Reporting')
89
                            ->default(true),
90
                        Forms\Components\TagsInput::make('report_reasons')
0 ignored issues
show
Bug introduced by
The type Filament\Forms\Components\TagsInput 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...
91
                            ->label('Report Reasons')
92
                            ->placeholder('Add report reason')
93
                            ->default(['spam', 'inappropriate', 'offensive', 'other']),
94
                    ]),
95
                Section::make('Features')
96
                    ->schema([
97
                        Forms\Components\Select::make('theme')
98
                            ->label('Theme Mode')
99
                            ->options([
100
                                'light' => 'Light',
101
                                'dark' => 'Dark',
102
                                'auto' => 'Auto (System Preference)',
103
                            ])
104
                            ->default('auto')
105
                            ->required(),
106
                        Forms\Components\Toggle::make('enable_emoji_picker')
107
                            ->label('Enable Emoji Picker')
108
                            ->default(true),
109
                    ]),
110
                Section::make('Notifications')
111
                    ->schema([
112
                        Forms\Components\Toggle::make('enable_notifications')
113
                            ->label('Enable Notifications')
114
                            ->default(false),
115
                        Forms\Components\CheckboxList::make('notification_channels')
0 ignored issues
show
Bug introduced by
The type Filament\Forms\Components\CheckboxList 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...
116
                            ->label('Notification Channels')
117
                            ->options([
118
                                'database' => 'Database',
119
                                'mail' => 'Email',
120
                                'broadcast' => 'Broadcast (WebSocket)',
121
                            ])
122
                            ->default(['database'])
123
                            ->visible(fn ($get) => $get('enable_notifications')),
124
                    ]),
125
            ])
126
            ->statePath('data');
127
    }
128
129
    public function mount(): void
130
    {
131
        $this->form->fill(config('commentify', []));
132
    }
133
134
    public function save(): void
135
    {
136
        $data = $this->form->getState();
137
138
        // Save to config file
139
        $configPath = config_path('commentify.php');
140
141
        if (file_exists($configPath)) {
142
            $config = require $configPath;
143
            $config = array_merge($config, $data);
144
145
            file_put_contents(
146
                $configPath,
147
                "<?php\n\nreturn " . var_export($config, true) . ";\n"
148
            );
149
150
            // Clear config cache
151
            if (function_exists('config')) {
152
                app()->make('config')->set('commentify', $config);
153
            }
154
        }
155
156
        Notification::make()
157
            ->title('Settings saved successfully')
158
            ->success()
159
            ->send();
160
    }
161
}
162
163