Skip to content

Commit 7c57c3b

Browse files
authored
Merge pull request #147 from CloCkWeRX/psr12-controllers-3
PSR12 - Controllers/Kits, Controllers/Accessories and more
2 parents bbb0abc + 9eb690c commit 7c57c3b

File tree

7 files changed

+82
-74
lines changed

7 files changed

+82
-74
lines changed

app/Http/Controllers/Components/ComponentCheckinController.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ public function create($component_asset_id)
3535
return redirect()->route('components.index')->with('error', trans('admin/components/messages.not_found'));
3636
}
3737
if (is_null($asset = Asset::find($component_assets->asset_id))) {
38-
return redirect()->route('components.index')->with('error',
39-
trans('admin/components/message.not_found'));
38+
return redirect()->route('components.index')->with(
39+
'error',
40+
trans('admin/components/message.not_found')
41+
);
4042
}
4143
$this->authorize('checkin', $component);
4244

@@ -61,9 +63,10 @@ public function store(Request $request, $component_asset_id, $backto = null)
6163
{
6264
if ($component_assets = DB::table('components_assets')->find($component_asset_id)) {
6365
if (is_null($component = Component::find($component_assets->component_id))) {
64-
65-
return redirect()->route('components.index')->with('error',
66-
trans('admin/components/message.not_found'));
66+
return redirect()->route('components.index')->with(
67+
'error',
68+
trans('admin/components/message.not_found')
69+
);
6770
}
6871

6972
$this->authorize('checkin', $component);
@@ -85,8 +88,10 @@ public function store(Request $request, $component_asset_id, $backto = null)
8588
// We have to modify the record to reflect the new qty that's
8689
// actually checked out.
8790
$component_assets->assigned_qty = $qty_remaining_in_checkout;
88-
DB::table('components_assets')->where('id',
89-
$component_asset_id)->update(['assigned_qty' => $qty_remaining_in_checkout]);
91+
DB::table('components_assets')->where(
92+
'id',
93+
$component_asset_id
94+
)->update(['assigned_qty' => $qty_remaining_in_checkout]);
9095

9196
// If the checked-in qty is exactly the same as the assigned_qty,
9297
// we can simply delete the associated components_assets record
@@ -100,8 +105,10 @@ public function store(Request $request, $component_asset_id, $backto = null)
100105

101106
session()->put(['redirect_option' => $request->get('redirect_option')]);
102107

103-
return redirect()->to(Helper::getRedirectOption($request, $component->id, 'Components'))->with('success',
104-
trans('admin/components/message.checkin.success'));
108+
return redirect()->to(Helper::getRedirectOption($request, $component->id, 'Components'))->with(
109+
'success',
110+
trans('admin/components/message.checkin.success')
111+
);
105112
}
106113

107114
return redirect()->route('components.index')->with('error', trans('admin/components/message.does_not_exist'));

app/Http/Controllers/Components/ComponentCheckoutController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ public function create($id)
3030
{
3131

3232
if ($component = Component::find($id)) {
33-
3433
$this->authorize('checkout', $component);
3534

3635
// Make sure the category is valid
3736
if ($component->category) {
38-
3937
// Make sure there is at least one available to checkout
40-
if ($component->numRemaining() <= 0){
38+
if ($component->numRemaining() <= 0) {
4139
return redirect()->route('components.index')
4240
->with('error', trans('admin/components/message.checkout.unavailable'));
4341
}
@@ -53,7 +51,6 @@ public function create($id)
5351

5452
// Not found
5553
return redirect()->route('components.index')->with('error', trans('admin/components/message.not_found'));
56-
5754
}
5855

5956
/**

app/Http/Controllers/Components/ComponentsFilesController.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function store(UploadFileRequest $request, $componentId = null)
2929
{
3030

3131
if (config('app.lock_passwords')) {
32-
return redirect()->route('components.show', ['component'=>$componentId])->with('error', trans('general.feature_disabled'));
32+
return redirect()->route('components.show', ['component' => $componentId])->with('error', trans('general.feature_disabled'));
3333
}
3434

3535
$component = Component::find($componentId);
@@ -43,15 +43,14 @@ public function store(UploadFileRequest $request, $componentId = null)
4343
}
4444

4545
foreach ($request->file('file') as $file) {
46-
$file_name = $request->handleFile('private_uploads/components/','component-'.$component->id, $file);
46+
$file_name = $request->handleFile('private_uploads/components/', 'component-' . $component->id, $file);
4747

4848
//Log the upload to the log
4949
$component->logUpload($file_name, e($request->input('notes')));
5050
}
5151

5252

5353
return redirect()->route('components.show', $component->id)->withFragment('files')->with('success', trans('general.file_upload_success'));
54-
5554
}
5655

5756
return redirect()->route('components.show', $component->id)->with('error', trans('general.no_files_uploaded'));
@@ -81,9 +80,9 @@ public function destroy($componentId = null, $fileId = null)
8180
$log = Actionlog::find($fileId);
8281

8382
// Remove the file if one exists
84-
if (Storage::exists('components/'.$log->filename)) {
83+
if (Storage::exists('components/' . $log->filename)) {
8584
try {
86-
Storage::delete('components/'.$log->filename);
85+
Storage::delete('components/' . $log->filename);
8786
} catch (\Exception $e) {
8887
Log::debug($e);
8988
}
@@ -111,7 +110,7 @@ public function destroy($componentId = null, $fileId = null)
111110
*/
112111
public function show($componentId = null, $fileId = null)
113112
{
114-
Log::debug('Private filesystem is: '.config('filesystems.default'));
113+
Log::debug('Private filesystem is: ' . config('filesystems.default'));
115114

116115

117116
// the component is valid
@@ -120,17 +119,15 @@ public function show($componentId = null, $fileId = null)
120119
$this->authorize('components.files', $component);
121120

122121
if ($log = Actionlog::whereNotNull('filename')->where('item_id', $component->id)->find($fileId)) {
123-
124-
$file = 'private_uploads/components/'.$log->filename;
122+
$file = 'private_uploads/components/' . $log->filename;
125123

126124
try {
127125
return StorageHelper::showOrDownloadFile($file, $log->filename);
128126
} catch (\Exception $e) {
129-
return redirect()->route('components.show', ['component' => $component])->with('error', trans('general.file_not_found'));
127+
return redirect()->route('components.show', ['component' => $component])->with('error', trans('general.file_not_found'));
130128
}
131129
}
132-
return redirect()->route('components.show', ['component' => $component])->with('error', trans('general.log_record_not_found'));
133-
130+
return redirect()->route('components.show', ['component' => $component])->with('error', trans('general.log_record_not_found'));
134131
}
135132

136133
return redirect()->route('components.index')->with('error', trans('general.file_does_not_exist', ['id' => $fileId]));

app/Http/Controllers/Consumables/ConsumableCheckoutController.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use App\Models\Consumable;
99
use App\Models\User;
1010
use Illuminate\Http\Request;
11-
use \Illuminate\Contracts\View\View;
12-
use \Illuminate\Http\RedirectResponse;
11+
use Illuminate\Contracts\View\View;
12+
use Illuminate\Http\RedirectResponse;
1313

1414
class ConsumableCheckoutController extends Controller
1515
{
@@ -21,18 +21,16 @@ class ConsumableCheckoutController extends Controller
2121
* @since [v1.0]
2222
* @param int $id
2323
*/
24-
public function create($id) : View | RedirectResponse
24+
public function create($id): View | RedirectResponse
2525
{
2626

2727
if ($consumable = Consumable::find($id)) {
28-
2928
$this->authorize('checkout', $consumable);
3029

3130
// Make sure the category is valid
3231
if ($consumable->category) {
33-
3432
// Make sure there is at least one available to checkout
35-
if ($consumable->numRemaining() <= 0){
33+
if ($consumable->numRemaining() <= 0) {
3634
return redirect()->route('consumables.index')
3735
->with('error', trans('admin/consumables/message.checkout.unavailable', ['requested' => 1, 'remaining' => $consumable->numRemaining()]));
3836
}
@@ -48,7 +46,6 @@ public function create($id) : View | RedirectResponse
4846

4947
// Not found
5048
return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.does_not_exist'));
51-
5249
}
5350

5451
/**
@@ -92,13 +89,13 @@ public function store(Request $request, $consumableId)
9289
// Update the consumable data
9390
$consumable->assigned_to = e($request->input('assigned_to'));
9491

95-
for ($i = 0; $i < $quantity; $i++){
96-
$consumable->users()->attach($consumable->id, [
92+
for ($i = 0; $i < $quantity; $i++) {
93+
$consumable->users()->attach($consumable->id, [
9794
'consumable_id' => $consumable->id,
9895
'created_by' => $admin_user->id,
9996
'assigned_to' => e($request->input('assigned_to')),
10097
'note' => $request->input('note'),
101-
]);
98+
]);
10299
}
103100

104101
$consumable->checkout_qty = $quantity;

app/Http/Controllers/Consumables/ConsumablesController.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Illuminate\Support\Facades\Auth;
1111
use Illuminate\Support\Facades\Validator;
1212
use Illuminate\Http\RedirectResponse;
13-
use \Illuminate\Contracts\View\View;
13+
use Illuminate\Contracts\View\View;
1414
use App\Http\Requests\StoreConsumableRequest;
1515

1616
/**
@@ -51,7 +51,7 @@ public function create()
5151
$this->authorize('create', Consumable::class);
5252

5353
return view('consumables.edit')->with('category_type', 'consumable')
54-
->with('item', new Consumable);
54+
->with('item', new Consumable());
5555
}
5656

5757
/**
@@ -104,13 +104,12 @@ public function store(StoreConsumableRequest $request)
104104
* @see ConsumablesController::postEdit() method that stores the form data.
105105
* @since [v1.0]
106106
*/
107-
public function edit(Consumable $consumable) : View | RedirectResponse
107+
public function edit(Consumable $consumable): View | RedirectResponse
108108
{
109109
$this->authorize($consumable);
110110
return view('consumables/edit')
111111
->with('item', $consumable)
112112
->with('category_type', 'consumable');
113-
114113
}
115114

116115
/**
@@ -204,7 +203,7 @@ public function show(Consumable $consumable)
204203
return view('consumables/view', compact('consumable'));
205204
}
206205

207-
public function clone(Consumable $consumable) : View
206+
public function clone(Consumable $consumable): View
208207
{
209208
$this->authorize('create', $consumable);
210209
$consumable_to_close = $consumable;

app/Http/Controllers/Consumables/ConsumablesFilesController.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Support\Facades\Storage;
1212
use Symfony\Consumable\HttpFoundation\JsonResponse;
1313
use Illuminate\Support\Facades\Log;
14+
1415
class ConsumablesFilesController extends Controller
1516
{
1617
/**
@@ -27,7 +28,7 @@ class ConsumablesFilesController extends Controller
2728
public function store(UploadFileRequest $request, $consumableId = null)
2829
{
2930
if (config('app.lock_passwords')) {
30-
return redirect()->route('consumables.show', ['consumable'=>$consumableId])->with('error', trans('general.feature_disabled'));
31+
return redirect()->route('consumables.show', ['consumable' => $consumableId])->with('error', trans('general.feature_disabled'));
3132
}
3233

3334
$consumable = Consumable::find($consumableId);
@@ -41,15 +42,14 @@ public function store(UploadFileRequest $request, $consumableId = null)
4142
}
4243

4344
foreach ($request->file('file') as $file) {
44-
$file_name = $request->handleFile('private_uploads/consumables/','consumable-'.$consumable->id, $file);
45+
$file_name = $request->handleFile('private_uploads/consumables/', 'consumable-' . $consumable->id, $file);
4546

4647
//Log the upload to the log
4748
$consumable->logUpload($file_name, e($request->input('notes')));
4849
}
4950

5051

5152
return redirect()->route('consumables.show', $consumable->id)->withFragment('files')->with('success', trans('general.file_upload_success'));
52-
5353
}
5454

5555
return redirect()->route('consumables.show', $consumable->id)->with('error', trans('general.no_files_uploaded'));
@@ -79,9 +79,9 @@ public function destroy($consumableId = null, $fileId = null)
7979
$log = Actionlog::find($fileId);
8080

8181
// Remove the file if one exists
82-
if (Storage::exists('consumables/'.$log->filename)) {
82+
if (Storage::exists('consumables/' . $log->filename)) {
8383
try {
84-
Storage::delete('consumables/'.$log->filename);
84+
Storage::delete('consumables/' . $log->filename);
8585
} catch (\Exception $e) {
8686
Log::debug($e);
8787
}
@@ -116,17 +116,16 @@ public function show($consumableId = null, $fileId = null)
116116
$this->authorize('consumables.files', $consumable);
117117

118118
if ($log = Actionlog::whereNotNull('filename')->where('item_id', $consumable->id)->find($fileId)) {
119-
$file = 'private_uploads/consumables/'.$log->filename;
119+
$file = 'private_uploads/consumables/' . $log->filename;
120120

121121
try {
122122
return StorageHelper::showOrDownloadFile($file, $log->filename);
123123
} catch (\Exception $e) {
124-
return redirect()->route('consumables.show', ['consumable' => $consumable])->with('error', trans('general.file_not_found'));
124+
return redirect()->route('consumables.show', ['consumable' => $consumable])->with('error', trans('general.file_not_found'));
125125
}
126126
}
127127
// The log record doesn't exist somehow
128-
return redirect()->route('consumables.show', ['consumable' => $consumable])->with('error', trans('general.log_record_not_found'));
129-
128+
return redirect()->route('consumables.show', ['consumable' => $consumable])->with('error', trans('general.log_record_not_found'));
130129
}
131130

132131
return redirect()->route('consumables.index')->with('error', trans('general.file_does_not_exist', ['id' => $fileId]));

0 commit comments

Comments
 (0)