OrderStateTrait::postOrder()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 15
ccs 10
cts 10
cp 1
rs 9.9666
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Distilleries\Expendable\States;
4
5
use Illuminate\Http\Request;
6
7
trait OrderStateTrait
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12 2
    public function getOrder()
13
    {
14 2
        $rows = $this->model->orderBy($this->model->orderFieldName(), 'asc')->get();
15
16 2
        $this->layoutManager->add([
17 2
            'content' => view('expendable::admin.form.state.order', [
18 2
                'rows' => $rows,
19
            ]),
20
        ]);
21
22 2
        return $this->layoutManager->render();
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 2
    public function postOrder(Request $request)
29
    {
30 2
        $ids = $request->input('ids');
31
32 2
        $order = 1;
33 2
        foreach ($ids as $id) {
34 2
            $instance = $this->model->find($id);
35 2
            if (!empty($instance)) {
36 2
                $instance->{$this->model->orderFieldName()} = $order;
37 2
                $instance->save();
38 2
                $order++;
39
            }
40
        }
41
42 2
        return response()->json(['error' => false]);
43
    }
44
}
45