Completed
Push — master ( 5da3c5...1ddebf )
by Manu
50:21 queued 35:23
created

PostController::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use App\Events\PostPublished;
7
use App\Post;
8
9
class PostController extends Controller {
10
11
  /**
12
   * Saves a new post to the database
13
   */
14
  public function store(Request $request) {
15
    // ...
16
    // validation can be done here before saving
17
    // with $this->validate($request, $rules)
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
18
    // ...
19
20
    // get data to save in an associative array using $request->only()
21
    $data = $request->only(['title', 'description']);
22
23
    //  save post and assign return value of created post to $post array
24
    $post = Post::create($data);
25
26
    // fire PostPublished event after post is successfully added to database
27
    event(new PostPublished($post));
28
    // or
29
    // \Event::fire(new PostPublished($post))
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
30
31
    // return post as response, Laravel automatically serializes this to JSON
32
    return response($post, 201);
33
  }
34
}
35