CommentifySettings::save()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 26
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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