Passed
Push — master ( 8be593...d0f45d )
by F
07:27
created

AddressController::show()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PWWEB\Localisation\Controllers;
4
5
use App\Http\Controllers\AppBaseController;
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\AppBaseController 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...
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\Requests\CreateAddressRequest;
11
use PWWEB\Localisation\Requests\UpdateAddressRequest;
12
use Response;
13
14
/**
15
 * PWWEB\Localisation\Controllers\AddressController AddressController.
16
 *
17
 * The CRUD controller for Address
18
 * Class AddressController
19
 *
20
 * @package   pwweb/localisation
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 AddressController extends AppBaseController
27
{
28
    /**
29
     * [private description].
30
     * @var [type]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
31
     */
32
    private $addressRepository;
33
34
    public function __construct(AddressRepository $addressRepo, TypeRepository $typeRepo)
35
    {
36
        $this->addressRepository = $addressRepo;
37
        $this->typeRepository = $typeRepo;
0 ignored issues
show
Bug Best Practice introduced by
The property typeRepository does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
38
    }
39
40
    /**
41
     * Display a listing of the Address.
42
     *
43
     * @param Request $request
44
     *
45
     * @return Response
46
     */
47
    public function index(Request $request)
48
    {
49
        $addresses = $this->addressRepository->all();
50
51
        return view('localisation::address.index')
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('localisatio...addresses', $addresses) returns the type Illuminate\View\View which is incompatible with the documented return type Response.
Loading history...
52
            ->with('addresses', $addresses);
53
    }
54
55
    /**
56
     * Show the form for creating a new Address.
57
     *
58
     * @return Response
59
     */
60
    public function create()
61
    {
62
        $types = $this->typeRepository->all();
63
64
        return view('localisation::address.create')
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('localisatio...->with('types', $types) returns the type Illuminate\View\View which is incompatible with the documented return type Response.
Loading history...
65
            ->with('types', $types);
66
    }
67
68
    /**
69
     * Store a newly created Address in storage.
70
     *
71
     * @param CreateAddressRequest $request
72
     *
73
     * @return Response
74
     */
75
    public function store(CreateAddressRequest $request)
76
    {
77
        $input = $request->all();
78
79
        $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...
80
81
        Flash::success('Address saved successfully.');
82
83
        return redirect(route('localisation.address.index'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l...sation.address.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Response.
Loading history...
84
    }
85
86
    /**
87
     * Display the specified Address.
88
     *
89
     * @param int $id
90
     *
91
     * @return Response
92
     */
93
    public function show($id)
94
    {
95
        $address = $this->addressRepository->find($id);
96
97
        if (empty($address)) {
98
            Flash::error('Address not found');
99
100
            return redirect(route('localisation.address.index'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l...sation.address.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Response.
Loading history...
101
        }
102
103
        return view('localisation::address.show')->with('address', $address);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('localisatio...th('address', $address) returns the type Illuminate\View\View which is incompatible with the documented return type Response.
Loading history...
104
    }
105
106
    /**
107
     * Show the form for editing the specified Address.
108
     *
109
     * @param int $id
110
     *
111
     * @return Response
112
     */
113
    public function edit($id)
114
    {
115
        $address = $this->addressRepository->find($id);
116
        $types = $this->typeRepository->all();
117
118
119
        if (empty($address)) {
120
            Flash::error('Address not found');
121
122
            return redirect(route('localisation.address.index'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l...sation.address.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Response.
Loading history...
123
        }
124
125
        return view('localisation::address.edit')
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('localisatio...->with('types', $types) returns the type Illuminate\View\View which is incompatible with the documented return type Response.
Loading history...
126
            ->with('address', $address)
127
            ->with('types', $types);
128
    }
129
130
    /**
131
     * Update the specified Address in storage.
132
     *
133
     * @param int $id
134
     * @param UpdateAddressRequest $request
135
     *
136
     * @return Response
137
     */
138
    public function update($id, UpdateAddressRequest $request)
139
    {
140
        $address = $this->addressRepository->find($id);
141
142
        if (empty($address)) {
143
            Flash::error('Address not found');
144
145
            return redirect(route('localisation.address.index'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l...sation.address.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Response.
Loading history...
146
        }
147
148
        $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...
149
150
        Flash::success('Address updated successfully.');
151
152
        return redirect(route('localisation.address.index'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l...sation.address.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Response.
Loading history...
153
    }
154
155
    /**
156
     * Remove the specified Address from storage.
157
     *
158
     * @param int $id
159
     *
160
     * @throws \Exception
161
     *
162
     * @return Response
163
     */
164
    public function destroy($id)
165
    {
166
        $address = $this->addressRepository->find($id);
167
168
        if (empty($address)) {
169
            Flash::error('Address not found');
170
171
            return redirect(route('localisation.address.index'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l...sation.address.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Response.
Loading history...
172
        }
173
174
        $this->addressRepository->delete($id);
175
176
        Flash::success('Address deleted successfully.');
177
178
        return redirect(route('localisation.address.index'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l...sation.address.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Response.
Loading history...
179
    }
180
}
181