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

visavi / rotor / 28323582235

28 Jun 2026 01:20PM UTC coverage: 16.474% (+0.06%) from 16.419%
28323582235

push

github

visavi
Переход на datetime

19 of 66 new or added lines in 23 files covered. (28.79%)

9 existing lines in 8 files now uncovered.

984 of 5973 relevant lines covered (16.47%)

2.38 hits per line

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

0.0
/app/Http/Controllers/Admin/NoticeController.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Http\Controllers\Admin;
6

7
use App\Classes\Validator;
8
use App\Models\Notice;
9
use Illuminate\Http\RedirectResponse;
10
use Illuminate\Http\Request;
11
use Illuminate\View\View;
12

13
class NoticeController extends AdminController
14
{
15
    /**
16
     * Главная страница
17
     */
18
    public function index(): View
×
19
    {
20
        $notices = Notice::query()
×
21
            ->orderBy('id')
×
22
            ->with('user')
×
23
            ->get();
×
24

25
        return view('admin/notices/index', compact('notices'));
×
26
    }
27

28
    /**
29
     * Создание шаблона
30
     */
31
    public function create(Request $request, Validator $validator): View|RedirectResponse
×
32
    {
33
        if ($request->isMethod('post')) {
×
34
            $type = $request->input('type');
×
35
            $name = $request->input('name');
×
36
            $text = $request->input('text');
×
37
            $protect = empty($request->input('protect')) ? 0 : 1;
×
38

39
            $validator
×
40
                ->regex($type, '|^[a-z0-9_\-]+$|i', ['type' => 'Недопустимое название типа шаблона!'])
×
41
                ->length($type, 3, 20, ['type' => __('admin.notices.notice_length')])
×
42
                ->length($name, 5, 100, ['name' => __('validator.text')])
×
43
                ->length($text, 10, 65000, ['text' => __('validator.text')]);
×
44

45
            $duplicate = Notice::query()->where('type', $type)->first();
×
46
            $validator->empty($duplicate, ['type' => __('admin.notices.notice_exists')]);
×
47

48
            if ($validator->isValid()) {
×
49
                $notice = Notice::query()->create([
×
NEW
50
                    'type'    => $type,
×
NEW
51
                    'name'    => $name,
×
NEW
52
                    'text'    => $text,
×
NEW
53
                    'user_id' => getUser('id'),
×
NEW
54
                    'protect' => $protect,
×
UNCOV
55
                ]);
×
56

57
                setFlash('success', __('admin.notices.notice_success_saved'));
×
58

59
                return redirect('admin/notices/edit/' . $notice->id);
×
60
            }
61

62
            setInput($request->all());
×
63
            setFlash('danger', $validator->getErrors());
×
64
        }
65

66
        return view('admin/notices/create');
×
67
    }
68

69
    /**
70
     * Редактирование шаблона
71
     */
72
    public function edit(int $id, Request $request, Validator $validator): View|RedirectResponse
×
73
    {
74
        $notice = Notice::query()->find($id);
×
75

76
        if (! $notice) {
×
77
            abort(404, __('admin.notices.notice_not_found'));
×
78
        }
79

80
        if ($request->isMethod('post')) {
×
81
            $name = $request->input('name');
×
82
            $text = $request->input('text');
×
83
            $protect = empty($request->input('protect')) ? 0 : 1;
×
84

85
            $validator
×
86
                ->length($name, 5, 100, ['name' => __('validator.text')])
×
87
                ->length($text, 10, 65000, ['text' => __('validator.text')]);
×
88

89
            if ($validator->isValid()) {
×
90
                $notice->update([
×
NEW
91
                    'name'    => $name,
×
NEW
92
                    'text'    => $text,
×
NEW
93
                    'user_id' => getUser('id'),
×
NEW
94
                    'protect' => $protect,
×
UNCOV
95
                ]);
×
96

97
                setFlash('success', __('admin.notices.notice_success_saved'));
×
98

99
                return redirect('admin/notices/edit/' . $notice->id);
×
100
            }
101

102
            setInput($request->all());
×
103
            setFlash('danger', $validator->getErrors());
×
104
        }
105

106
        return view('admin/notices/edit', compact('notice'));
×
107
    }
108

109
    /**
110
     * Удаление шаблона
111
     */
112
    public function delete(int $id, Validator $validator): RedirectResponse
×
113
    {
114
        $notice = Notice::query()->find($id);
×
115

116
        $validator
×
117
            ->notEmpty($notice, __('admin.notices.notice_not_found'))
×
118
            ->empty($notice->protect, __('admin.notices.notice_protect'));
×
119

120
        if ($validator->isValid()) {
×
121
            $notice->delete();
×
122

123
            setFlash('success', __('admin.notices.notice_success_deleted'));
×
124
        } else {
125
            setFlash('danger', $validator->getErrors());
×
126
        }
127

128
        return redirect('admin/notices');
×
129
    }
130
}
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