Skip to content

A free open source IT asset/license management system

Switch to using Handler::reportOrRethrow to avoid Exception is never thrown

snipe9674befcef6b
diff --git a/app/Http/Controllers/Api/CategoriesController.php b/app/Http/Controllers/Api/CategoriesController.php
index b46a2946c4..84a9c9f966 100644
--- a/app/Http/Controllers/Api/CategoriesController.php
+++ b/app/Http/Controllers/Api/CategoriesController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api;
use App\Actions\Categories\DestroyCategoryAction;
+use App\Exceptions\Handler;
use App\Exceptions\ItemStillHasChildren;
use App\Helpers\Helper;
use App\Http\Controllers\Controller;
@@ -240,8 +241,8 @@ class CategoriesController extends Controller
return response()->json(
Helper::formatStandardApiResponse('error', null, trans('general.bulk_delete_associations.general_assoc_warning', ['asset_type' => $category->category_type]))
);
- } catch (\Exception $e) {
- report($e);
+ } catch (\Throwable $e) {
+ Handler::reportOrRethrow($e);
return response()->json(
Helper::formatStandardApiResponse('error', null, trans('general.something_went_wrong'))
diff --git a/app/Http/Controllers/Api/ManufacturersController.php b/app/Http/Controllers/Api/ManufacturersController.php
index 93938bb1fc..ce06e76ce1 100644
--- a/app/Http/Controllers/Api/ManufacturersController.php
+++ b/app/Http/Controllers/Api/ManufacturersController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api;
use App\Actions\Manufacturers\DestroyManufacturerAction;
+use App\Exceptions\Handler;
use App\Exceptions\ItemStillHasChildren;
use App\Helpers\Helper;
use App\Http\Controllers\Controller;
@@ -216,8 +217,8 @@ class ManufacturersController extends Controller
DestroyManufacturerAction::run($manufacturer);
} catch (ItemStillHasChildren $e) {
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.bulk_delete_associations.general_assoc_warning', ['item' => trans('general.manufacturer')])));
- } catch (\Exception $e) {
- report($e);
+ } catch (\Throwable $e) {
+ Handler::reportOrRethrow($e);
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.something_went_wrong')));
}
diff --git a/app/Http/Controllers/Api/SuppliersController.php b/app/Http/Controllers/Api/SuppliersController.php
index 0eb045d2b3..b0fe754e7a 100644
--- a/app/Http/Controllers/Api/SuppliersController.php
+++ b/app/Http/Controllers/Api/SuppliersController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api;
use App\Actions\Suppliers\DestroySupplierAction;
+use App\Exceptions\Handler;
use App\Exceptions\ItemStillHasAccessories;
use App\Exceptions\ItemStillHasAssets;
use App\Exceptions\ItemStillHasComponents;
@@ -235,8 +236,8 @@ class SuppliersController extends Controller
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.bulk_delete_associations.assoc_components', [
'components_count' => (int) $supplier->components_count, 'item' => trans('general.supplier'),
])));
- } catch (\Exception $e) {
- report($e);
+ } catch (\Throwable $e) {
+ Handler::reportOrRethrow($e);
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.something_went_wrong')));
}
diff --git a/app/Http/Controllers/BulkCategoriesController.php b/app/Http/Controllers/BulkCategoriesController.php
index 943907b0ed..62d0c38aaa 100644
--- a/app/Http/Controllers/BulkCategoriesController.php
+++ b/app/Http/Controllers/BulkCategoriesController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Actions\Categories\DestroyCategoryAction;
+use App\Exceptions\Handler;
use App\Exceptions\ItemStillHasAccessories;
use App\Exceptions\ItemStillHasAssetModels;
use App\Exceptions\ItemStillHasAssets;
@@ -43,8 +44,8 @@ class BulkCategoriesController extends Controller
$errors[] = trans('general.bulk_delete_associations.assoc_consumables_no_count', ['item_name' => $category->name, 'item' => trans('general.category')]);
} catch (ItemStillHasLicenses) {
$errors[] = trans('general.bulk_delete_associations.assoc_licenses_no_count', ['item_name' => $category->name, 'item' => trans('general.category')]);
- } catch (\Exception $e) {
- report($e);
+ } catch (\Throwable $e) {
+ Handler::reportOrRethrow($e);
$errors[] = trans('general.something_went_wrong');
}
}
diff --git a/app/Http/Controllers/BulkCompaniesController.php b/app/Http/Controllers/BulkCompaniesController.php
index 77ee14bc7b..40999880b9 100644
--- a/app/Http/Controllers/BulkCompaniesController.php
+++ b/app/Http/Controllers/BulkCompaniesController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Actions\Companies\DestroyCompanyAction;
+use App\Exceptions\Handler;
use App\Exceptions\ItemStillHasAccessories;
use App\Exceptions\ItemStillHasAssets;
use App\Exceptions\ItemStillHasChildCompanies;
@@ -46,8 +47,8 @@ class BulkCompaniesController extends Controller
$errors[] = trans('general.bulk_delete_associations.assoc_users_no_count', ['item_name' => $company->name, 'item' => trans('general.company')]);
} catch (ItemStillHasChildCompanies $e) {
$errors[] = trans('general.bulk_delete_associations.assoc_child_companies_no_count', ['item_name' => $company->name, 'item' => trans('general.company')]);
- } catch (\Exception $e) {
- report($e);
+ } catch (\Throwable $e) {
+ Handler::reportOrRethrow($e);
$errors[] = trans('general.something_went_wrong');
}
}
diff --git a/app/Http/Controllers/BulkDepartmentsController.php b/app/Http/Controllers/BulkDepartmentsController.php
index 0eb988005c..88d8b6fdbc 100644
--- a/app/Http/Controllers/BulkDepartmentsController.php
+++ b/app/Http/Controllers/BulkDepartmentsController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Actions\Departments\DestroyDepartmentAction;
+use App\Exceptions\Handler;
use App\Exceptions\ItemStillHasUsers;
use App\Models\Department;
use Illuminate\Http\Request;
@@ -28,8 +29,8 @@ class BulkDepartmentsController extends Controller
$success_count++;
} catch (ItemStillHasUsers $e) {
$errors[] = trans('general.bulk_delete_associations.assoc_users_no_count', ['item_name' => $department->name, 'item' => trans('general.department')]);
- } catch (\Exception $e) {
- report($e);
+ } catch (\Throwable $e) {
+ Handler::reportOrRethrow($e);
$errors[] = trans('general.something_went_wrong');
}
}
diff --git a/app/Http/Controllers/BulkDepreciationsController.php b/app/Http/Controllers/BulkDepreciationsController.php
index 571beba083..feb0071bd3 100644
--- a/app/Http/Controllers/BulkDepreciationsController.php
+++ b/app/Http/Controllers/BulkDepreciationsController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Actions\Depreciations\DestroyDepreciationAction;
+use App\Exceptions\Handler;
use App\Exceptions\ItemStillHasAssetModels;
use App\Exceptions\ItemStillHasAssets;
use App\Exceptions\ItemStillHasLicenses;
@@ -34,8 +35,8 @@ class BulkDepreciationsController extends Controller
$errors[] = trans('general.bulk_delete_associations.asset_models_no_count', ['item_name' => $depreciation->name, 'item' => trans('general.depreciation')]);
} catch (ItemStillHasLicenses $e) {
$errors[] = trans('general.bulk_delete_associations.assoc_licenses_no_count', ['item_name' => $depreciation->name, 'item' => trans('general.depreciation')]);
- } catch (\Exception $e) {
- report($e);
+ } catch (\Throwable $e) {
+ Handler::reportOrRethrow($e);
$errors[] = trans('general.something_went_wrong');
}
}
diff --git a/app/Http/Controllers/BulkManufacturersController.php b/app/Http/Controllers/BulkManufacturersController.php
index 1690710935..29b2efac0a 100644
--- a/app/Http/Controllers/BulkManufacturersController.php
+++ b/app/Http/Controllers/BulkManufacturersController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Actions\Manufacturers\DestroyManufacturerAction;
+use App\Exceptions\Handler;
use App\Exceptions\ItemStillHasAccessories;
use App\Exceptions\ItemStillHasAssets;
use App\Exceptions\ItemStillHasComponents;
@@ -39,8 +40,8 @@ class BulkManufacturersController extends Controller
$errors[] = trans('general.bulk_delete_associations.assoc_components_no_count', ['item_name' => $manufacturer->name, 'item' => trans('general.manufacturer')]);
} catch (ItemStillHasLicenses $e) {
$errors[] = trans('general.bulk_delete_associations.assoc_licenses_no_count', ['item_name' => $manufacturer->name, 'item' => trans('general.manufacturer')]);
- } catch (\Exception $e) {
- report($e);
+ } catch (\Throwable $e) {
+ Handler::reportOrRethrow($e);
$errors[] = trans('general.something_went_wrong');
}
}
diff --git a/app/Http/Controllers/BulkStatuslabelsController.php b/app/Http/Controllers/BulkStatuslabelsController.php
index 146401eb1f..c48f1c02ab 100644
--- a/app/Http/Controllers/BulkStatuslabelsController.php
+++ b/app/Http/Controllers/BulkStatuslabelsController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Actions\StatusLabels\DestroyStatuslabelAction;
+use App\Exceptions\Handler;
use App\Exceptions\ItemStillHasAssets;
use App\Models\Statuslabel;
use Illuminate\Http\Request;
@@ -28,8 +29,8 @@ class BulkStatuslabelsController extends Controller
$success_count++;
} catch (ItemStillHasAssets $e) {
$errors[] = trans('general.bulk_delete_associations.assoc_assets_no_count', ['item_name' => $statuslabel->name, 'item' => trans('admin/statuslabels/table.status_label')]);
- } catch (\Exception $e) {
- report($e);
+ } catch (\Throwable $e) {
+ Handler::reportOrRethrow($e);
$errors[] = trans('general.something_went_wrong');
}
}
diff --git a/app/Http/Controllers/BulkSuppliersController.php b/app/Http/Controllers/BulkSuppliersController.php
index dc21cdf558..8bf4224ea5 100644
--- a/app/Http/Controllers/BulkSuppliersController.php
+++ b/app/Http/Controllers/BulkSuppliersController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Actions\Suppliers\DestroySupplierAction;
+use App\Exceptions\Handler;
use App\Exceptions\ItemStillHasAccessories;
use App\Exceptions\ItemStillHasAssets;
use App\Exceptions\ItemStillHasComponents;
@@ -43,8 +44,8 @@ class BulkSuppliersController extends Controller
$errors[] = trans('general.bulk_delete_associations.assoc_consumables', ['consumables_count' => (int) $supplier->consumables_count, 'item' => trans('general.supplier'), 'item_name' => $supplier->name]);
} catch (ItemStillHasComponents $e) {
$errors[] = trans('general.bulk_delete_associations.assoc_components', ['components_count' => (int) $supplier->components_count, 'item' => trans('general.supplier'), 'item_name' => $supplier->name]);
- } catch (\Exception $e) {
- report($e);
+ } catch (\Throwable $e) {
+ Handler::reportOrRethrow($e);
$errors[] = trans('general.something_went_wrong');
}
}
diff --git a/app/Http/Controllers/CategoriesController.php b/app/Http/Controllers/CategoriesController.php
index 4788d4e2d5..98bd98e367 100755
--- a/app/Http/Controllers/CategoriesController.php
+++ b/app/Http/Controllers/CategoriesController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Actions\Categories\DestroyCategoryAction;
+use App\Exceptions\Handler;
use App\Exceptions\ItemStillHasChildren;
use App\Helpers\Helper;
use App\Http\Requests\ImageUploadRequest;
@@ -164,8 +165,8 @@ class CategoriesController extends Controller
DestroyCategoryAction::run($category);
} catch (ItemStillHasChildren $e) {
return redirect()->route('categories.index')->with('error', trans('general.bulk_delete_associations.general_assoc_warning', ['item' => trans('general.category')]));
- } catch (\Exception $e) {
- report($e);
+ } catch (\Throwable $e) {
+ Handler::reportOrRethrow($e);
return redirect()->route('categories.index')->with('error', trans('admin/categories/message.delete.error'));
}
diff --git a/app/Http/Controllers/ManufacturersController.php b/app/Http/Controllers/ManufacturersController.php
index f87af87c37..e89c93c0c4 100755
--- a/app/Http/Controllers/ManufacturersController.php
+++ b/app/Http/Controllers/ManufacturersController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Actions\Manufacturers\DestroyManufacturerAction;
+use App\Exceptions\Handler;
use App\Exceptions\ItemStillHasChildren;
use App\Http\Requests\ImageUploadRequest;
use App\Models\Actionlog;
@@ -179,8 +180,8 @@ class ManufacturersController extends Controller
DestroyManufacturerAction::run($manufacturer);
} catch (ItemStillHasChildren $e) {
return redirect()->route('manufacturers.index')->with('error', trans('general.bulk_delete_associations.general_assoc_warning', ['item' => trans('general.manufacturer')]));
- } catch (\Exception $e) {
- report($e);
+ } catch (\Throwable $e) {
+ Handler::reportOrRethrow($e);
return redirect()->route('manufacturers.index')->with('error', trans('general.something_went_wrong'));
}
diff --git a/app/Http/Controllers/SuppliersController.php b/app/Http/Controllers/SuppliersController.php
index 1128743e7d..84b104c240 100755
--- a/app/Http/Controllers/SuppliersController.php
+++ b/app/Http/Controllers/SuppliersController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Actions\Suppliers\DestroySupplierAction;
+use App\Exceptions\Handler;
use App\Exceptions\ItemStillHasAccessories;
use App\Exceptions\ItemStillHasAssets;
use App\Exceptions\ItemStillHasComponents;
@@ -156,8 +157,8 @@ class SuppliersController extends Controller
return redirect()->route('suppliers.index')->with('error', trans('general.bulk_delete_associations.assoc_components', [
'components_count' => (int) $supplier->components_count, 'item' => trans('general.supplier'),
]));
- } catch (\Exception $e) {
- report($e);
+ } catch (\Throwable $e) {
+ Handler::reportOrRethrow($e);
return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.delete.error'));
}
diff --git a/app/Http/Controllers/Users/LDAPImportController.php b/app/Http/Controllers/Users/LDAPImportController.php
index 48d2a15568..74345f9fb7 100644
--- a/app/Http/Controllers/Users/LDAPImportController.php
+++ b/app/Http/Controllers/Users/LDAPImportController.php
@@ -34,11 +34,6 @@ class LDAPImportController extends Controller
if (! auth()->user()?->isSuperUser()) {
abort(403);
}
- try {
- // $this->ldap->connect(); I don't think this actually exists in LdapAd.php, and we don't really 'persist' LDAP connections anyways...right?
- } catch (\Exception $e) {
- return redirect()->route('users.index')->with('error', $e->getMessage());
- }
return view('users/ldap');
}
diff --git a/app/Models/Labels/FieldOption.php b/app/Models/Labels/FieldOption.php
index 9661b686ca..5810bdcade 100644
--- a/app/Models/Labels/FieldOption.php
+++ b/app/Models/Labels/FieldOption.php
@@ -4,7 +4,6 @@ namespace App\Models\Labels;
use App\Models\Asset;
use App\Models\User;
-use App\Helpers\Helper;
class FieldOption
{
@@ -32,7 +31,7 @@ class FieldOption
if (in_array($dataPath[0], ['assignedTo', 'displayName'])) {
$assigned = $asset->relationLoaded('assignedTo') ? $asset->assigned : $asset->assignedTo;
- if (!$assigned) {
+ if (! $assigned) {
return null;
}
if ($dataPath[0] === 'displayName') {
@@ -41,6 +40,7 @@ class FieldOption
if ($assigned instanceof User) {
return $assigned->full_name;
}
+
return $assigned->name ?? $assigned->display_name ?? null;
}
@@ -50,16 +50,17 @@ class FieldOption
}
if ($dataPath[0] === 'warranty_months') {
- return ($asset->warranty_months > 0) ? e($asset->warranty_months . ' ' . trans('admin/hardware/form.months')) : null;
+ return ($asset->warranty_months > 0) ? e($asset->warranty_months.' '.trans('admin/hardware/form.months')) : null;
}
if ($dataPath[0] === 'warranty_expires') {
return ($asset->warranty_months > 0) ? $asset->warranty_expires->toDateString() : null;
}
+
return $dataPath->reduce(
function ($myValue, $path) {
try {
return $myValue ? $myValue->{$path} : ${$myValue};
- } catch (\Exception $e) {
+ } catch (\Throwable $e) {
return $myValue;
}
}, $asset
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 0f2fe30ade..85d66c4c5f 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -1266,12 +1266,6 @@ parameters:
count: 2
path: app/Http/Controllers/Api/CategoriesController.php
- -
- message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
- identifier: catch.neverThrown
- count: 1
- path: app/Http/Controllers/Api/CategoriesController.php
-
-
message: '#^Method Illuminate\\Filesystem\\FilesystemAdapter\:\:url\(\) invoked with 2 parameters, 1 required\.$#'
identifier: arguments.count
@@ -1770,12 +1764,6 @@ parameters:
count: 2
path: app/Http/Controllers/Api/ManufacturersController.php
- -
- message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
- identifier: catch.neverThrown
- count: 1
- path: app/Http/Controllers/Api/ManufacturersController.php
-
-
message: '#^Method Illuminate\\Filesystem\\FilesystemAdapter\:\:url\(\) invoked with 2 parameters, 1 required\.$#'
identifier: arguments.count
@@ -1950,12 +1938,6 @@ parameters:
count: 2
path: app/Http/Controllers/Api/SuppliersController.php
- -
- message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
- identifier: catch.neverThrown
- count: 1
- path: app/Http/Controllers/Api/SuppliersController.php
-
-
message: '#^Method Illuminate\\Filesystem\\FilesystemAdapter\:\:url\(\) invoked with 2 parameters, 1 required\.$#'
identifier: arguments.count
@@ -2526,48 +2508,12 @@ parameters:
count: 1
path: app/Http/Controllers/Auth/SamlController.php
- -
- message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
- identifier: catch.neverThrown
- count: 1
- path: app/Http/Controllers/BulkCategoriesController.php
-
- -
- message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
- identifier: catch.neverThrown
- count: 1
- path: app/Http/Controllers/BulkCompaniesController.php
-
- -
- message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
- identifier: catch.neverThrown
- count: 1
- path: app/Http/Controllers/BulkDepartmentsController.php
-
- -
- message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
- identifier: catch.neverThrown
- count: 1
- path: app/Http/Controllers/BulkDepreciationsController.php
-
-
message: '#^Access to an undefined property App\\Models\\Actionlog\:\:\$created_by\.$#'
identifier: property.notFound
count: 1
path: app/Http/Controllers/BulkMaintenancesController.php
- -
- message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
- identifier: catch.neverThrown
- count: 1
- path: app/Http/Controllers/BulkManufacturersController.php
-
- -
- message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
- identifier: catch.neverThrown
- count: 1
- path: app/Http/Controllers/BulkStatuslabelsController.php
-
-
message: '#^Access to an undefined property App\\Models\\Supplier\|Illuminate\\Database\\Eloquent\\Collection\<int, App\\Models\\Supplier\>\:\:\$accessories_count\.$#'
identifier: property.notFound
@@ -2592,12 +2538,6 @@ parameters:
count: 1
path: app/Http/Controllers/BulkSuppliersController.php
- -
- message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
- identifier: catch.neverThrown
- count: 1
- path: app/Http/Controllers/BulkSuppliersController.php
-
-
message: '#^Access to an undefined property App\\Models\\Category\:\:\$created_by\.$#'
identifier: property.notFound
@@ -2610,12 +2550,6 @@ parameters:
count: 2
path: app/Http/Controllers/CategoriesController.php
- -
- message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
- identifier: catch.neverThrown
- count: 1
- path: app/Http/Controllers/CategoriesController.php
-
-
message: '#^PHPDoc tag @param references unknown parameter\: \$categoryId$#'
identifier: parameter.notFound
@@ -3270,12 +3204,6 @@ parameters:
count: 2
path: app/Http/Controllers/ManufacturersController.php
- -
- message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
- identifier: catch.neverThrown
- count: 1
- path: app/Http/Controllers/ManufacturersController.php
-
-
message: '#^PHPDoc tag @param for parameter \$request with type Illuminate\\Http\\Request is not subtype of native type App\\Http\\Requests\\ImageUploadRequest\.$#'
identifier: parameter.phpDocType
@@ -3648,12 +3576,6 @@ parameters:
count: 2
path: app/Http/Controllers/SuppliersController.php
- -
- message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
- identifier: catch.neverThrown
- count: 1
- path: app/Http/Controllers/SuppliersController.php
-
-
message: '#^PHPDoc tag @param references unknown parameter\: \$supplierId$#'
identifier: parameter.notFound
@@ -3738,12 +3660,6 @@ parameters:
count: 2
path: app/Http/Controllers/Users/ImpersonateController.php
- -
- message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
- identifier: catch.neverThrown
- count: 1
- path: app/Http/Controllers/Users/LDAPImportController.php
-
-
message: '#^Access to an undefined property App\\Models\\AccessoryCheckout\:\:\$created_by\.$#'
identifier: property.notFound
@@ -7483,7 +7399,7 @@ parameters:
path: app/Models/Labels/FieldOption.php
-
- message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
+ message: '#^Dead catch \- Throwable is never thrown in the try block\.$#'
identifier: catch.neverThrown
count: 1
path: app/Models/Labels/FieldOption.php