Issues (264)

app/Notifications/MentionNotification.php (6 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Notifications;
6
7
use Illuminate\Bus\Queueable;
8
use Illuminate\Contracts\Queue\ShouldQueue;
9
use Illuminate\Notifications\Notification;
10
use Xetaravel\Models\BlogArticle;
11
use Xetaravel\Models\BlogComment;
12
use Xetaravel\Models\DiscussPost;
13
use Xetaravel\Models\Model;
14
15
class MentionNotification extends Notification implements ShouldQueue
16
{
17
    use Queueable;
18
19
    /**
20
     * The model instance.
21
     *
22
     * @var Model
23
     */
24
    public Model $model;
25
26
    /**
27
     * Create a new notification instance.
28
     *
29
     * @param Model $model
30
     */
31
    public function __construct(Model $model)
32
    {
33
        $this->model = $model;
34
    }
35
36
    /**
37
     * Parse the instance of the model and build the array.
38
     *
39
     * @param array $data
40
     *
41
     * @return array
42
     */
43
    protected function parseInstance(array $data = []): array
44
    {
45
        $model = $this->model;
46
47
        switch (true) {
48
            case $model instanceof DiscussPost:
49
                $data['message'] = '<strong>@%s</strong> has mentioned your name in his post !';
50
                $data['link'] = $model->post_url;
0 ignored issues
show
The property post_url does not seem to exist on Xetaravel\Models\DiscussPost. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
51
52
                break;
53
54
            case $model instanceof BlogComment:
55
                $data['message'] = '<strong>@%s</strong> has mentioned your name in his comment !';
56
                $data['link'] = $model->comment_url;
0 ignored issues
show
The property comment_url does not seem to exist on Xetaravel\Models\BlogComment. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
57
58
                break;
59
60
            case $model instanceof BlogArticle:
61
                $data['message'] = '<strong>@%s</strong> has mentioned your name in his article !';
62
                $data['link'] = $model->show_url;
0 ignored issues
show
The property show_url does not seem to exist on Xetaravel\Models\BlogArticle. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
63
64
                break;
65
        }
66
        $data['message'] = sprintf($data['message'], $model->user->username);
0 ignored issues
show
The property user does not seem to exist on Xetaravel\Models\Model. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
67
68
        return $data;
69
    }
70
71
    /**
72
     * Get the notification's delivery channels.
73
     *
74
     * @param mixed $notifiable
75
     *
76
     * @return array
77
     */
78
    public function via(mixed $notifiable): array
0 ignored issues
show
The parameter $notifiable is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

78
    public function via(/** @scrutinizer ignore-unused */ mixed $notifiable): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
79
    {
80
        return ['database'];
81
    }
82
83
    /**
84
     * Get the array representation of the notification.
85
     *
86
     * @param mixed $notifiable
87
     *
88
     * @return array
89
     */
90
    public function toDatabase(mixed $notifiable): array
0 ignored issues
show
The parameter $notifiable is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

90
    public function toDatabase(/** @scrutinizer ignore-unused */ mixed $notifiable): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
91
    {
92
        return $this->parseInstance(['type' => 'mention']);
93
    }
94
}
95