Completed
Pull Request — master (#8)
by Karl
18:46 queued 16:09
created

JobMailMessage::getCompany()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 1
crap 2
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
10
    /**
11
     * Add a Job listing to the notification
12
     *
13
     * @param  Job $job
14
     *
15
     * @return $this
16
     */
17 2
    public function listing(Job $job)
18
    {
19 2
        $line = "";
20 2
        $line .= $this->getTitle($job->getTitle());
21 2
        $line .= $this->getCompany($job->getCompanyName());
22 2
        $line .= $this->getLocation($job->getLocation());
23 2
        $line .= ".";
24 2
        $this->jobListings[] = [
25 2
            'link' => $job->getUrl(),
26 2
            'text' => $line,
27 2
            'date' => $this->getDate($job->getDatePosted()),
28
        ];
29 2
        return $this;
30
    }
31
32
    /**
33
     * Get the data array for the mail message.
34
     *
35
     * @return array
36
     */
37 1
    public function data()
38
    {
39 1
        return array_merge(
40 1
            $this->toArray(),
41 1
            $this->viewData,
42 1
            ['jobListings' => $this->jobListings]
43
        );
44
    }
45
46 2
    private function getTitle($title)
47
    {
48 2
        return $title ?: null;
49
    }
50
51 2
    private function getLocation($location)
52
    {
53 2
        return $location ? " in {$location}" : null;
54
    }
55
56 2
    private function getCompany($company)
57
    {
58 2
        return $company ? " at {$company}" : null;
59
    }
60
61 2
    private function getDate($dateTime)
62
    {
63 2
        if (is_object($dateTime) && \DateTime::class == get_class($dateTime)) {
64 1
            return $dateTime->format('F j, Y');
65
        }
66 1
        return null;
67
    }
68
}
69