JobMailMessage::listing()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
ccs 8
cts 8
cp 1
cc 1
nc 1
nop 1
crap 1
1
<?php namespace JobApis\JobsToMail\Notifications\Messages;
2
3
use Illuminate\Notifications\Messages\MailMessage;
4
use JobApis\Jobs\Client\Job;
5
6
class JobMailMessage extends MailMessage
7
{
8
    public $jobListings = [];
9
    public $advertisement = null;
10
11
    /**
12
     * Add a Job listing to the notification
13
     *
14
     * @param  Job $job
15
     *
16
     * @return $this
17
     */
18 2
    public function listing(Job $job)
19
    {
20 2
        $this->jobListings[] = [
21 2
            'link' => $job->getUrl(),
22 2
            'title' => $this->getTitle($job->getTitle()),
23 2
            'company' => $this->getCompany($job->getCompanyName(), $job->getIndustry()),
24 2
            'location' => $this->getLocation($job->getLocation()),
25 2
            'date' => $this->getDate($job->getDatePosted()),
26
        ];
27 2
        return $this;
28
    }
29
30
    /**
31
     * Sets the advertisement to be shown in this message.
32
     *
33
     * @param null $name
34
     *
35
     * @return $this
36
     */
37 1
    public function advertisement($name = null)
38
    {
39 1
        $this->advertisement = $name;
40 1
        return $this;
41
    }
42
43
    /**
44
     * Get the data array for the mail message.
45
     *
46
     * @return array
47
     */
48 1
    public function data()
49
    {
50 1
        return array_merge(
51 1
            $this->toArray(),
52 1
            $this->viewData,
53
            [
54 1
                'jobListings' => $this->jobListings,
55 1
                'advertisement' => $this->advertisement,
56
            ]
57
        );
58
    }
59
60 2
    private function getTitle($title)
61
    {
62 2
        return $title ?: null;
63
    }
64
65 2
    private function getLocation($location)
66
    {
67 2
        return $location ? " in {$location}" : null;
68
    }
69
70 2
    private function getCompany($company, $industry = null)
71
    {
72 2
        $response = null;
73 2
        if ($company) {
74 1
            $response = " at {$company}";
75 1
            if ($industry == "Staffing") {
76
                $response .= " (Professional Recruiter)";
77
            }
78
        }
79 2
        return $response;
80
    }
81
82 2
    private function getDate($dateTime)
83
    {
84 2
        if (is_object($dateTime) && \DateTime::class == get_class($dateTime)) {
85 1
            return $dateTime->format('F j, Y');
86
        }
87 1
        return null;
88
    }
89
}
90