Skip to content

A free open source IT asset/license management system

Clean up unreachable code (via phpstan)

sniped9a86f5f29c0
diff --git a/app/Console/Commands/LdapTroubleshooter.php b/app/Console/Commands/LdapTroubleshooter.php
index b2c430e1fa..e7b5583eea 100644
--- a/app/Console/Commands/LdapTroubleshooter.php
+++ b/app/Console/Commands/LdapTroubleshooter.php
@@ -627,13 +627,11 @@ class LdapTroubleshooter extends Command
posix_kill($parent_pid, SIGUSR2);
}
exit();
- break; // yes I know we don't need it.
case -1:
// couldn't fork
$this->error('COULD NOT FORK - assuming failure');
return false;
- break; // I still know that we don't need it
default:
// we remain the 'parent', $pid is the PID of the forked process.
$siginfo = [];
@@ -645,7 +643,6 @@ class LdapTroubleshooter extends Command
return false;
}
- break; // Yeah I get it already, shush.
}
}
diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php
index 83b6cb1e40..72e652848e 100644
--- a/app/Helpers/Helper.php
+++ b/app/Helpers/Helper.php
@@ -1642,7 +1642,6 @@ class Helper
{
if (config('app.lock_passwords') === true) {
return true;
- Log::debug('app locked!');
}
return false;
@@ -1699,8 +1698,6 @@ class Helper
return (1 / 72) * static::getUnitConversionFactor('in');
default:
throw new \InvalidArgumentException('Unit: '.e($unit).' is not supported');
-
- return false;
}
}
diff --git a/app/Http/Controllers/ActionlogController.php b/app/Http/Controllers/ActionlogController.php
index 12a74cdf28..059275e6cc 100644
--- a/app/Http/Controllers/ActionlogController.php
+++ b/app/Http/Controllers/ActionlogController.php
@@ -49,27 +49,24 @@ class ActionlogController extends Controller
{
$filename = basename((string) $filename);
- if ($actionlog = Actionlog::where('filename', $filename)->with('user')->with('target')->firstOrFail()) {
+ $actionlog = Actionlog::where('filename', $filename)->with('user')->with('target')->firstOrFail();
- $this->authorize('view', $actionlog->target);
- $this->authorize('view', $actionlog->user);
+ $this->authorize('view', $actionlog->target);
+ $this->authorize('view', $actionlog->user);
- if (config('filesystems.default') == 's3_private') {
- return redirect()->away(Storage::disk('s3_private')->temporaryUrl('private_uploads/eula-pdfs/'.$filename, now()->addMinutes(5)));
- }
-
- if (Storage::exists('private_uploads/eula-pdfs/'.$filename)) {
+ if (config('filesystems.default') == 's3_private') {
+ return redirect()->away(Storage::disk('s3_private')->temporaryUrl('private_uploads/eula-pdfs/'.$filename, now()->addMinutes(5)));
+ }
- if (request()->input('inline') == 'true') {
- return response()->file(config('app.private_uploads').'/eula-pdfs/'.$filename);
- }
+ if (Storage::exists('private_uploads/eula-pdfs/'.$filename)) {
- return response()->download(config('app.private_uploads').'/eula-pdfs/'.$filename);
+ if (request()->input('inline') == 'true') {
+ return response()->file(config('app.private_uploads').'/eula-pdfs/'.$filename);
}
- return redirect()->back()->with('error', trans('general.file_does_not_exist'));
+ return response()->download(config('app.private_uploads').'/eula-pdfs/'.$filename);
}
- return redirect()->back()->with('error', trans('general.record_not_found'));
+ return redirect()->back()->with('error', trans('general.file_does_not_exist'));
}
}
diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php
index e8043cf678..5e9b0aea69 100755
--- a/app/Http/Controllers/Assets/AssetsController.php
+++ b/app/Http/Controllers/Assets/AssetsController.php
@@ -341,68 +341,64 @@ class AssetsController extends Controller
$this->authorize('view', $asset);
$settings = Setting::getSettings();
- if (isset($asset)) {
- $audit_log = Actionlog::where('action_type', '=', 'audit')
- ->where('item_id', '=', $asset->id)
- ->where('item_type', '=', Asset::class)
- ->orderBy('created_at', 'DESC')->first();
-
- if ($asset->location) {
- $use_currency = $asset->location->currency;
- } else {
- if ($settings->default_currency != '') {
- $use_currency = $settings->default_currency;
- } else {
- $use_currency = trans('general.currency');
- }
- }
+ $audit_log = Actionlog::where('action_type', '=', 'audit')
+ ->where('item_id', '=', $asset->id)
+ ->where('item_type', '=', Asset::class)
+ ->orderBy('created_at', 'DESC')->first();
- $qr_code = (object) [
- 'display' => $settings->qr_code == '1',
- 'url' => route('qr_code/common', ['object_type' => 'hardware', 'id' => $asset->id]),
- ];
-
- $total_maintenance_cost = $asset->maintenances?->sum('cost');
- $total_asset_cost = ($asset->assignedAssets()?->AssetsForShow()) ? $asset->assignedAssets()?->AssetsForShow()?->sum('purchase_cost') : 0;
- $total_license_cost = ($asset->licenses) ? $asset->licenses->sum('purchase_cost') : 0;
- // accessories.purchase_cost no longer exists; getAccessoryCost()
- // walks lastOrderDefaults() per attached accessory so the total
- // reflects each item's last acquisition (with the parent's
- // default_purchase_cost as fallback).
- $total_accessory_cost = $asset->getAccessoryCost();
- $total_component_cost = ($asset->components) ? $asset->components->sum('calculated_purchase_cost') : 0;
-
- $total_cost_for_asset = $asset->purchase_cost + $total_maintenance_cost + $total_asset_cost + $total_license_cost + $total_accessory_cost + $total_component_cost;
-
- $audit_custom_field_columns = [];
- if ($asset->model && $asset->model->fieldset) {
- $audit_custom_field_columns = $asset->model->fieldset->fields
- ->where('display_audit', '1')
- ->map(fn ($field) => [
- 'field' => $field->db_column,
- 'searchable' => false,
- 'sortable' => false,
- 'switchable' => true,
- 'title' => e($field->name),
- 'visible' => true,
- ])
- ->values()
- ->all();
+ if ($asset->location) {
+ $use_currency = $asset->location->currency;
+ } else {
+ if ($settings->default_currency != '') {
+ $use_currency = $settings->default_currency;
+ } else {
+ $use_currency = trans('general.currency');
}
+ }
- return view('hardware/view', compact('asset', 'qr_code', 'settings'))
- ->with('total_maintenance_cost', $total_maintenance_cost)
- ->with('total_asset_cost', $total_asset_cost)
- ->with('total_license_cost', $total_license_cost)
- ->with('total_accessory_cost', $total_accessory_cost)
- ->with('total_component_cost', $total_component_cost)
- ->with('total_cost_for_asset', $total_cost_for_asset)
- ->with('use_currency', $use_currency)
- ->with('audit_log', $audit_log)
- ->with('audit_custom_field_columns', $audit_custom_field_columns);
+ $qr_code = (object) [
+ 'display' => $settings->qr_code == '1',
+ 'url' => route('qr_code/common', ['object_type' => 'hardware', 'id' => $asset->id]),
+ ];
+
+ $total_maintenance_cost = $asset->maintenances?->sum('cost');
+ $total_asset_cost = ($asset->assignedAssets()?->AssetsForShow()) ? $asset->assignedAssets()?->AssetsForShow()?->sum('purchase_cost') : 0;
+ $total_license_cost = ($asset->licenses) ? $asset->licenses->sum('purchase_cost') : 0;
+ // accessories.purchase_cost no longer exists; getAccessoryCost()
+ // walks lastOrderDefaults() per attached accessory so the total
+ // reflects each item's last acquisition (with the parent's
+ // default_purchase_cost as fallback).
+ $total_accessory_cost = $asset->getAccessoryCost();
+ $total_component_cost = ($asset->components) ? $asset->components->sum('calculated_purchase_cost') : 0;
+
+ $total_cost_for_asset = $asset->purchase_cost + $total_maintenance_cost + $total_asset_cost + $total_license_cost + $total_accessory_cost + $total_component_cost;
+
+ $audit_custom_field_columns = [];
+ if ($asset->model && $asset->model->fieldset) {
+ $audit_custom_field_columns = $asset->model->fieldset->fields
+ ->where('display_audit', '1')
+ ->map(fn ($field) => [
+ 'field' => $field->db_column,
+ 'searchable' => false,
+ 'sortable' => false,
+ 'switchable' => true,
+ 'title' => e($field->name),
+ 'visible' => true,
+ ])
+ ->values()
+ ->all();
}
- return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
+ return view('hardware/view', compact('asset', 'qr_code', 'settings'))
+ ->with('total_maintenance_cost', $total_maintenance_cost)
+ ->with('total_asset_cost', $total_asset_cost)
+ ->with('total_license_cost', $total_license_cost)
+ ->with('total_accessory_cost', $total_accessory_cost)
+ ->with('total_component_cost', $total_component_cost)
+ ->with('total_cost_for_asset', $total_cost_for_asset)
+ ->with('use_currency', $use_currency)
+ ->with('audit_log', $audit_log)
+ ->with('audit_custom_field_columns', $audit_custom_field_columns);
}
/**
diff --git a/app/Http/Traits/CheckInOutTrait.php b/app/Http/Traits/CheckInOutTrait.php
index fc60cdd761..68b9386c7d 100644
--- a/app/Http/Traits/CheckInOutTrait.php
+++ b/app/Http/Traits/CheckInOutTrait.php
@@ -23,8 +23,6 @@ trait CheckInOutTrait
default:
return User::findOrFail(request('assigned_user'));
}
-
- return null;
}
/**
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 1af97761f0..0f2fe30ade 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -390,12 +390,6 @@ parameters:
count: 1
path: app/Console/Commands/LdapTroubleshooter.php
- -
- message: '#^Unreachable statement \- code above always terminates\.$#'
- identifier: deadCode.unreachable
- count: 3
- path: app/Console/Commands/LdapTroubleshooter.php
-
-
message: '#^Variable \$conn might not be defined\.$#'
identifier: variable.undefined
@@ -864,12 +858,6 @@ parameters:
count: 1
path: app/Helpers/Helper.php
- -
- message: '#^Unreachable statement \- code above always terminates\.$#'
- identifier: deadCode.unreachable
- count: 2
- path: app/Helpers/Helper.php
-
-
message: '#^Variable \$permissions on left side of \?\? always exists and is not nullable\.$#'
identifier: nullCoalesce.variable
@@ -990,12 +978,6 @@ parameters:
count: 1
path: app/Http/Controllers/Accessories/AccessoryCheckoutController.php
- -
- message: '#^Unreachable statement \- code above always terminates\.$#'
- identifier: deadCode.unreachable
- count: 1
- path: app/Http/Controllers/Accessories/AccessoryCheckoutController.php
-
-
message: '#^Using nullsafe property access "\?\-\>name" on left side of \?\? is unnecessary\. Use \-\> instead\.$#'
identifier: nullsafe.neverNull
@@ -1014,18 +996,6 @@ parameters:
count: 1
path: app/Http/Controllers/Account/AcceptanceController.php
- -
- message: '#^If condition is always true\.$#'
- identifier: if.alwaysTrue
- count: 1
- path: app/Http/Controllers/ActionlogController.php
-
- -
- message: '#^Unreachable statement \- code above always terminates\.$#'
- identifier: deadCode.unreachable
- count: 1
- path: app/Http/Controllers/ActionlogController.php
-
-
message: '#^Access to an undefined property App\\Models\\Accessory\:\:\$checkout_qty\.$#'
identifier: property.notFound
@@ -1128,12 +1098,6 @@ parameters:
count: 1
path: app/Http/Controllers/Api/AccessoriesController.php
- -
- message: '#^Unreachable statement \- code above always terminates\.$#'
- identifier: deadCode.unreachable
- count: 1
- path: app/Http/Controllers/Api/AccessoriesController.php
-
-
message: '#^Access to an undefined property App\\Models\\AssetModel\:\:\$use_image\.$#'
identifier: property.notFound
@@ -2244,12 +2208,6 @@ parameters:
count: 1
path: app/Http/Controllers/Assets/AssetCheckoutController.php
- -
- message: '#^Unreachable statement \- code above always terminates\.$#'
- identifier: deadCode.unreachable
- count: 1
- path: app/Http/Controllers/Assets/AssetCheckoutController.php
-
-
message: '#^Using nullsafe property access "\?\-\>name" on left side of \?\? is unnecessary\. Use \-\> instead\.$#'
identifier: nullsafe.neverNull
@@ -2370,24 +2328,12 @@ parameters:
count: 2
path: app/Http/Controllers/Assets/AssetsController.php
- -
- message: '#^Unreachable statement \- code above always terminates\.$#'
- identifier: deadCode.unreachable
- count: 1
- path: app/Http/Controllers/Assets/AssetsController.php
-
-
message: '#^Using nullsafe method call on non\-nullable type Illuminate\\Database\\Eloquent\\Relations\\Relation\. Use \-\> instead\.$#'
identifier: nullsafe.neverNull
count: 2
path: app/Http/Controllers/Assets/AssetsController.php
- -
- message: '#^Variable \$asset in isset\(\) always exists and is not nullable\.$#'
- identifier: isset.variable
- count: 1
- path: app/Http/Controllers/Assets/AssetsController.php
-
-
message: '#^Variable \$serial_errors in empty\(\) always exists and is always falsy\.$#'
identifier: empty.variable
@@ -2430,12 +2376,6 @@ parameters:
count: 1
path: app/Http/Controllers/Assets/BulkAssetsController.php
- -
- message: '#^Unreachable statement \- code above always terminates\.$#'
- identifier: deadCode.unreachable
- count: 1
- path: app/Http/Controllers/Assets/BulkAssetsController.php
-
-
message: '#^Access to an undefined property App\\Http\\Controllers\\Auth\\LoginController\:\:\$decayMinutes\.$#'
identifier: property.notFound
@@ -2988,12 +2928,6 @@ parameters:
count: 1
path: app/Http/Controllers/Kits/CheckoutKitController.php
- -
- message: '#^Unreachable statement \- code above always terminates\.$#'
- identifier: deadCode.unreachable
- count: 1
- path: app/Http/Controllers/Kits/CheckoutKitController.php
-
-
message: '#^Access to an undefined property App\\Models\\PredefinedKit\:\:\$created_by\.$#'
identifier: property.notFound