Completed
Push — master ( 82fb75...b618f7 )
by Karl
10s
created

JobsCollected::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php namespace JobApis\JobsToMail\Notifications;
2
3
use Illuminate\Bus\Queueable;
4
use Illuminate\Notifications\Notification;
5
use Illuminate\Contracts\Queue\ShouldQueue;
6
use Illuminate\Queue\SerializesModels;
7
use JobApis\JobsToMail\Models\Search;
8
use JobApis\JobsToMail\Notifications\Messages\JobMailMessage;
9
10
class JobsCollected extends Notification implements ShouldQueue
11
{
12
    use Queueable, SerializesModels;
13
14
    /**
15
     * @var array of Job objects
16
     */
17
    protected $jobs;
18
19
    /**
20
     * @var Search
21
     */
22
    protected $search;
23
24
    /**
25
     * Create a new notification instance.
26
     *
27
     * @param array $jobs
28
     * @param Search $search
29
     *
30
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
31
     */
32 8
    public function __construct(array $jobs, Search $search)
33
    {
34 8
        $this->jobs = $jobs;
35 8
        $this->search = $search;
36 8
    }
37
38
    /**
39
     * Get the notification's delivery channels.
40
     *
41
     * @param  mixed  $notifiable
42
     * @return array
43
     */
44 1
    public function via($notifiable)
0 ignored issues
show
Unused Code introduced by
The parameter $notifiable is not used and could be removed.

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

Loading history...
45
    {
46 1
        return ['mail', 'database'];
47
    }
48
49
    /**
50
     * Get the array representation of the notification for saving to the database.
51
     *
52
     * @param  mixed  $notifiable
53
     * @return array
54
     */
55 1
    public function toArray($notifiable)
0 ignored issues
show
Unused Code introduced by
The parameter $notifiable is not used and could be removed.

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

Loading history...
56
    {
57 1
        return $this->jobs;
58
    }
59
60
    /**
61
     * Get the mail representation of the notification.
62
     *
63
     * @param  mixed  $notifiable
64
     * @return \Illuminate\Notifications\Messages\MailMessage
65
     */
66 1
    public function toMail($notifiable)
67
    {
68 1
        $count = count($this->jobs);
69 1
        $message = new JobMailMessage();
70 1
        $message->viewData['user_id'] = $notifiable->id;
71 1
        $message->subject($count.' job listings found especially for you')
72 1
            ->greeting('Hello,')
73 1
            ->line('We found the following jobs that we think you\'ll be interested in based on your search:')
74 1
            ->line("\"{$this->search->keyword}\" in \"{$this->search->location}\"");
75 1
        foreach ($this->jobs as $job) {
76 1
            $message->listing($job);
77
        }
78 1
        return $message;
79
    }
80
}
81