SendingMethodCountryPriceController   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 34
c 1
b 0
f 0
dl 0
loc 77
rs 10
wmc 11

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getImport() 0 5 1
A index() 0 16 2
A edit() 0 6 1
A postImport() 0 10 2
A update() 0 4 1
A destroy() 0 7 2
A create() 0 5 1
A store() 0 4 1
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * CouponController
5
 *
6
 * This is the controller of the sending methods of the shop
7
 * @author Matthijs Neijenhuijs <[email protected]>
8
 * @version 1.0
9
 */
10
11
use App\Http\Controllers\Controller;
12
use Hideyo\Ecommerce\Framework\Services\SendingMethod\SendingMethodFacade as SendingMethodService;
13
use Hideyo\Ecommerce\Framework\Services\PaymentMethod\PaymentMethodFacade as PaymentMethodService;
14
use Hideyo\Ecommerce\Framework\Services\TaxRate\TaxRateFacade as TaxRateService;
15
16
use Illuminate\Http\Request;
17
use Input;
0 ignored issues
show
Bug introduced by
The type Input 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...
18
use Excel;
0 ignored issues
show
Bug introduced by
The type Excel 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...
19
20
class SendingMethodCountryPriceController extends Controller
21
{
22
    public function index(Request $request, $sendingMethodId)
23
    {
24
        if ($request->wantsJson()) {
25
            $users = SendingMethodService::getCountryModel()->where('sending_method_id', '=', $sendingMethodId);
26
            
27
            $datatables = \DataTables::of($users)->addColumn('action', function ($users) use ($sendingMethodId) {
28
                $delete = \Form::deleteajax(url()->route('sending-method.country-prices.destroy', array('sendingMethodId' => $sendingMethodId, 'id' => $users->id)), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
29
                $link = '<a href="'.url()->route('sending-method.country-prices.edit', array('sendingMethodId' => $sendingMethodId, 'id' => $users->id)).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>  '.$delete;
30
            
31
                return $link;
32
            });
33
34
            return $datatables->make(true);
35
        }
36
        
37
        return view('backend.sending_method_country_price.index')->with('sendingMethod', SendingMethodService::find($sendingMethodId));
38
    }
39
40
    public function create($sendingMethodId)
41
    {
42
        return view('backend.sending_method_country_price.create')->with(array(
43
            'taxRates' => TaxRateService::selectAll()->pluck('rate', 'id'),
44
            'sendingMethod' => SendingMethodService::find($sendingMethodId)
45
        ));
46
    }
47
48
    public function getImport($sendingMethodId)
49
    {
50
        return view('backend.sending_method_country_price.import')->with(array(
51
            'taxRates' => TaxRateService::selectAll()->pluck('rate', 'id'),
52
            'sendingMethod' => SendingMethodService::find($sendingMethodId)
53
        ));
54
    }
55
56
    public function postImport(Request $request, $sendingMethodId)
57
    {
58
        $file = $request->file('file');
59
        $countries = \Excel::load($file, function($reader) {
0 ignored issues
show
Unused Code introduced by
The parameter $reader is not used and could be removed. ( Ignorable by Annotation )

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

59
        $countries = \Excel::load($file, function(/** @scrutinizer ignore-unused */ $reader) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
        })->get();
61
62
        if($countries) {
63
            $result  = SendingMethodService::importCountries($countries, $request->get('tax_rate_id'), $sendingMethodId);
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
64
            flash('The countries are inserted.');
65
            return redirect()->route('sending-method.country-prices.index', $sendingMethodId);
66
        }         
67
    }
68
69
    public function store(Request $request, $sendingMethodId)
70
    {
71
        $result  = SendingMethodService::createCountry($request->all(), $sendingMethodId);
72
        return SendingMethodService::notificationRedirect(array('sending-method.country-prices.index', $sendingMethodId), $result, 'The country was inserted.');
73
    }
74
75
    public function edit($sendingMethodId, $id)
76
    {
77
        return view('backend.sending_method_country_price.edit')->with(array(
78
            'taxRates' => TaxRateService::selectAll()->pluck('rate', 'id'),
79
            'sendingMethod' => SendingMethodService::find($sendingMethodId),
80
            'sendingMethodCountry' => SendingMethodService::findCountry($id)
81
            ));
82
    }
83
84
    public function update(Request $request, $sendingMethodId, $id)
85
    {
86
        $result  = SendingMethodService::updateCountryById($request->all(), $id);
87
        return SendingMethodService::notificationRedirect(array('sending-method.country-prices.index', $sendingMethodId), $result, 'The country was updated.');
88
    }
89
90
    public function destroy($sendingMethodId, $id)
91
    {
92
        $result  = SendingMethodService::destroyCountry($id);
93
94
        if ($result) {
95
            flash('The country price was deleted.');
96
            return redirect()->route('sending-method.country-prices.index', $sendingMethodId);
97
        }
98
    }
99
}