LoanTableUpdated::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 3
c 1
b 0
f 1
nc 2
nop 3
dl 0
loc 5
rs 10
1
<?php
2
3
namespace App\Events;
4
5
use App\Loan;
6
use Illuminate\Broadcasting\Channel;
7
use Illuminate\Http\Request;
8
use Illuminate\Queue\SerializesModels;
9
use Illuminate\Broadcasting\PrivateChannel;
10
use Illuminate\Broadcasting\PresenceChannel;
11
use Illuminate\Foundation\Events\Dispatchable;
12
use Illuminate\Broadcasting\InteractsWithSockets;
13
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
14
15
class LoanTableUpdated implements ShouldBroadcast
16
{
17
    use Dispatchable, InteractsWithSockets, SerializesModels;
0 ignored issues
show
introduced by
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by App\Events\LoanTableUpdated: $id, $relations, $class, $connection, $keyBy
Loading history...
18
19
    /**
20
     * Action to highlight
21
     *
22
     * @var string
23
     */
24
    public $action;
25
26
    /**
27
     * Loan to highlight
28
     *
29
     * @var string
30
     */
31
    public $loan;
32
33
    /**
34
     * Sender window
35
     *
36
     * @var string
37
     */
38
    public $sender;
39
40
    /**
41
     * Create a new event instance.
42
     *
43
     * @param string $action
44
     * @param Request $request
45
     * @param Loan|null $loan
46
     */
47
    public function __construct(string $action, Request $request, Loan $loan = null)
48
    {
49
        $this->action = $action;
50
        $this->sender = $request->headers->get('x-bibrex-window');
51
        $this->loan = $loan ? $loan->toArray() : null;
0 ignored issues
show
Documentation Bug introduced by
It seems like $loan ? $loan->toArray() : null can also be of type array. However, the property $loan is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
52
    }
53
54
    /**
55
     * Get the channels the event should broadcast on.
56
     *
57
     * @return \Illuminate\Broadcasting\Channel|array
58
     */
59
    public function broadcastOn()
60
    {
61
        $library = \Auth::user();
62
        return new PrivateChannel('loans.' . $library->id);
63
    }
64
}
65