• 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/Models/Message.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Models;
6

7
use App\Casts\HtmlCast;
8
use App\Traits\ConvertVideoTrait;
9
use App\Traits\FileableTrait;
10
use App\Traits\UploadTrait;
11
use Carbon\CarbonImmutable;
12
use Illuminate\Database\Eloquent\Model;
13
use Illuminate\Database\Eloquent\Relations\BelongsTo;
14
use Illuminate\Database\Eloquent\Relations\HasMany;
15
use Illuminate\Support\Collection;
16
use Illuminate\Support\Facades\DB;
17
use Illuminate\Support\HtmlString;
18

19
/**
20
 * Class Message
21
 *
22
 * @property int             $id
23
 * @property int             $user_id
24
 * @property int             $author_id
25
 * @property string          $text
26
 * @property CarbonImmutable $created_at
27
 * @property-read User $user
28
 * @property-read User $author
29
 * @property-read Collection<File> $files
30
 * @property-read Collection<Dialogue> $dialogues
31
 */
32
class Message extends Model
33
{
34
    use FileableTrait;
35
    use ConvertVideoTrait;
36
    use UploadTrait;
37

38
    public const string IN = 'in'; // Принятые
39
    public const string OUT = 'out'; // Отправленные
40

41
    /**
42
     * The name of the "updated at" column.
43
     */
44
    public const ?string UPDATED_AT = null;
45

46
    /**
47
     * The attributes that aren't mass assignable.
48
     */
49
    protected $guarded = [];
50

51
    /**
52
     * Morph name
53
     */
54
    public static string $morphName = 'messages';
55

56
    /**
57
     * Директория загрузки файлов
58
     */
59
    public string $uploadPath = '/uploads/messages';
60

61
    /**
62
     * Get the attributes that should be cast.
63
     */
64
    protected function casts(): array
×
65
    {
66
        return [
×
67
            'user_id' => 'int',
×
68
            'text'    => HtmlCast::class,
×
69
        ];
×
70
    }
71

72
    /**
73
     * Get text
74
     */
75
    public function getText(): HtmlString
×
76
    {
77
        return renderHtml($this->text, 'message-' . $this->id);
×
78
    }
79

80
    /**
81
     * Возвращает связь пользователя
82
     */
83
    public function user(): BelongsTo
×
84
    {
85
        return $this->belongsTo(User::class, 'user_id')->withDefault();
×
86
    }
87

88
    /**
89
     * Возвращает связь владельца
90
     */
91
    public function author(): BelongsTo
×
92
    {
93
        return $this->belongsTo(User::class, 'author_id')->withDefault();
×
94
    }
95

96
    /**
97
     * Возвращает связь с диалогами
98
     */
99
    public function dialogues(): HasMany
×
100
    {
101
        return $this->hasMany(Dialogue::class);
×
102
    }
103

104
    /**
105
     * Create dialogue
106
     */
107
    public function createDialogue(User $user, ?User $author, string $text, bool $withAuthor): self
×
108
    {
109
        $authorId = $author->id ?? 0;
×
110

111
        $message = self::query()->create([
×
NEW
112
            'user_id'   => $user->id,
×
NEW
113
            'author_id' => $authorId,
×
NEW
114
            'text'      => $text,
×
UNCOV
115
        ]);
×
116

117
        Dialogue::query()->create([
×
118
            'message_id' => $message->id,
×
119
            'user_id'    => $user->id,
×
120
            'author_id'  => $authorId,
×
121
            'type'       => self::IN,
×
122
        ]);
×
123

124
        if ($authorId && $withAuthor) {
×
125
            Dialogue::query()->create([
×
126
                'message_id' => $message->id,
×
127
                'user_id'    => $authorId,
×
128
                'author_id'  => $user->id,
×
129
                'type'       => self::OUT,
×
130
                'reading'    => 1,
×
131
            ]);
×
132
        }
133

134
        $user->increment('newprivat');
×
135

136
        return $message;
×
137
    }
138

139
    /**
140
     * Удаление сообщения и загруженных файлов
141
     */
142
    public function delete(): ?bool
×
143
    {
144
        return DB::transaction(function () {
×
145
            $this->files->each(static function (File $file) {
×
146
                $file->delete();
×
147
            });
×
148

149
            return parent::delete();
×
150
        });
×
151
    }
152
}
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