Passed
Push — master ( c8fc29...ea1130 )
by F
03:55
created

LanguageController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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