ReOrderFieldCommandHandler::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 11
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 8
nc 2
nop 1
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