Issues (28)

src/Events/TrackActivityEvent.php (1 issue)

1
<?php
2
3
namespace Sfneal\Tracking\Events;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Sfneal\Events\Event;
7
8
class TrackActivityEvent extends Event
9
{
10
    /**
11
     * @var Model
12
     */
13
    public $model;
14
15
    /**
16
     * @var array Array of model changes
17
     */
18
    public $model_changes;
19
20
    /**
21
     * Active user's ID.
22
     *
23
     * @var int|null
24
     */
25
    public $user_id;
26
27
    /**
28
     * @var string TrackTraffic token that associated traffic with activity
29
     */
30
    public $request_token;
31
32
    /**
33
     * @var string|null Requested route
34
     */
35
    public $route;
36
37
    /**
38
     * @var string|null Session flash message
39
     */
40
    public $description;
41
42
    /**
43
     * Create a new event instance.
44
     *
45
     * @param  Model  $model
46
     */
47
    public function __construct(Model $model)
48
    {
49
        // Get array of changes made to the model
50
        $this->model = $model;
51
        $this->model_changes = $this->model->getChanges();
52
53
        // Set user_id and request_token for associating with traffic tracking data
54
        $this->user_id = intval(auth()->id());
55
        $this->request_token = request()->get('track_traffic_token') ?? null;
56
57
        // Get the route name
58
        $this->route = request() && request()->route() ? (request()->route()->getName() ?? null) : null;
59
        $this->description = session('success') ?? null;
0 ignored issues
show
Documentation Bug introduced by
It seems like session('success') ?? null can also be of type Illuminate\Session\SessionManager or Illuminate\Session\Store. However, the property $description is declared as type null|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...
60
    }
61
}
62