DefaultTransition::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Spatie\ModelStates;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class DefaultTransition extends Transition
8
{
9
    /** @var \Illuminate\Database\Eloquent\Model */
10
    protected $model;
11
12
    /** @var string */
13
    protected $field;
14
15
    /** @var \Spatie\ModelStates\State */
16
    protected $newState;
17
18
    public function __construct(
19
        Model $model,
20
        string $field,
21
        State $newState
22
    ) {
23
        $this->model = $model;
24
        $this->field = $field;
25
        $this->newState = $newState;
26
    }
27
28
    public function handle()
29
    {
30
        $this->model->{$this->field} = $this->newState;
31
32
        $this->model->save();
33
34
        return $this->model;
35
    }
36
}
37