FavoritesController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 2
c 4
b 1
f 1
lcom 1
cbo 3
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A update() 0 13 2
1
<?php
2
3
namespace LearnParty\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use LearnParty\Http\Requests;
7
use LearnParty\Favorite;
8
use LearnParty\Video;
9
use Auth;
10
11
class FavoritesController extends Controller
12
{
13
    /**
14
     * Add a new favorite if it does not exist and
15
     * remove it if does exist
16
     *
17
     * @param  Request $request User request
18
     * @return array           favorite or unfavorite message
19
     */
20
    public function update(Request $request)
21
    {
22
        $request['user_id'] = Auth::user()->id;
23
        $favorite = Favorite::where('user_id', Auth::user()->id)
24
                       ->where('video_id', $request->input('video_id'))
25
                       ->get();
26
27
        if ($favorite->count() === 0) {
28
            return $this->videoRepository->favoriteVideo($request->all());
0 ignored issues
show
Documentation introduced by
$request->all() is of type array, but the function expects a object<LearnParty\Http\Repositories\Request>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
29
        }
30
31
        return $this->videoRepository->unFavoriteVideo($request->all());
0 ignored issues
show
Documentation introduced by
$request->all() is of type array, but the function expects a object<LearnParty\Http\Repositories\Request>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
32
    }
33
}
34