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

visavi / rotor / 27388066632

12 Jun 2026 01:15AM UTC coverage: 14.172%. Remained the same
27388066632

push

github

visavi
Исправил ошибки phpstan

0 of 36 new or added lines in 9 files covered. (0.0%)

4 existing lines in 3 files now uncovered.

816 of 5758 relevant lines covered (14.17%)

1.64 hits per line

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

0.0
/app/Http/Controllers/CommentController.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Http\Controllers;
6

7
use App\Classes\Validator;
8
use App\Models\Comment;
9
use App\Models\File;
10
use Illuminate\Database\Eloquent\Relations\Relation;
11
use Illuminate\Http\JsonResponse;
12
use Illuminate\Http\Request;
13

14
class CommentController extends Controller
15
{
16
    /**
17
     * Возвращает данные комментария для редактирования (текст + файлы)
18
     */
19
    public function show(int $id): JsonResponse
×
20
    {
21
        $comment = Comment::query()
×
22
            ->where('id', $id)
×
23
            ->where('user_id', getUser('id'))
×
24
            ->first();
×
25

26
        if (! $comment) {
×
27
            return response()->json(['files' => [], 'text' => '']);
×
28
        }
29

30
        $files = $comment->files->map(fn (File $file) => [
×
31
            'id'      => $file->id,
×
32
            'path'    => $file->path,
×
33
            'name'    => $file->name,
×
34
            'size'    => formatSize($file->size),
×
35
            'isImage' => $file->isImage(),
×
36
            'type'    => Comment::$morphName,
×
37
        ]);
×
38

39
        return response()->json(['files' => $files, 'text' => $comment->text]);
×
40
    }
41

42
    /**
43
     * Редактирует комментарий
44
     */
45
    public function update(int $id, Request $request, Validator $validator): JsonResponse
×
46
    {
47
        if (! $user = getUser()) {
×
48
            return response()->json(['success' => false, 'message' => __('main.not_authorized')]);
×
49
        }
50

51
        $msg = $request->input('msg');
×
52

53
        $comment = Comment::query()
×
54
            ->where('id', $id)
×
55
            ->where('user_id', $user->id)
×
56
            ->first();
×
57

58
        if (! $comment) {
×
59
            return response()->json(['success' => false, 'message' => __('main.comment_deleted')]);
×
60
        }
61

62
        if ($comment->created_at + 600 < SITETIME) {
×
63
            return response()->json(['success' => false, 'message' => __('main.editing_impossible')]);
×
64
        }
65

66
        $validator->length($msg, setting('comment_text_min'), setting('comment_text_max'), ['msg' => __('validator.text')]);
×
67

68
        $relate = $comment->relate;
×
NEW
69
        if ($relate && array_key_exists('closed', $relate->getAttributes()) && $relate->getAttribute('closed')) {
×
70
            return response()->json(['success' => false, 'message' => __('main.closed_comments')]);
×
71
        }
72

73
        if (! $validator->isValid()) {
×
74
            return response()->json(['success' => false, 'message' => current($validator->getErrors())]);
×
75
        }
76

77
        $comment->update(['text' => antimat($msg)]);
×
78

79
        return response()->json([
×
80
            'success' => true,
×
81
            'text'    => $comment->getText()->toHtml(),
×
82
        ]);
×
83
    }
84

85
    /**
86
     * Удаляет комментарий
87
     */
88
    public function destroy(int $id): JsonResponse
×
89
    {
90
        if (! isAdmin()) {
×
91
            return response()->json(['success' => false, 'message' => __('main.not_authorized')]);
×
92
        }
93

94
        $comment = Comment::query()->find($id);
×
95

96
        if (! $comment) {
×
97
            return response()->json(['success' => false, 'message' => __('main.comment_deleted')]);
×
98
        }
99

100
        $relateType = $comment->relate_type;
×
101
        $relateId = $comment->relate_id;
×
102

103
        if ($comment->children()->exists()) {
×
104
            $comment->softDelete();
×
105

106
            return response()->json(['success' => true, 'soft_deleted' => true]);
×
107
        }
108

109
        $comment->delete();
×
110

111
        $class = Relation::getMorphedModel($relateType);
×
112
        $model = $class::query()->find($relateId);
×
113
        if ($model) {
×
114
            $model->decrement('count_comments');
×
115
        }
116

117
        return response()->json(['success' => true, 'soft_deleted' => false]);
×
118
    }
119
}
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