Passed
Pull Request — master (#16)
by Mateusz
06:02
created

NewDevice::toSlack()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 12
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace serwin35\AuthenticationLog\Notifications;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Notifications\Messages\MailMessage;
7
use Illuminate\Notifications\Messages\NexmoMessage;
0 ignored issues
show
Bug introduced by
The type Illuminate\Notifications\Messages\NexmoMessage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Illuminate\Notifications\Messages\SlackMessage;
0 ignored issues
show
Bug introduced by
The type Illuminate\Notifications\Messages\SlackMessage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Illuminate\Notifications\Notification;
10
use serwin35\AuthenticationLog\AuthenticationLog;
11
12
class NewDevice extends Notification
13
{
14
    use Queueable;
15
16
    /**
17
     * The authentication log.
18
     *
19
     * @var \serwin35\AuthenticationLog\AuthenticationLog
20
     */
21
    public $authenticationLog;
22
23
    /**
24
     * Create a new notification instance.
25
     *
26
     * @param  \serwin35\AuthenticationLog\AuthenticationLog  $authenticationLog
27
     * @return void
28
     */
29
    public function __construct(AuthenticationLog $authenticationLog)
30
    {
31
        $this->authenticationLog = $authenticationLog;
32
    }
33
34
    /**
35
     * Get the notification's delivery channels.
36
     *
37
     * @param  mixed  $notifiable
38
     * @return array
39
     */
40
    public function via($notifiable)
41
    {
42
        return $notifiable->notifyAuthenticationLogVia();
43
    }
44
45
    /**
46
     * Get the mail representation of the notification.
47
     *
48
     * @param  mixed  $notifiable
49
     * @return \Illuminate\Notifications\Messages\MailMessage
50
     */
51
    public function toMail($notifiable)
52
    {
53
        return (new MailMessage)
54
            ->subject(trans('authentication-log::messages.subject'))
0 ignored issues
show
Bug introduced by
It seems like trans('authentication-log::messages.subject') can also be of type array and array; however, parameter $subject of Illuminate\Notifications...impleMessage::subject() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

54
            ->subject(/** @scrutinizer ignore-type */ trans('authentication-log::messages.subject'))
Loading history...
55
            ->markdown('authentication-log::emails.new', [
56
                'account' => $notifiable,
57
                'time' => $this->authenticationLog->login_at,
0 ignored issues
show
Bug introduced by
The property login_at does not seem to exist on serwin35\AuthenticationLog\AuthenticationLog. 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...
58
                'ipAddress' => $this->authenticationLog->ip_address,
0 ignored issues
show
Bug introduced by
The property ip_address does not seem to exist on serwin35\AuthenticationLog\AuthenticationLog. 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...
59
                'browser' => $this->authenticationLog->user_agent,
0 ignored issues
show
Bug introduced by
The property user_agent does not seem to exist on serwin35\AuthenticationLog\AuthenticationLog. 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...
60
            ]);
61
    }
62
63
    /**
64
     * Get the Slack representation of the notification.
65
     *
66
     * @param  mixed  $notifiable
67
     * @return \Illuminate\Notifications\Messages\SlackMessage
68
     */
69
    public function toSlack($notifiable)
70
    {
71
        return (new SlackMessage)
72
            ->from(config('app.name'))
73
            ->warning()
74
            ->content(trans('authentication-log::messages.content', ['app' => config('app.name')]))
75
            ->attachment(function ($attachment) use ($notifiable) {
76
                $attachment->fields([
77
                    'Account' => $notifiable->email,
78
                    'Time' => $this->authenticationLog->login_at->toCookieString(),
0 ignored issues
show
Bug introduced by
The property login_at does not seem to exist on serwin35\AuthenticationLog\AuthenticationLog. 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...
79
                    'IP Address' => $this->authenticationLog->ip_address,
0 ignored issues
show
Bug introduced by
The property ip_address does not seem to exist on serwin35\AuthenticationLog\AuthenticationLog. 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...
80
                    'Browser' => $this->authenticationLog->user_agent,
0 ignored issues
show
Bug introduced by
The property user_agent does not seem to exist on serwin35\AuthenticationLog\AuthenticationLog. 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...
81
                ]);
82
            });
83
    }
84
85
    /**
86
     * Get the Nexmo / SMS representation of the notification.
87
     *
88
     * @param  mixed  $notifiable
89
     * @return \Illuminate\Notifications\Messages\NexmoMessage
90
     */
91
    public function toNexmo($notifiable)
0 ignored issues
show
Unused Code introduced by
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

91
    public function toNexmo(/** @scrutinizer ignore-unused */ $notifiable)

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...
92
    {
93
        return (new NexmoMessage)
94
            ->content(trans('authentication-log::messages.content', ['app' => config('app.name')]));
95
    }
96
}
97