StageChanger::changeStage()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 15
rs 9.9666
1
<?php
2
3
namespace App\Utils\Candidates;
4
5
use App\Events\CandidateStageChanged;
6
use App\Http\Requests\ChangeStageRequest;
7
use App\Models\Candidate;
8
use App\Utils\MessageService;
9
10
class StageChanger
11
{
12
    public static function changeStage(ChangeStageRequest $request)
13
    {
14
        $candidate = Candidate::findOrFail($request->get('candidate_id'));
0 ignored issues
show
Bug introduced by
The method get() does not exist on App\Http\Requests\ChangeStageRequest. ( Ignorable by Annotation )

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

14
        $candidate = Candidate::findOrFail($request->/** @scrutinizer ignore-call */ 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...
15
        $previousStage = $candidate->stage_id;
16
        $candidate->stage_id = $request->get('stage_id');
0 ignored issues
show
Bug introduced by
The property stage_id does not seem to exist on Illuminate\Database\Eloquent\Collection.
Loading history...
17
        $candidate->save();
18
19
        if ($candidate->wasChanged()) {
20
            if ($request->get('send_message')) {
21
                MessageService::sendMessage($candidate, $request);
22
            }
23
            event(new CandidateStageChanged($candidate, $previousStage, $candidate->stage_id));
24
        }
25
26
        return $candidate;
27
    }
28
}
29