Issues (17)

src/Events/StateChanged.php (3 issues)

1
<?php
2
3
namespace Spatie\ModelStates\Events;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Queue\SerializesModels;
7
use Spatie\ModelStates\State;
8
use Spatie\ModelStates\Transition;
9
10
class StateChanged
11
{
12
    use SerializesModels;
0 ignored issues
show
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by Spatie\ModelStates\Events\StateChanged: $id, $relations, $class, $connection, $keyBy
Loading history...
13
14
    /** @var \Spatie\ModelStates\State|null */
15
    public $initialState;
16
17
    /**
18
     * @var null
19
     * @deprecated
20
     * @see https://github.com/spatie/laravel-model-states/issues/49
21
     */
22
    public $finalState;
23
24
    /** @var \Spatie\ModelStates\Transition */
25
    public $transition;
26
27
    /** @var \Illuminate\Database\Eloquent\Model */
28
    public $model;
29
30
    public function __construct(
31
        ?State $initialState,
32
        ?State $finalState,
33
        Transition $transition,
34
        Model $model
35
    ) {
36
        $this->initialState = $initialState;
37
        $this->finalState = $finalState;
0 ignored issues
show
Deprecated Code introduced by
The property Spatie\ModelStates\Event...ateChanged::$finalState has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

37
        /** @scrutinizer ignore-deprecated */ $this->finalState = $finalState;
Loading history...
Documentation Bug introduced by
It seems like $finalState can also be of type Spatie\ModelStates\State. However, the property $finalState is declared as type null. 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...
38
        $this->transition = $transition;
39
        $this->model = $model;
40
    }
41
}
42