EditFieldCommandHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 23
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 15 2
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\FieldGenerator\Handler;
4
5
use Hechoenlaravel\JarvisFoundation\FieldGenerator\Events\FieldWasEdited;
6
use Hechoenlaravel\JarvisFoundation\FieldGenerator\FieldModel;
7
8
class EditFieldCommandHandler
9
{
10
    /**
11
     * Handle the creation of the Field in the Database
12
     * @param $command
13
     * @return static
14
     */
15
    public function handle($command)
16
    {
17
        $fields = (array) $command;
18
        $model = FieldModel::find($command->id);
19
        $rename = false;
20
        $oldSlug = $model->slug;
21
        if ($model->slug !== $command->slug) {
22
            $rename = true;
23
        }
24
        unset($fields['id']);
25
        $model->fill($fields);
26
        $model->save();
27
        event(new FieldWasEdited($model, $rename, $oldSlug));
28
        return $model;
29
    }
30
}
31