Completed
Pull Request — master (#108)
by Freek
57s
created

DefaultTransition   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 30
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\ModelStates;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class DefaultTransition extends Transition
8
{
9
    protected Model $model;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
10
11
    protected string $field;
12
13
    protected State $newState;
14
15
    public function __construct(
16
        Model $model,
17
        string $field,
18
        State $newState
19
    ) {
20
        $this->model = $model;
21
        $this->field = $field;
22
        $this->newState = $newState;
23
    }
24
25
    public function handle(): Model
26
    {
27
        $this->model->{$this->field} = $this->newState;
28
29
        $this->model->save();
30
31
        return $this->model;
32
    }
33
}
34