LinkController::destroy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace Larafolio\Http\Controllers;
4
5
use Larafolio\Models\Link;
6
use Illuminate\Http\Request;
7
use Larafolio\Http\HttpValidator\HttpValidator;
8
9
class LinkController extends Controller
10
{
11
    /**
12
     * Remove a link.
13
     *
14
     * @param Link $link Link to remove.
15
     *
16
     * @return \Illuminate\Http\JsonResponse
17
     */
18
    public function destroy(Link $link)
19
    {
20
        $deleted = $this->user->removeLink($link);
21
22
        return response()->json($deleted);
23
    }
24
25
    /**
26
     * Check the status of a link and return json http code.
27
     *
28
     * @param Request       $request       Http request with 'url'.
29
     * @param HttpValidator $httpValidator Instance of http validator class.
30
     *
31
     * @return \Illuminate\Http\JsonResponse
32
     */
33
    public function check(Request $request, HttpValidator $httpValidator)
34
    {
35
        $url = $request->input('url');
36
37
        $httpCode = $httpValidator->validate($url);
1 ignored issue
show
Bug introduced by
It seems like $url defined by $request->input('url') on line 35 can also be of type array; however, Larafolio\Http\HttpValid...tpValidator::validate() does only seem to accept string, 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...
38
39
        return response()->json(['httpCode' => $httpCode]);
40
    }
41
}
42