• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SameOldNick / SameOldWebsite / 20218987083

15 Dec 2025 02:57AM UTC coverage: 87.51% (-0.2%) from 87.681%
20218987083

push

github

SameOldNick
Set default value for topic in fromArray method

The fromArray method now assigns an empty string as the default value for 'topic' if it is not present in the input array. This prevents potential undefined index errors.

1 of 1 new or added line in 1 file covered. (100.0%)

117 existing lines in 10 files now uncovered.

28509 of 32578 relevant lines covered (87.51%)

696.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/Http/Controllers/Api/Backup/BackupSettingsController.php
1
<?php
2

3
namespace App\Http\Controllers\Api\Backup;
4

5
use App\Components\Backup\Enums\NotificationChannels;
6
use App\Http\Controllers\Controller;
7
use App\Models\BackupConfig;
8
use App\Rules\CronExpression;
9
use Illuminate\Http\Request;
10
use Illuminate\Support\Arr;
11
use Illuminate\Validation\Rule;
12

13
class BackupSettingsController extends Controller
14
{
15
    public function __construct()
16
    {
UNCOV
17
        $this->middleware('can:role-manage-backups');
×
18
    }
19

20
    /**
21
     * Displays backup settings.
22
     */
23
    public function show()
24
    {
25
        // Fetch current values
26
        $keys = [
×
27
            'notification_channel',
×
28
            'notification_to_email',
×
29
            'notification_from_email',
×
30
            'notification_from_name',
×
31
            'notification_discord_webhook',
×
32
            'notification_discord_username',
×
33
            'notification_discord_avatar_url',
×
34
            'notification_slack_webhook',
×
35
            'notification_slack_username',
×
36
            'notification_slack_icon',
×
37
            'notification_slack_channel',
×
38
            'backup_cron',
×
39
            'cleanup_cron',
×
UNCOV
40
        ];
×
41

UNCOV
42
        return response()->json(BackupConfig::whereIn('key', $keys)->get());
×
43
    }
44

45
    /**
46
     * Updates backup settings
47
     */
48
    public function update(Request $request)
49
    {
UNCOV
50
        $channels = $request->collect('notification_channel');
×
51

52
        $validated = $request->validate([
×
53
            'notification_channel' => 'nullable|array',
×
UNCOV
54
            'notification_channel.*' => Rule::enum(NotificationChannels::class),
×
55

56
            'notification_to_email' => [Rule::requiredIf($channels->contains(NotificationChannels::Mail)), 'nullable', 'array'],
×
57
            'notification_to_email.*' => 'email',
×
58
            'notification_from_email' => [Rule::requiredIf($channels->contains(NotificationChannels::Mail)), 'nullable', 'email'],
×
UNCOV
59
            'notification_from_name' => [Rule::requiredIf($channels->contains(NotificationChannels::Mail)), 'nullable', 'string', 'max:255'],
×
60

61
            'notification_discord_webhook' => [Rule::requiredIf($channels->contains(NotificationChannels::Discord)), 'nullable', 'url:http,https', 'max:255'],
×
62
            'notification_discord_username' => [Rule::requiredIf($channels->contains(NotificationChannels::Discord)), 'nullable', 'string', 'max:255'],
×
UNCOV
63
            'notification_discord_avatar_url' => ['nullable', 'url:http,https', 'max:255'],
×
64

65
            'notification_slack_webhook' => [Rule::requiredIf($channels->contains(NotificationChannels::Slack)), 'nullable', 'url:http,https', 'max:255'],
×
66
            'notification_slack_username' => [Rule::requiredIf($channels->contains(NotificationChannels::Slack)), 'nullable', 'string', 'max:255'],
×
67
            'notification_slack_icon' => ['nullable', 'string', 'max:255'],
×
UNCOV
68
            'notification_slack_channel' => [Rule::requiredIf($channels->contains(NotificationChannels::Slack)), 'nullable', 'string', 'max:255'],
×
69

70
            'notification_ntfy_topic' => [Rule::requiredIf($channels->contains(NotificationChannels::Ntfy)), 'nullable', 'string', 'max:255'],
×
71

UNCOV
72
            'backup_cron' => ['nullable', 'string', new CronExpression],
×
73
            'cleanup_cron' => ['nullable', 'string', new CronExpression],
×
74
        ]);
×
75

76
        foreach (Arr::except($validated, ['notification_channel', 'notification_to_email', 'backup_cron', 'cleanup_cron']) as $key => $value) {
×
77
            BackupConfig::updateOrCreate(
×
UNCOV
78
                ['key' => $key],
×
UNCOV
79
                ['value' => $value ?? '']
×
80
            );
×
81
        }
82

83
        foreach (['notification_channel', 'notification_to_email'] as $key) {
×
UNCOV
84
            BackupConfig::updateOrCreateArrayValue($key, function () use ($key, $validated) {
×
UNCOV
85
                return $validated[$key] ?? [];
×
86
            });
×
87
        }
88

89
        foreach (['backup_cron', 'cleanup_cron'] as $key) {
×
90
            if (isset($validated[$key])) {
×
91
                BackupConfig::updateOrCreate(
×
UNCOV
92
                    ['key' => $key],
×
93
                    ['value' => $validated[$key]]
×
UNCOV
94
                );
×
95
            } else {
UNCOV
96
                BackupConfig::where('key', $key)->delete();
×
97
            }
98
        }
99

UNCOV
100
        return BackupConfig::all();
×
101
    }
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc