Passed
Push — master ( f4b030...a2b3af )
by Matthijs
22:06 queued 15:53
created

TaxRateController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace App\Http\Controllers\Backend;
2
3
use App\Http\Controllers\Controller;
4
use Hideyo\Ecommerce\Framework\Services\TaxRate\TaxRateFacade as TaxRateService;
5
6
use Illuminate\Http\Request;
7
use Notification;
8
use Form;
9
use Datatables;
0 ignored issues
show
Bug introduced by
The type Datatables was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
class TaxRateController extends Controller
12
{
13
    public function index(Request $request)
14
    {
15
        if ($request->wantsJson()) {
16
            $query = TaxRateService::getModel()->where('shop_id', '=', auth('hideyobackend')->user()->selected_shop_id);
0 ignored issues
show
Bug introduced by
Accessing selected_shop_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
17
            $datatables = Datatables::of($query)->addColumn('action', function ($query) {
18
                $deleteLink = Form::deleteajax(url()->route('tax-rate.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-sm btn-danger'), $query->title);
19
                $links = '<a href="'.url()->route('tax-rate.edit', $query->id).'" class="btn btn-sm btn-success"><i class="fi-pencil"></i>Edit</a>  '.$deleteLink;
20
                return $links;
21
            });
22
23
            return $datatables->make(true);
24
        }
25
        
26
        return view('backend.tax_rate.index')->with('taxRate', TaxRateService::selectAll());
27
    }
28
29
    public function create()
30
    {
31
        return view('backend.tax_rate.create')->with(array());
32
    }
33
34
    public function store(Request $request)
35
    {
36
        $result  = TaxRateService::create($request->all());
37
        return TaxRateService::notificationRedirect('tax-rate.index', $result, 'The tax rate was inserted.');
38
    }
39
40
    public function edit($taxRateId)
41
    {
42
        return view('backend.tax_rate.edit')->with(array('taxRate' => TaxRateService::find($taxRateId)));
43
    }
44
45
    public function update(Request $request, $taxRateId)
46
    {
47
        $result  = TaxRateService::updateById($request->all(), $taxRateId);
48
        return TaxRateService::notificationRedirect('tax-rate.index', $result, 'The tax rate was updated.');
49
    }
50
51
    public function destroy($taxRateId)
52
    {
53
        $result  = TaxRateService::destroy($taxRateId);
54
        if ($result) {
55
            Notification::error('The tax rate was deleted.');
56
            return redirect()->route('tax-rate.index');
57
        }
58
    }
59
}
60