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

visavi / rotor / 27440345661

12 Jun 2026 08:11PM UTC coverage: 16.687% (+0.04%) from 16.644%
27440345661

push

github

visavi
Упростил Registry модулей, поправил метки в жалобах, улучшил подсветку комментария при переходе по якорю, улучшил отправку жалобы

6 of 41 new or added lines in 7 files covered. (14.63%)

2 existing lines in 2 files now uncovered.

960 of 5753 relevant lines covered (16.69%)

2.36 hits per line

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

36.0
/app/Http/Controllers/Admin/SpamController.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Http\Controllers\Admin;
6

7
use App\Classes\Registry;
8
use App\Classes\Validator;
9
use App\Models\Spam;
10
use Illuminate\Database\Eloquent\Relations\Relation;
11
use Illuminate\Http\JsonResponse;
12
use Illuminate\Http\Request;
13
use Illuminate\View\View;
14

15
class SpamController extends AdminController
16
{
17
    private array $types;
18
    private string $type;
19
    private array $total = [];
20

21
    /**
22
     * SpamController constructor.
23
     */
24
    public function __construct(Request $request)
3✔
25
    {
26
        $moduleTypes = [];
3✔
27
        foreach (Registry::$spamTypes as $morphName) {
3✔
NEW
28
            $moduleTypes[$morphName] = Registry::$labelTypes[$morphName] ?? $morphName;
×
29
        }
30

31
        $this->types = array_merge([
3✔
32
            'messages' => __('index.private_messages'),
3✔
33
            'comments' => __('main.comments'),
3✔
34
        ], $moduleTypes);
3✔
35

36
        $type = $request->input('type');
3✔
37

38
        $spam = Spam::query()
3✔
39
            ->selectRaw('relate_type, count(*) as total')
3✔
40
            ->groupBy('relate_type')
3✔
41
            ->pluck('total', 'relate_type')
3✔
42
            ->all();
3✔
43

44
        if ($type && isset($this->types[$type])) {
3✔
NEW
45
            $this->type = $type;
×
46
        } elseif ($spam) {
3✔
47
            $this->type = array_search(max($spam), $spam, true);
×
48
        } else {
49
            $this->type = array_key_first($this->types);
3✔
50
        }
51

52
        foreach ($this->types as $key => $value) {
3✔
53
            $this->total[$key] = $spam[$key] ?? 0;
3✔
54
        }
55
    }
56

57
    /**
58
     * Главная страница
59
     */
60
    public function index(): View
×
61
    {
62
        $type = $this->type;
×
63
        $types = $this->types;
×
64

65
        // У Message и Wall автор текста в связи author, у остальных моделей — user
NEW
66
        $model = Relation::getMorphedModel($type);
×
NEW
67
        $relateWith = $model && method_exists($model, 'author')
×
68
            ? 'relate.author'
×
69
            : 'relate.user';
×
70

71
        $records = Spam::query()
×
72
            ->where('relate_type', $type)
×
73
            ->orderByDesc('created_at')
×
74
            ->with(['user', $relateWith])
×
75
            ->paginate(setting('spamlist'))
×
76
            ->appends(['type' => $type]);
×
77

78
        $total = $this->total;
×
79

80
        return view('admin/spam/index', compact('records', 'total', 'type', 'types'));
×
81
    }
82

83
    /**
84
     * Удаление жалоб
85
     */
86
    public function delete(Request $request, Validator $validator): JsonResponse
×
87
    {
88
        $id = int($request->input('id'));
×
89

90
        $validator
×
91
            ->true($request->ajax(), __('validator.not_ajax'))
×
92
            ->notEmpty($id, __('validator.deletion'));
×
93

94
        if ($validator->isValid()) {
×
95
            $spam = Spam::query()->find($id);
×
96

97
            if ($spam) {
×
98
                $spam->delete();
×
99
            }
100

101
            return response()->json(['success' => true]);
×
102
        }
103

104
        return response()->json([
×
105
            'success' => false,
×
106
            'message' => current($validator->getErrors()),
×
107
        ]);
×
108
    }
109
}
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