Passed
Push — master ( 5dc35c...8be593 )
by F
03:23
created

TypeController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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