Passed
Push — master ( ea1130...b24b06 )
by F
03:15
created

CountryController::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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\CountryRepository;
9
use PWWEB\Localisation\Requests\CreateCountryRequest;
10
use PWWEB\Localisation\Requests\UpdateCountryRequest;
11
12
/**
13
 * PWWEB\Localisation\Controllers\CountryController CountryController.
14
 *
15
 * The CRUD controller for Country
16
 * Class CountryController
17
 *
18
 * @package   pwweb/localisation
19
 * @author    Frank Pillukeit <[email protected]>
20
 * @author    Richard Browne <[email protected]
21
 * @copyright 2020 pw-websolutions.com
22
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
23
*/
24
class CountryController extends Controller
25
{
26
    /** @var  CountryRepository */
27
    private $countryRepository;
28
29
    public function __construct(CountryRepository $countryRepo)
30
    {
31
        $this->countryRepository = $countryRepo;
32
    }
33
34
    /**
35
     * Display a listing of the Country.
36
     *
37
     * @param Request $request
38
     *
39
     * @return \Illuminate\View\View
40
     */
41
    public function index(Request $request)
42
    {
43
        $countries = $this->countryRepository->all();
44
45
        return view('localisation::countries.index')
46
            ->with('countries', $countries);
47
    }
48
49
    /**
50
     * Show the form for creating a new Country.
51
     *
52
     * @return \Illuminate\View\View
53
     */
54
    public function create()
55
    {
56
        return view('localisation::countries.create');
57
    }
58
59
    /**
60
     * Store a newly created Country in storage.
61
     *
62
     * @param CreateCountryRequest $request
63
     *
64
     * @return \Illuminate\Http\RedirectResponse
65
     */
66
    public function store(CreateCountryRequest $request)
67
    {
68
        $input = $request->all();
69
70
        $country = $this->countryRepository->create($input);
0 ignored issues
show
Unused Code introduced by
The assignment to $country is dead and can be removed.
Loading history...
71
72
        Flash::success('Country saved successfully.');
73
74
        return redirect(route('localisation.countries.index'));
75
    }
76
77
    /**
78
     * Display the specified Country.
79
     *
80
     * @param int $id
81
     *
82
     * @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse
83
     */
84
    public function show($id)
85
    {
86
        $country = $this->countryRepository->find($id);
87
88
        if (empty($country)) {
89
            Flash::error('Country not found');
90
91
            return redirect(route('localisation.countries.index'));
92
        }
93
94
        return view('localisation::countries.show')->with('country', $country);
95
    }
96
97
    /**
98
     * Show the form for editing the specified Country.
99
     *
100
     * @param int $id
101
     *
102
     * @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse
103
     */
104
    public function edit($id)
105
    {
106
        $country = $this->countryRepository->find($id);
107
108
        if (empty($country)) {
109
            Flash::error('Country not found');
110
111
            return redirect(route('localisation.countries.index'));
112
        }
113
114
        return view('localisation::countries.edit')->with('country', $country);
115
    }
116
117
    /**
118
     * Update the specified Country in storage.
119
     *
120
     * @param int $id
121
     * @param UpdateCountryRequest $request
122
     *
123
     * @return \Illuminate\Http\RedirectResponse
124
     */
125
    public function update($id, UpdateCountryRequest $request)
126
    {
127
        $country = $this->countryRepository->find($id);
128
129
        if (empty($country)) {
130
            Flash::error('Country not found');
131
132
            return redirect(route('localisation.countries.index'));
133
        }
134
135
        $country = $this->countryRepository->update($request->all(), $id);
0 ignored issues
show
Unused Code introduced by
The assignment to $country is dead and can be removed.
Loading history...
136
137
        Flash::success('Country updated successfully.');
138
139
        return redirect(route('localisation.countries.index'));
140
    }
141
142
    /**
143
     * Remove the specified Country from storage.
144
     *
145
     * @param int $id
146
     *
147
     * @throws \Exception
148
     *
149
     * @return \Illuminate\Http\RedirectResponse
150
     */
151
    public function destroy($id)
152
    {
153
        $country = $this->countryRepository->find($id);
154
155
        if (empty($country)) {
156
            Flash::error('Country not found');
157
158
            return redirect(route('localisation.countries.index'));
159
        }
160
161
        $this->countryRepository->delete($id);
162
163
        Flash::success('Country deleted successfully.');
164
165
        return redirect(route('localisation.countries.index'));
166
    }
167
}
168