Passed
Push — task/comment-feed ( 4588e4...75c509 )
by Yonathan
09:06 queued 18s
created

CommentController::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace App\Http\Controllers\Api;
4
5
use App\Http\Controllers\Controller;
6
use App\Http\Requests\StoreComment;
7
use App\Models\Comment;
8
use App\Models\JobPoster;
9
use Illuminate\Http\Request;
10
use Illuminate\Http\Resources\Json\JsonResource;
11
use Illuminate\Http\Resources\Json\ResourceCollection;
12
use Illuminate\Support\Facades\Log;
13
14
class CommentController extends Controller
15
{
16
    /**
17
     * Get the set of comments associated with a Job.
18
     *
19
     * @param JobPoster $jobPoster
20
     * @return \Illuminate\Http\Response
21
     */
22
    public function indexByJob(JobPoster $jobPoster)
23
    {
24
          $comments = Comment::where('job_poster_id', $jobPoster->id)->get();
25
          return response()->json(new ResourceCollection($comments));
26
    }
27
28
    /**
29
     * Store a newly created resource in storage
30
     *
31
     * @param \App\Http\Requests\StoreComment $request Incoming request.
32
     * @param  \App\Models\JobPoster          $jobPoster    Incoming Job Poster.
33
     * @return \Illuminate\Http\Response
34
     */
35
    public function store(StoreComment $request, JobPoster $jobPoster)
0 ignored issues
show
Unused Code introduced by
The parameter $jobPoster is not used and could be removed. ( Ignorable by Annotation )

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

35
    public function store(StoreComment $request, /** @scrutinizer ignore-unused */ JobPoster $jobPoster)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
    {
37
          $data = $request->validated();
38
          $comment = new Comment();
39
          $comment->fill($data);
40
          $comment->save();
41
          return response()->json(new JsonResource($comment));
42
    }
43
}
44