From d3b62aa918fc0db34a6b5ae58b85d15697138959 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 4 Jul 2024 22:52:49 +0100 Subject: [PATCH] Few more Signed-off-by: snipe --- app/Http/Controllers/SettingsController.php | 144 +++++------------- .../Controllers/StatuslabelsController.php | 30 ++-- app/Http/Controllers/SuppliersController.php | 34 ++--- app/Http/Controllers/ViewAssetsController.php | 17 +-- 4 files changed, 65 insertions(+), 160 deletions(-) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 8f1324e938..1f03a709c8 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -20,6 +20,7 @@ use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Storage; use Illuminate\Validation\Rule; use Illuminate\Http\RedirectResponse; +use Illuminate\Http\JsonResponse; use \Illuminate\Contracts\View\View; use Illuminate\Support\Str; use Illuminate\Support\Facades\Artisan; @@ -159,7 +160,7 @@ class SettingsController extends Controller */ public function postSaveFirstAdmin(SetupUserRequest $request) : RedirectResponse { - { + $user = new User(); $user->first_name = $data['first_name'] = $request->input('first_name'); $user->last_name = $request->input('last_name'); @@ -547,10 +548,8 @@ class SettingsController extends Controller * @author [A. Gianotto] [] * * @since [v1.0] - * - * @return \Illuminate\Contracts\View\View */ - public function getLocalization() + public function getLocalization() : View { $setting = Setting::getSettings(); @@ -563,10 +562,8 @@ class SettingsController extends Controller * @author [A. Gianotto] [] * * @since [v1.0] - * - * @return \Illuminate\Http\RedirectResponse */ - public function postLocalization(Request $request) + public function postLocalization(Request $request) : RedirectResponse { if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); @@ -595,10 +592,8 @@ class SettingsController extends Controller * @author [A. Gianotto] [] * * @since [v1.0] - * - * @return \Illuminate\Contracts\View\View */ - public function getAlerts() + public function getAlerts() : View { $setting = Setting::getSettings(); @@ -609,12 +604,9 @@ class SettingsController extends Controller * Return a form to allow a super admin to update settings. * * @author [A. Gianotto] [] - * * @since [v1.0] - * - * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ - public function postAlerts(Request $request) + public function postAlerts(Request $request) : RedirectResponse { if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); @@ -668,10 +660,8 @@ class SettingsController extends Controller * @author [A. Gianotto] [] * * @since [v1.0] - * - * @return \Illuminate\Contracts\View\View */ - public function getSlack() + public function getSlack() : View { $setting = Setting::getSettings(); @@ -684,10 +674,8 @@ class SettingsController extends Controller * @author [A. Gianotto] [] * * @since [v1.0] - * - * @return \Illuminate\Contracts\View\View */ - public function getAssetTags() + public function getAssetTags() : View { $setting = Setting::getSettings(); @@ -700,10 +688,8 @@ class SettingsController extends Controller * @author [A. Gianotto] [] * * @since [v1.0] - * - * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ - public function postAssetTags(Request $request) + public function postAssetTags(Request $request) : RedirectResponse { if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); @@ -728,10 +714,8 @@ class SettingsController extends Controller * @author [A. Gianotto] [] * * @since [v1.0] - * - * @return \Illuminate\Contracts\View\View */ - public function getBarcodes() + public function getBarcodes() : View { $setting = Setting::getSettings(); $is_gd_installed = extension_loaded('gd'); @@ -745,10 +729,8 @@ class SettingsController extends Controller * @author [A. Gianotto] [] * * @since [v1.0] - * - * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ - public function postBarcodes(Request $request) + public function postBarcodes(Request $request) : RedirectResponse { if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); @@ -774,10 +756,8 @@ class SettingsController extends Controller * @author [A. Gianotto] [] * * @since [v4.0] - * - * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ - public function getPhpInfo() + public function getPhpInfo() : View | RedirectResponse { if (config('app.debug') === true) { return view('settings.phpinfo'); @@ -791,12 +771,9 @@ class SettingsController extends Controller * Return a form to allow a super admin to update settings. * * @author [A. Gianotto] [] - * * @since [v4.0] - * - * @return \Illuminate\Contracts\View\View */ - public function getLabels() + public function getLabels() : View { return view('settings.labels') ->with('setting', Setting::getSettings()) @@ -807,12 +784,9 @@ class SettingsController extends Controller * Saves settings from form. * * @author [A. Gianotto] [] - * * @since [v4.0] - * - * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ - public function postLabels(Request $request) + public function postLabels(Request $request) : RedirectResponse { if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); @@ -886,10 +860,8 @@ class SettingsController extends Controller * @author [A. Gianotto] [] * * @since [v4.0] - * - * @return \Illuminate\Contracts\View\View */ - public function getLdapSettings() + public function getLdapSettings() : View { $setting = Setting::getSettings(); $groups = Group::pluck('name', 'id'); @@ -919,12 +891,9 @@ class SettingsController extends Controller * Saves settings from form. * * @author [A. Gianotto] [] - * * @since [v4.0] - * - * @return \Illuminate\Http\RedirectResponse */ - public function postLdapSettings(Request $request) + public function postLdapSettings(Request $request) : RedirectResponse { if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); @@ -978,15 +947,11 @@ class SettingsController extends Controller * Return a form to allow a super admin to update settings. * * @author Johnson Yi - * * @since v5.0.0 - * - * @return \Illuminate\Contracts\View\View */ - public function getSamlSettings() + public function getSamlSettings() : View { $setting = Setting::getSettings(); - return view('settings.saml', compact('setting')); } @@ -994,12 +959,9 @@ class SettingsController extends Controller * Saves settings from form. * * @author Johnson Yi - * * @since v5.0.0 - * - * @return \Illuminate\Http\RedirectResponse */ - public function postSamlSettings(SettingsSamlRequest $request) + public function postSamlSettings(SettingsSamlRequest $request) : RedirectResponse { if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); @@ -1028,10 +990,13 @@ class SettingsController extends Controller return redirect()->back()->withInput()->withErrors($setting->getErrors()); } - public static function getPDFBranding() - { - $pdf_branding= Setting::getSettings(); + /** + * Do we need this? Can we not just call getSettings() directly? + */ + public static function getPDFBranding() : Setting + { + $pdf_branding = Setting::getSettings(); return $pdf_branding; } @@ -1041,9 +1006,8 @@ class SettingsController extends Controller * * @author [A. Gianotto] [] * @since [v6.1.1] - * @return \Illuminate\Contracts\View\View */ - public function getGoogleLoginSettings() + public function getGoogleLoginSettings() : View { $setting = Setting::getSettings(); return view('settings.google', compact('setting')); @@ -1054,9 +1018,8 @@ class SettingsController extends Controller * * @author [A. Gianotto] [] * @since [v6.1.1] - * @return \Illuminate\Http\RedirectResponse */ - public function postGoogleLoginSettings(Request $request) + public function postGoogleLoginSettings(Request $request) : RedirectResponse { if (!config('app.lock_passwords')) { $setting = Setting::getSettings(); @@ -1083,10 +1046,8 @@ class SettingsController extends Controller * @author [A. Gianotto] [] * * @since [v1.8] - * - * @return \Illuminate\Contracts\View\View */ - public function getBackups() + public function getBackups() : View { $settings = Setting::getSettings(); $path = 'app/backups'; @@ -1122,12 +1083,9 @@ class SettingsController extends Controller * Process the backup. * * @author [A. Gianotto] [] - * * @since [v1.8] - * - * @return \Illuminate\Http\RedirectResponse */ - public function postBackups() + public function postBackups() : RedirectResponse { if (! config('app.lock_passwords')) { Artisan::call('snipeit:backup', ['--filename' => 'manual-backup-'.date('Y-m-d-H-i-s')]); @@ -1156,12 +1114,9 @@ class SettingsController extends Controller * Download the backup file. * * @author [A. Gianotto] [] - * * @since [v1.8] - * - * @return \Illuminate\Http\RedirectResponse */ - public function downloadFile($filename = null) + public function downloadFile($filename = null) : RedirectResponse { $path = 'app/backups'; @@ -1182,12 +1137,9 @@ class SettingsController extends Controller * Delete the backup file. * * @author [A. Gianotto] [] - * * @since [v1.8] - * - * @return \Illuminate\Http\RedirectResponse */ - public function deleteFile($filename = null) + public function deleteFile($filename = null) : RedirectResponse { if (config('app.allow_backup_delete')=='true') { @@ -1220,13 +1172,11 @@ class SettingsController extends Controller * Uploads a backup file * * @author [A. Gianotto] [] - * * @since [v6.0] - * - * @return \Illuminate\Http\RedirectResponse */ - public function postUploadBackup(Request $request) { + public function postUploadBackup(Request $request) : RedirectResponse + { if (! config('app.lock_passwords')) { if (!$request->hasFile('file')) { @@ -1258,12 +1208,9 @@ class SettingsController extends Controller * Restore the backup file. * * @author [A. Gianotto] [] - * * @since [v6.0] - * - * @return \Illuminate\Http\RedirectResponse */ - public function postRestore($filename = null) + public function postRestore($filename = null) : RedirectResponse { if (! config('app.lock_passwords')) { @@ -1331,13 +1278,11 @@ class SettingsController extends Controller * @author [A. Gianotto] [] * * @since [v4.0] - * - * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ - public function getPurge() + public function getPurge() : View | RedirectResponse { - Log::warning('User '.auth()->user()->username.' (ID'.auth()->id().') is attempting a PURGE'); + Log::warning('User '.auth()->user()->username.' (ID: '.auth()->id().') is attempting a PURGE'); if (config('app.allow_purge')=='true') { return view('settings.purge-form'); @@ -1350,12 +1295,9 @@ class SettingsController extends Controller * Purges soft-deletes. * * @author [A. Gianotto] [] - * * @since [v3.0] - * - * @return \Illuminate\Http\RedirectResponse */ - public function postPurge(Request $request) + public function postPurge(Request $request) : RedirectResponse { Log::warning('User '.auth()->user()->username.' (ID'.auth()->id().') is attempting a PURGE'); @@ -1399,12 +1341,9 @@ class SettingsController extends Controller * in the routes file if you want to be able to cache the routes. * * @author [A. Gianotto] [] - * * @since [v4.0] - * - * @return \Illuminate\Contracts\View\View */ - public function api() + public function api() : View { return view('settings.api'); } @@ -1413,12 +1352,9 @@ class SettingsController extends Controller * Test the email configuration. * * @author [A. Gianotto] [] - * * @since [v3.0] - * - * @return \Illuminate\Http\JsonResponse */ - public function ajaxTestEmail() + public function ajaxTestEmail() : JsonResponse { try { (new User())->forceFill([ @@ -1438,10 +1374,8 @@ class SettingsController extends Controller * Get login attempts view * * @author [A. Gianotto] [] - * - * @return \Illuminate\Contracts\View\View */ - public function getLoginAttempts() + public function getLoginAttempts() : View { return view('settings.logins'); } diff --git a/app/Http/Controllers/StatuslabelsController.php b/app/Http/Controllers/StatuslabelsController.php index aba678d47c..535117e97f 100755 --- a/app/Http/Controllers/StatuslabelsController.php +++ b/app/Http/Controllers/StatuslabelsController.php @@ -6,6 +6,8 @@ use App\Helpers\Helper; use App\Models\Statuslabel; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Illuminate\Http\RedirectResponse; +use \Illuminate\Contracts\View\View; /** * This controller handles all actions related to Status Labels for @@ -17,18 +19,14 @@ class StatuslabelsController extends Controller { /** * Show a list of all the statuslabels. - * - * @return \Illuminate\Contracts\View\View - * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function index() + public function index() : View { $this->authorize('view', Statuslabel::class); - return view('statuslabels.index'); } - public function show($id) + public function show($id) : View | RedirectResponse { $this->authorize('view', Statuslabel::class); if ($statuslabel = Statuslabel::find($id)) { @@ -41,10 +39,8 @@ class StatuslabelsController extends Controller /** * Statuslabel create. * - * @return \Illuminate\Contracts\View\View - * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function create() + public function create() : View { // Show the page $this->authorize('create', Statuslabel::class); @@ -58,10 +54,8 @@ class StatuslabelsController extends Controller * Statuslabel create form processing. * * @param Request $request - * @return \Illuminate\Http\RedirectResponse - * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function store(Request $request) + public function store(Request $request) : RedirectResponse { $this->authorize('create', Statuslabel::class); // create a new model instance @@ -96,10 +90,8 @@ class StatuslabelsController extends Controller * Statuslabel update. * * @param int $statuslabelId - * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse - * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function edit($statuslabelId = null) + public function edit($statuslabelId = null) : View | RedirectResponse { $this->authorize('update', Statuslabel::class); // Check if the Statuslabel exists @@ -119,10 +111,8 @@ class StatuslabelsController extends Controller * Statuslabel update form processing page. * * @param int $statuslabelId - * @return \Illuminate\Http\RedirectResponse - * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function update(Request $request, $statuslabelId = null) + public function update(Request $request, $statuslabelId = null) : RedirectResponse { $this->authorize('update', Statuslabel::class); // Check if the Statuslabel exists @@ -159,10 +149,8 @@ class StatuslabelsController extends Controller * Delete the given Statuslabel. * * @param int $statuslabelId - * @return \Illuminate\Http\RedirectResponse - * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function destroy($statuslabelId) + public function destroy($statuslabelId) : RedirectResponse { $this->authorize('delete', Statuslabel::class); // Check if the Statuslabel exists diff --git a/app/Http/Controllers/SuppliersController.php b/app/Http/Controllers/SuppliersController.php index 86b6147bd4..e96e32b84f 100755 --- a/app/Http/Controllers/SuppliersController.php +++ b/app/Http/Controllers/SuppliersController.php @@ -5,6 +5,8 @@ namespace App\Http\Controllers; use App\Http\Requests\ImageUploadRequest; use App\Models\Supplier; use Illuminate\Support\Facades\Auth; +use Illuminate\Http\RedirectResponse; +use \Illuminate\Contracts\View\View; /** * This controller handles all actions related to Suppliers for @@ -20,25 +22,19 @@ class SuppliersController extends Controller * @return \Illuminate\Contracts\View\View * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function index() + public function index() : View { - // Grab all the suppliers $this->authorize('view', Supplier::class); - - // Show the page return view('suppliers/index'); } /** * Supplier create. * - * @return \Illuminate\Contracts\View\View - * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function create() + public function create() : View { $this->authorize('create', Supplier::class); - return view('suppliers/edit')->with('item', new Supplier); } @@ -46,10 +42,8 @@ class SuppliersController extends Controller * Supplier create form processing. * * @param ImageUploadRequest $request - * @return \Illuminate\Http\RedirectResponse - * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function store(ImageUploadRequest $request) + public function store(ImageUploadRequest $request) : RedirectResponse { $this->authorize('create', Supplier::class); // Create a new supplier @@ -82,10 +76,8 @@ class SuppliersController extends Controller * Supplier update. * * @param int $supplierId - * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse - * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function edit($supplierId = null) + public function edit($supplierId = null) : View | RedirectResponse { $this->authorize('update', Supplier::class); // Check if the supplier exists @@ -102,15 +94,12 @@ class SuppliersController extends Controller * Supplier update form processing page. * * @param int $supplierId - * @return \Illuminate\Http\RedirectResponse - * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function update($supplierId, ImageUploadRequest $request) + public function update($supplierId, ImageUploadRequest $request) : RedirectResponse { $this->authorize('update', Supplier::class); - // Check if the supplier exists + if (is_null($supplier = Supplier::find($supplierId))) { - // Redirect to the supplier page return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.does_not_exist')); } @@ -141,10 +130,8 @@ class SuppliersController extends Controller * Delete the given supplier. * * @param int $supplierId - * @return \Illuminate\Http\RedirectResponse - * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function destroy($supplierId) + public function destroy($supplierId) : RedirectResponse { $this->authorize('delete', Supplier::class); if (is_null($supplier = Supplier::with('asset_maintenances', 'assets', 'licenses')->withCount('asset_maintenances as asset_maintenances_count', 'assets as assets_count', 'licenses as licenses_count')->find($supplierId))) { @@ -174,10 +161,9 @@ class SuppliersController extends Controller * Get the asset information to present to the supplier view page * * @param null $supplierId - * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @internal param int $assetId */ - public function show($supplierId = null) + public function show($supplierId = null) : View | RedirectResponse { $this->authorize('view', Supplier::class); $supplier = Supplier::find($supplierId); diff --git a/app/Http/Controllers/ViewAssetsController.php b/app/Http/Controllers/ViewAssetsController.php index 87a993fa1f..db4afc8322 100755 --- a/app/Http/Controllers/ViewAssetsController.php +++ b/app/Http/Controllers/ViewAssetsController.php @@ -8,11 +8,11 @@ use App\Models\AssetModel; use App\Models\Company; use App\Models\Setting; use App\Models\User; -use App\Models\CustomField; use App\Notifications\RequestAssetCancelation; use App\Notifications\RequestAssetNotification; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Auth; +use Illuminate\Http\RedirectResponse; +use \Illuminate\Contracts\View\View; /** * This controller handles all actions related to the ability for users @@ -25,9 +25,8 @@ class ViewAssetsController extends Controller /** * Redirect to the profile page. * - * @return \Illuminate\Http\RedirectResponse */ - public function getIndex() + public function getIndex() : View | RedirectResponse { $user = User::with( 'assets', @@ -72,9 +71,8 @@ class ViewAssetsController extends Controller /** * Returns view of requestable items for a user. - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function getRequestableIndex() + public function getRequestableIndex() : View { $assets = Asset::with('model', 'defaultLoc', 'location', 'assignedTo', 'requests')->Hardware()->RequestableAssets(); $models = AssetModel::with('category', 'requests', 'assets')->RequestableModels()->get(); @@ -82,7 +80,7 @@ class ViewAssetsController extends Controller return view('account/requestable-assets', compact('assets', 'models')); } - public function getRequestItem(Request $request, $itemType, $itemId = null, $cancel_by_admin = false, $requestingUser = null) + public function getRequestItem(Request $request, $itemType, $itemId = null, $cancel_by_admin = false, $requestingUser = null) : RedirectResponse { $item = null; $fullItemType = 'App\\Models\\'.studly_case($itemType); @@ -144,9 +142,8 @@ class ViewAssetsController extends Controller /** * Process a specific requested asset * @param null $assetId - * @return \Illuminate\Http\RedirectResponse */ - public function getRequestAsset($assetId = null) + public function getRequestAsset($assetId = null) : RedirectResponse { $user = auth()->user(); @@ -196,7 +193,7 @@ class ViewAssetsController extends Controller return redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.success')); } - public function getRequestedAssets() + public function getRequestedAssets() : View { return view('account/requested'); }