Completed
Push — master ( d61877...118139 )
by Ryan
08:24
created

Reorder::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 23
rs 9.0856
cc 3
eloc 10
nc 3
nop 2
1
<?php namespace Anomaly\Streams\Platform\Ui\Table\Component\Action\Handler;
2
3
use Anomaly\Streams\Platform\Model\EloquentModel;
4
use Anomaly\Streams\Platform\Ui\Table\Component\Action\ActionHandler;
5
use Anomaly\Streams\Platform\Ui\Table\TableBuilder;
6
use Illuminate\Contracts\Bus\SelfHandling;
7
use Illuminate\Http\Request;
8
9
/**
10
 * Class ReorderActionHandler
11
 *
12
 * @link          http://anomaly.is/streams-platform
13
 * @author        AnomalyLabs, Inc. <[email protected]>
14
 * @author        Ryan Thompson <[email protected]>
15
 * @package       Anomaly\Streams\Platform\Ui\Table\Component\Action\Handler
16
 */
17
class Reorder extends ActionHandler implements SelfHandling
18
{
19
20
    /**
21
     * Save the order of the entries.
22
     *
23
     * @param TableBuilder $builder
24
     * @param Request      $request
25
     */
26
    public function handle(TableBuilder $builder, Request $request)
27
    {
28
        $count = 0;
29
30
        $model = $builder->getTableModel();
31
32
        /* @var EloquentModel $entry */
33
        foreach ($request->get($builder->getTableOption('prefix') . 'order', []) as $k => $id) {
34
35
            if ($entry = $model->find($id)) {
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<Anomaly\Streams\P...rm\Model\EloquentModel>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
36
37
                $entry->sort_order = $k + 1;
38
39
                $entry->save();
40
41
                $count++;
42
            }
43
        }
44
45
        $builder->fire('reordered', compact('count', 'builder'));
46
47
        $this->messages->success(trans('streams::message.reorder_success', compact('count')));
48
    }
49
}
50