NotesController::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Note;
6
use Illuminate\Http\Request;
7
8
class NotesController extends Controller
9
{
10
    public function get(Request $request)
11
    {
12
        $notes = Note::where('candidate_id', $request->get('candidate_id'))->with('user')->orderBy('created_at', 'ASC')->get();
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

12
        $notes = Note::where('candidate_id', $request->/** @scrutinizer ignore-call */ get('candidate_id'))->with('user')->orderBy('created_at', 'ASC')->get();

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...
13
14
        return response()->json($notes);
15
    }
16
17
    public function create(Request $request)
18
    {
19
        $note = new Note();
20
        $note->candidate_id = $request->candidate_id;
0 ignored issues
show
Bug introduced by
The property candidate_id does not exist on App\Models\Note. Did you mean candidate?
Loading history...
Bug introduced by
The property candidate_id does not seem to exist on Illuminate\Http\Request.
Loading history...
21
        $note->body = $request->body;
0 ignored issues
show
Bug introduced by
The property body does not seem to exist on Illuminate\Http\Request.
Loading history...
22
        $note->user_id = \Auth::id();
0 ignored issues
show
Bug introduced by
The property user_id does not exist on App\Models\Note. Did you mean user?
Loading history...
23
        $note->save();
24
25
        $note = Note::with('user')->find($note->id);
26
27
        return response()->json($note, 201, ['Location'=>'/notes/'.$note->id]);
28
    }
29
}
30