RepliesController::update()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Seongbae\Discuss\Http\Controllers;
4
5
6
use Illuminate\Http\Request;
7
use Seongbae\Discuss\Models\Thread;
8
use Seongbae\Discuss\Models\Channel;
9
use Illuminate\Support\Facades\Auth;
10
use Seongbae\Discuss\Models\Reply;
11
use App\Http\Controllers\Controller;
12
13
class RepliesController extends Controller
14
{
15
    /**
16
     * Create a new RepliesController instance.
17
     */
18
    public function __construct()
19
    {
20
        $this->middleware('auth');
21
    }
22
23
    /**
24
     * Persist a new reply.
25
     *
26
     * @param  Thread $thread
27
     * @return \Illuminate\Http\RedirectResponse
28
     */
29
    public function store(Request $request, Channel $channel, Thread $thread)
30
    {
31
        $this->validate(request(), [
32
            'body'=>'required'
33
        ]);
34
35
        $reply = $thread->addReply([
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $reply is correct as $thread->addReply(array(...st('subscribe') == '1') (which targets Seongbae\Discuss\Models\Thread::addReply()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
36
            'body' => request('body'),
37
            'user_id' => Auth::id(),
38
            'user_type' => $thread->user_type
39
        ], request('subscribe') == '1');
40
41
        if ($request->ajax())
42
            return $request->json([$reply], 200);
0 ignored issues
show
Documentation introduced by
array($reply) is of type array<integer,null,{"0":"null"}>, but the function expects a string|null.

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...
43
       else
44
            return redirect()->back();
45
    }
46
47
    /**
48
     * Update the specified resource in storage.
49
     *
50
     * @param  \Illuminate\Http\Request  $request
51
     * @param  \App\Thread  $thread
0 ignored issues
show
Bug introduced by
There is no parameter named $thread. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
52
     * @return \Illuminate\Http\Response
53
     */
54
    public function update(Request $request, Reply $reply)
55
    {
56
         $this->validate(request(), [
57
             'body'=>'required'
58
         ]);
59
60
        $reply->update(request(['body']));
61
62
        if ($request->ajax())
63
            return $request->json([$reply], 200);
0 ignored issues
show
Documentation introduced by
array($reply) is of type array<integer,object<Seo...cuss\\Models\\Reply>"}>, but the function expects a string|null.

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...
64
        else
65
            return redirect()->back();
66
    }
67
68
    /**
69
     * Remove the specified resource from storage.
70
     *
71
     * @param  \App\Thread  $thread
0 ignored issues
show
Bug introduced by
There is no parameter named $thread. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
72
     * @return \Illuminate\Http\Response
73
     */
74
    public function destroy(Reply $reply, Request $request)
75
    {
76
        $reply->delete();
77
78
        if ($request->ajax())
79
            return $request->json([], 200);
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string|null.

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...
80
        else
81
            return redirect()->back();
82
    }
83
}
84