Passed
Push — feature/micro-ref-email ( 6f6312...e2ffc1 )
by Tristan
04:54
created

MicroReferenceController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers\Api;
4
5
use App\Http\Controllers\Controller;
6
use App\Mail\MicroReferenceMail;
7
use App\Models\ApplicationReview;
8
use App\Models\JobApplication;
9
use Illuminate\Support\Facades\Mail;
10
11
class MicroReferenceController extends Controller
12
{
13
14
    /**
15
     * Get all reference emails created for an application.
16
     *
17
     * @param JobApplication $application The application the references are for.
18
     *
19
     * @return \Illuminate\Http\Response
20
     */
21
    public function index(JobApplication $application)
22
    {
23
        $directorMail = new MicroReferenceMail($application, true);
24
        $referenceMail = new MicroReferenceMail($application, false);
25
        $mails = [
26
            'director' => $directorMail->build()->toArray(),
27
            'secondary' => $referenceMail->build()->toArray(),
28
        ];
29
        return response()->json($mails);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

29
        return /** @scrutinizer ignore-call */ response()->json($mails);
Loading history...
30
    }
31
32
    /**
33
     * Get email created to be sent to an application's Director reference.
34
     *
35
     * @param JobApplication $application The application the reference is for.
36
     *
37
     * @return \Illuminate\Http\Response
38
     */
39
    public function showDirectorEmail(JobApplication $application)
40
    {
41
        $mail = new MicroReferenceMail($application, true);
42
        return response()->json($mail->build()->toArray());
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

42
        return /** @scrutinizer ignore-call */ response()->json($mail->build()->toArray());
Loading history...
43
    }
44
45
    public function sendDirectorEmail(JobApplication $application)
46
    {
47
        $mail = new MicroReferenceMail($application, true);
48
        Mail::send($mail->build());
49
50
        $review = $application->application_review;
51
        if ($review === null) {
52
            $review = new ApplicationReview();
53
            $review->job_application()->associate($application);
54
        }
55
        $review->director_email_sent = true;
56
        $review->save();
57
58
        return response()->json($mail->build()->toArray());
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

58
        return /** @scrutinizer ignore-call */ response()->json($mail->build()->toArray());
Loading history...
59
    }
60
61
    /**
62
     * Get email created to be sent to an application's Secondary reference.
63
     *
64
     * @param JobApplication $application The application the reference is for.
65
     *
66
     * @return \Illuminate\Http\Response
67
     */
68
    public function showSecondaryReferenceEmail(JobApplication $application)
69
    {
70
        $mail = new MicroReferenceMail($application, false);
71
        return response()->json($mail->build()->toArray());
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

71
        return /** @scrutinizer ignore-call */ response()->json($mail->build()->toArray());
Loading history...
72
    }
73
74
    public function sendSecondaryReferenceEmail(JobApplication $application)
75
    {
76
        $mail = new MicroReferenceMail($application, false);
77
        Mail::send($mail->build());
78
79
        $review = $application->application_review;
80
        if ($review === null) {
81
            $review = new ApplicationReview();
82
            $review->job_application()->associate($application);
83
        }
84
        $review->reference_email_sent = true;
85
        $review->save();
86
87
        return response()->json($mail->build()->toArray());
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

87
        return /** @scrutinizer ignore-call */ response()->json($mail->build()->toArray());
Loading history...
88
    }
89
}
90