Issues (185)

Http/Controllers/MessageTemplatesController.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests\PredefinedMessageUpdateRequest;
6
use App\Models\Candidate;
7
use App\Models\PredefinedMessage;
8
use App\Services\PredefinedMessageService;
9
use App\Utils\ContentParser;
10
use Illuminate\Http\Request;
11
use Illuminate\Support\Facades\Auth;
12
13
class MessageTemplatesController extends Controller
14
{
15
    public function list(Request $request)
16
    {
17
        $recruitment_id = $request->get('recruitment_id');
0 ignored issues
show
The method get() does not exist on Illuminate\Http\Request. ( Ignorable by Annotation )

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

17
        /** @scrutinizer ignore-call */ 
18
        $recruitment_id = $request->get('recruitment_id');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
18
        $messages = PredefinedMessage::where('recruitment_id', $recruitment_id)->get();
19
20
        return response()->json($messages);
21
    }
22
23
    public function update(PredefinedMessageUpdateRequest $request, $messageId)
24
    {
25
        $field = PredefinedMessageService::update($messageId, $request);
26
27
        return response()->json($field, 200);
28
    }
29
30
    public function getParsed(Request $request)
31
    {
32
        $candidateId = $request->get('candidate_id');
33
        $fromStageId = $request->get('from_stage_id');
34
        $toStageId = $request->get('to_stage_id');
35
        $candidate = Candidate::findOrFail($candidateId);
36
        $appointmentDateString = $request->get('appointment_date');
37
        $appointmentDate = new \DateTime($appointmentDateString);
38
39
        $predefinedMessage = PredefinedMessage::where('recruitment_id', $candidate->recruitment->id)->where('from_stage_id', $fromStageId)->where('to_stage_id', $toStageId)->first();
0 ignored issues
show
The property id does not seem to exist on Illuminate\Database\Eloquent\Relations\Relation.
Loading history...
40
41
        if (empty($predefinedMessage)) {
42
            $predefinedMessage = PredefinedMessage::where('recruitment_id', $candidate->recruitment->id)->where('from_stage_id', null)->where('to_stage_id', $toStageId)->first();
43
        }
44
45
        if (empty($predefinedMessage)) {
46
            return response()->json(null, 404);
47
        }
48
49
        $predefinedMessage->body = ContentParser::parse($predefinedMessage->body, $candidate, $appointmentDate, Auth::user());
50
        $predefinedMessage->subject = ContentParser::parse($predefinedMessage->subject, $candidate, $appointmentDate, Auth::user());
51
52
        return response()->json($predefinedMessage);
53
    }
54
}
55