CommentController::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php 
2
3
namespace App\Http\Controllers;
4
5
use App\Comment;
6
7
class CommentController extends Controller{
8
9
	public function index(){
10
		
11
		$comments = Comment::all();
12
		return $this->success($comments, 200);
0 ignored issues
show
Bug introduced by
It seems like $comments defined by \App\Comment::all() on line 11 can also be of type object<Illuminate\Database\Eloquent\Collection>; however, App\Http\Controllers\Controller::success() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
13
	}
14
15
	public function show($id){
16
17
		$comment = Comment::find($id);
18
19
		if(!$comment){
20
			return $this->error("The comment with {$id} doesn't exist", 404);
21
		}
22
23
		return $this->success($comment, 200);
24
	}
25
}