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

SendingMethodCountryPriceController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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 Notification;
18
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...
19
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...
20
21
class SendingMethodCountryPriceController extends Controller
22
{
23
    public function index($sendingMethodId)
24
    {
25
        if ($request->wantsJson()) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $request seems to be never defined.
Loading history...
26
27
            $users = SendingMethodService::getCountryModel()->select([
28
                
29
                'id',
30
                'name']
31
            )->where('sending_method_id', '=', $sendingMethodId);
32
            
33
            $datatables = \Datatables::of($users)->addColumn('action', function ($users) use ($sendingMethodId) {
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...
34
                $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'));
35
                $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;
36
            
37
                return $link;
38
            });
39
40
            return $datatables->make(true);
41
        }
42
        
43
        return view('backend.sending_method_country_price.index')->with('sendingMethod', SendingMethodService::find($sendingMethodId));
44
    }
45
46
    public function create($sendingMethodId)
47
    {
48
        return view('backend.sending_method_country_price.create')->with(array(
49
            'taxRates' => TaxRateService::selectAll()->pluck('rate', 'id'),
50
            'sendingMethod' => SendingMethodService::find($sendingMethodId)
51
        ));
52
    }
53
54
    public function getImport($sendingMethodId)
55
    {
56
        return view('backend.sending_method_country_price.import')->with(array(
57
            'taxRates' => TaxRateService::selectAll()->pluck('rate', 'id'),
58
            'sendingMethod' => SendingMethodService::find($sendingMethodId)
59
        ));
60
    }
61
62
    public function postImport(Request $request, $sendingMethodId)
63
    {
64
        $file = $request->file('file');
65
        $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

65
        $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...
66
        })->get();
67
68
        if($countries) {
69
            $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...
70
            Notification::success('The countries are inserted.');
71
            return redirect()->route('sending-method.country-prices.index', $sendingMethodId);
72
        }         
73
    }
74
75
    public function store(Request $request, $sendingMethodId)
76
    {
77
        $result  = SendingMethodService::createCountry($request->all(), $sendingMethodId);
78
        return SendingMethodService::notificationRedirect(array('sending-method.country-prices.index', $sendingMethodId), $result, 'The country was inserted.');
79
    }
80
81
    public function edit($sendingMethodId, $id)
82
    {
83
        return view('backend.sending_method_country_price.edit')->with(array(
84
            'taxRates' => TaxRateService::selectAll()->pluck('rate', 'id'),
85
            'sendingMethod' => SendingMethodService::find($sendingMethodId),
86
            'sendingMethodCountry' => SendingMethodService::findCountry($id)
87
            ));
88
    }
89
90
    public function update(Request $request, $sendingMethodId, $id)
91
    {
92
        $result  = SendingMethodService::updateCountryById($request->all(), $id);
93
        return SendingMethodService::notificationRedirect(array('sending-method.country-prices.index', $sendingMethodId), $result, 'The country was updated.');
94
    }
95
96
    public function destroy($sendingMethodId, $id)
97
    {
98
        $result  = SendingMethodService::destroyCountry($id);
99
100
        if ($result) {
101
            Notification::success('The country price was deleted.');
102
            return redirect()->route('sending-method.country-prices.index', $sendingMethodId);
103
        }
104
    }
105
}