Completed
Push — master ( a19a47...15bbc5 )
by Arjay
15:59
created

ExtensionsController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 9.4285
1
<?php
2
3
namespace Yajra\CMS\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Yajra\CMS\DataTables\ExtensionsDataTable;
7
use Yajra\CMS\Repositories\Extension\Repository;
8
9
class ExtensionsController extends Controller
10
{
11
    /**
12
     * @var \Yajra\CMS\Repositories\Extension\Repository
13
     */
14
    protected $repository;
15
16
    /**
17
     * ExtensionsController constructor.
18
     *
19
     * @param \Yajra\CMS\Repositories\Extension\Repository $repository
20
     */
21
    public function __construct(Repository $repository)
22
    {
23
        $this->authorizePermissionResource('extension');
24
        $this->repository = $repository;
25
    }
26
27
    /**
28
     * Display extensions resource.
29
     *
30
     * @param \Yajra\CMS\DataTables\ExtensionsDataTable $dataTable
31
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
32
     */
33
    public function index(ExtensionsDataTable $dataTable)
34
    {
35
        return $dataTable->render('administrator.extensions.index');
36
    }
37
38
    public function store(Request $request)
39
    {
40
        $extension          = $this->repository->findOrFail($request->get('id'));
41
        $extension->enabled = ! $extension->enabled;
42
        $extension->save();
43
44
        $response = 'cms::extension.' . ($extension->enabled ? 'enabled' : 'disabled');
45
46
        return $this->notifySuccess(trans($response));
47
    }
48
49
    /**
50
     * Uninstall an extension.
51
     *
52
     * @param string $id
53
     * @return \Illuminate\Http\RedirectResponse
54
     */
55
    public function destroy($id)
56
    {
57
        $extension = $this->repository->findOrFail($id);
58
        if ($extension->protected) {
59
            return $this->notifyError(trans('cms::extension.protected'));
60
        }
61
62
        if ($this->repository->uninstall($id)) {
63
            flash()->success(trans('cms::extension.deleted', compact('id')));
0 ignored issues
show
Bug introduced by
It seems like trans('cms::extension.deleted', compact('id')) targeting trans() can also be of type object<Illuminate\Contra...Translation\Translator>; however, Laracasts\Flash\FlashNotifier::success() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
64
        } else {
65
            flash()->error(trans('cms::extension.error', compact('id')));
0 ignored issues
show
Bug introduced by
It seems like trans('cms::extension.error', compact('id')) targeting trans() can also be of type object<Illuminate\Contra...Translation\Translator>; however, Laracasts\Flash\FlashNotifier::error() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
66
        }
67
68
        return back();
69
    }
70
}
71