AddressController   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 179
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 48
c 2
b 0
f 0
dl 0
loc 179
rs 10
wmc 12

8 Methods

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