BatchController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 13
c 2
b 1
f 0
dl 0
loc 45
ccs 0
cts 12
cp 0
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A export() 0 9 1
A batch() 0 15 3
1
<?php
2
3
namespace Terranet\Administrator\Controllers;
4
5
use Illuminate\Contracts\Support\Renderable;
6
use Illuminate\Http\RedirectResponse;
7
use Symfony\Component\HttpFoundation\Response;
8
use Terranet\Administrator\AdminRequest;
9
10
class BatchController extends AdminController
11
{
12
    /**
13
     * Perform a batch action against selected collection.
14
     *
15
     * @param  AdminRequest  $request
16
     * @param  string  $page
17
     * @return RedirectResponse
18
     */
19
    public function batch(AdminRequest $request, string $page)
20
    {
21
        $resource = $request->resource();
22
23
        $this->authorize($action = $request->get('batch_action'), $model = $resource->model());
24
25
        $response = $resource->actions()->exec('batch::'.$action, [$model, $request]);
26
27
        if ($response instanceof Response || $response instanceof Renderable) {
28
            return $response;
29
        }
30
31
        return back()->with(
0 ignored issues
show
Bug introduced by
The function back was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
        return /** @scrutinizer ignore-call */ back()->with(
Loading history...
32
            'messages',
33
            [trans('administrator::messages.action_success')]
0 ignored issues
show
Bug introduced by
The function trans was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
            [/** @scrutinizer ignore-call */ trans('administrator::messages.action_success')]
Loading history...
34
        );
35
    }
36
37
    /**
38
     * Export collection.
39
     *
40
     * @param  AdminRequest  $request
41
     * @param  string  $page
42
     * @param  string  $format
43
     * @return mixed
44
     * @throws \Exception
45
     */
46
    public function export(AdminRequest $request, string $page, string $format)
47
    {
48
        $resource = $request->resource();
49
50
        $this->authorize('index', $resource->model());
51
52
        $query = $resource->finder()->getQuery();
0 ignored issues
show
Bug introduced by
The method getQuery() does not exist on Terranet\Administrator\Contracts\Services\Finder. Since it exists in all sub-types, consider adding an abstract or default implementation to Terranet\Administrator\Contracts\Services\Finder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
        $query = $resource->finder()->/** @scrutinizer ignore-call */ getQuery();
Loading history...
53
54
        return $resource->actions()->exec('export', [$query, $format]);
55
    }
56
}
57