Issues (60)

src/Controllers/Tax/LocationController.php (14 issues)

1
<?php
2
3
namespace PWWEB\Localisation\Controllers\Tax;
4
5
use App\Http\Controllers\Controller;
6
use Flash;
0 ignored issues
show
The type Flash 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...
7
use Illuminate\Http\Request;
8
use PWWEB\Localisation\Repositories\CountryRepository;
9
use PWWEB\Localisation\Repositories\Tax\LocationRepository;
10
use PWWEB\Localisation\Repositories\Tax\RateRepository;
11
use PWWEB\Localisation\Requests\Tax\CreateLocationRequest;
12
use PWWEB\Localisation\Requests\Tax\UpdateLocationRequest;
13
use Response;
14
15
/**
16
 * PWWEB\Localisation\Controllers\Tax\RateController RateController.
17
 *
18
 * The CRUD controller for Rate
19
 * Class RateController
20
 *
21
 * @author    Frank Pillukeit <[email protected]>
22
 * @author    Richard Browne <[email protected]
23
 * @copyright 2020 pw-websolutions.com
24
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
25
 */
26
class LocationController extends Controller
27
{
28
    /**
29
     * Repository of locations to be used throughout the controller.
30
     *
31
     * @var \PWWEB\Localisation\Repositories\Tax\LocationRepository
32
     */
33
    private $locationRepository;
34
35
    /**
36
     * Repository of rates to be used throughout the controller.
37
     *
38
     * @var \PWWEB\Localisation\Repositories\Tax\RateRepository
39
     */
40
    private $rateRepository;
41
42
    /**
43
     * Repository of addresses to be used throughout the controller.
44
     *
45
     * @var \PWWEB\Localisation\Repositories\CountryRepository
46
     */
47
    private $countryRepository;
48
49
    /**
50
     * Constructor for the Location controller.
51
     *
52
     * @param LocationRepository $locationRepo Repository of Locations.
53
     * @param CountryRepository  $countryRepo  Repository of Countries.
54
     * @param RateRepository     $rateRepo     Repository of Rates.
55
     */
56
    public function __construct(LocationRepository $locationRepo, CountryRepository $countryRepo, RateRepository $rateRepo)
57
    {
58
        $this->locationRepository = $locationRepo;
59
        $this->rateRepository = $rateRepo;
60
        $this->countryRepository = $countryRepo;
61
    }
62
63
    /**
64
     * Display a listing of the Location.
65
     *
66
     * @param Request $request Index Request
67
     *
68
     * @return Response
69
     */
70
    public function index(Request $request)
71
    {
72
        $locations = $this->locationRepository->paginate(15);
73
74
        return view('localisation::tax.locations.index')
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('localisatio...locations', $locations) returns the type Illuminate\View\View which is incompatible with the documented return type Response.
Loading history...
75
            ->with('locations', $locations);
76
    }
77
78
    /**
79
     * Show the form for creating a new Location.
80
     *
81
     * @return Response
82
     */
83
    public function create()
84
    {
85
        $countries = $this->countryRepository->all();
86
        $rates = $this->rateRepository->all();
87
88
        return view('localisation::tax.locations.create', compact('countries', 'rates'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('localisatio...('countries', 'rates')) returns the type Illuminate\View\View which is incompatible with the documented return type Response.
Loading history...
89
    }
90
91
    /**
92
     * Store a newly created Location in storage.
93
     *
94
     * @param CreateLocationRequest $request Create Request
95
     *
96
     * @return Response
97
     */
98
    public function store(CreateLocationRequest $request)
99
    {
100
        $input = $request->all();
101
102
        $location = $this->locationRepository->create($input);
0 ignored issues
show
The assignment to $location is dead and can be removed.
Loading history...
103
104
        Flash::success(__('pwweb::localisation.tax.locations.saved'));
105
106
        return redirect(route('localisation.tax.locations.index'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l....tax.locations.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Response.
Loading history...
107
    }
108
109
    /**
110
     * Display the specified Location.
111
     *
112
     * @param int $id ID to show
113
     *
114
     * @return Response
115
     */
116
    public function show($id)
117
    {
118
        $location = $this->locationRepository->find($id);
119
120
        if (true === empty($location)) {
121
            Flash::error(__('pwweb::localisation.tax.locations.not_found'));
122
123
            return redirect(route('localisation.tax.locations.index'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l....tax.locations.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Response.
Loading history...
124
        }
125
126
        return view('localisation::tax.locations.show')->with('location', $location);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('localisatio...('location', $location) returns the type Illuminate\View\View which is incompatible with the documented return type Response.
Loading history...
127
    }
128
129
    /**
130
     * Show the form for editing the specified Location.
131
     *
132
     * @param int $id ID to edit
133
     *
134
     * @return Response
135
     */
136
    public function edit($id)
137
    {
138
        $location = $this->locationRepository->find($id);
139
        $countries = $this->countryRepository->all();
140
        $rates = $this->rateRepository->all();
141
142
        if (true === empty($location)) {
143
            Flash::error(__('pwweb::localisation.tax.locations.not_found'));
144
145
            return redirect(route('localisation.tax.locations.index'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l....tax.locations.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Response.
Loading history...
146
        }
147
148
        return view('localisation::tax.locations.edit', compact('location', 'countries', 'rates'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('localisatio... 'countries', 'rates')) returns the type Illuminate\View\View which is incompatible with the documented return type Response.
Loading history...
149
    }
150
151
    /**
152
     * Update the specified Location in storage.
153
     *
154
     * @param int                   $id      ID to update
155
     * @param UpdateLocationRequest $request Update Request
156
     *
157
     * @return Response
158
     */
159
    public function update($id, UpdateLocationRequest $request)
160
    {
161
        $location = $this->locationRepository->find($id);
162
163
        if (true === empty($location)) {
164
            Flash::error(__('pwweb::localisation.tax.locations.not_found'));
165
166
            return redirect(route('localisation.tax.locations.index'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l....tax.locations.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Response.
Loading history...
167
        }
168
169
        $location = $this->locationRepository->update($request->all(), $id);
0 ignored issues
show
The assignment to $location is dead and can be removed.
Loading history...
170
171
        Flash::success(__('pwweb::localisation.tax.locations.updated'));
172
173
        return redirect(route('localisation.tax.locations.index'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l....tax.locations.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Response.
Loading history...
174
    }
175
176
    /**
177
     * Remove the specified Location from storage.
178
     *
179
     * @param int $id ID to destroy
180
     *
181
     * @throws \Exception
182
     *
183
     * @return Response
184
     */
185
    public function destroy($id)
186
    {
187
        $location = $this->locationRepository->find($id);
188
189
        if (true === empty($location)) {
190
            Flash::error(__('pwweb::localisation.tax.locations.not_found'));
191
192
            return redirect(route('localisation.tax.locations.index'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l....tax.locations.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Response.
Loading history...
193
        }
194
195
        $this->locationRepository->delete($id);
196
197
        Flash::success(__('pwweb::localisation.tax.locations.deleted'));
198
199
        return redirect(route('localisation.tax.locations.index'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l....tax.locations.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Response.
Loading history...
200
    }
201
}
202