DefaultTransition   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 10
c 0
b 0
f 0
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A handle() 0 7 1
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