MessagesController::templateParsedAjax()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 24
rs 9.8333
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Candidate;
6
use App\Models\Message;
7
use App\Models\PredefinedMessage;
8
use App\Models\StageMessageTemplate;
9
use App\Services\MessagesService;
0 ignored issues
show
Bug introduced by
The type App\Services\MessagesService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use App\Services\UtilsService;
0 ignored issues
show
Bug introduced by
The type App\Services\UtilsService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Illuminate\Http\Request;
12
13
class MessagesController extends Controller
14
{
15
    public function list(Request $request)
16
    {
17
        $candidateId = $request->get('candidate_id');
0 ignored issues
show
Bug introduced by
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
        $candidateId = $request->get('candidate_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
19
        if ($candidateId) {
20
            $messages = Message::where('candidate_id', $candidateId)->orderBy('created_at', 'ASC')->get();
21
        } else {
22
            $messages = Message::orderBy('id', 'ASC')->get();
23
        }
24
25
        return response()->json($messages);
26
    }
27
28
    public function templateParsedAjax(Request $request)
29
    {
30
        $candidate = Candidate::find($request->candidate_id);
0 ignored issues
show
Bug introduced by
The property candidate_id does not seem to exist on Illuminate\Http\Request.
Loading history...
31
32
        $hashSuffix = UtilsService::hashSuffix($request->candidate_id);
33
34
        $messageTemplate = PredefinedMessage::where('recruitment_id', $candidate->recruitment_id)->where('stage_id', $request->stage_id)->first();
0 ignored issues
show
Bug introduced by
The property recruitment_id does not exist on App\Models\Candidate. Did you mean recruitment?
Loading history...
Bug introduced by
The property stage_id does not seem to exist on Illuminate\Http\Request.
Loading history...
35
36
        if (!$messageTemplate) {
37
            $messageTemplate = StageMessageTemplate::where('stage_id', $request->stage_id)->first();
38
        }
39
40
        if (!$messageTemplate) {
41
            return response()->json([
42
                'subject' => $hashSuffix,
43
                'body'    => '',
44
            ]);
45
        }
46
47
        MessagesService::parseTemplate($messageTemplate, $candidate);
48
49
        return response()->json([
50
            'subject' => "$messageTemplate->subject $hashSuffix",
51
            'body'    => $messageTemplate->body,
52
        ]);
53
    }
54
55
    public function update(Request $request, $id)
56
    {
57
        $messageTemplate = PredefinedMessage::find($id);
58
        $messageTemplate->update($request->all());
0 ignored issues
show
Bug introduced by
The method all() 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

58
        $messageTemplate->update($request->/** @scrutinizer ignore-call */ all());

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...
59
60
        return 'OK';
61
    }
62
}
63