ReOrderFieldCommandHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 2
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\FieldGenerator\Handler;
4
5
use Hechoenlaravel\JarvisFoundation\FieldGenerator\FieldModel;
6
7
/**
8
 * Class ReOrderFieldCommandHandler
9
 * @package Hechoenlaravel\JarvisFoundation\FieldGenerator\Handler
10
 */
11
class ReOrderFieldCommandHandler
12
{
13
    /**
14
     * @param $command
15
     * @return mixed
16
     */
17
    public function handle($command)
18
    {
19
        $order = 1;
20
        foreach ($command->fields as $field) {
21
            $f = FieldModel::find($field);
22
            $f->order = $order;
23
            $f->save();
24
            $order++;
25
        }
26
        return $field;
0 ignored issues
show
Bug introduced by
The variable $field seems to be defined by a foreach iteration on line 20. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
27
    }
28
}
29