Skip to content

A free open source IT asset/license management system

Small phpstan fixes

snipe19a907720c54
diff --git a/app/Http/Controllers/Accessories/AccessoriesController.php b/app/Http/Controllers/Accessories/AccessoriesController.php
index cc19a704d0..82b9f077e2 100755
--- a/app/Http/Controllers/Accessories/AccessoriesController.php
+++ b/app/Http/Controllers/Accessories/AccessoriesController.php
@@ -159,11 +159,15 @@ class AccessoriesController extends Controller
// create-form input names so enrichInitialOrderFromRequest
// in store() picks them up on save and writes them onto the
// observer-created initial Order + OrderItem for the new row.
- foreach ($accessory->lastOrderPrefill() as $field => $value) {
- if ($value !== null) {
- $cloned->{$field} = $value;
- }
- }
+ // Explicit assignments (not a foreach) so each typed value from
+ // lastOrderPrefill() lands on the matching typed model property
+ // without going through a mixed intermediate that would fail
+ // larastan's assign.propertyType check.
+ $prefill = $accessory->lastOrderPrefill();
+ $cloned->supplier_id = $prefill['supplier_id'];
+ $cloned->purchase_date = $prefill['purchase_date'];
+ $cloned->purchase_cost = $prefill['purchase_cost'];
+ $cloned->order_number = $prefill['order_number'];
return view('accessories/edit')
->with('cloned_model', $accessory_to_clone)
diff --git a/app/Http/Controllers/Components/ComponentsController.php b/app/Http/Controllers/Components/ComponentsController.php
index 38c1947f37..2bafa01851 100644
--- a/app/Http/Controllers/Components/ComponentsController.php
+++ b/app/Http/Controllers/Components/ComponentsController.php
@@ -252,14 +252,13 @@ class ComponentsController extends Controller
$cloned_component->id = null;
$cloned_component->deleted_at = null;
- // See AccessoriesController::getClone — same rationale for
- // carrying the source item's most recent acquisition context
- // onto the cloned create form.
- foreach ($component->lastOrderPrefill() as $field => $value) {
- if ($value !== null) {
- $cloned_component->{$field} = $value;
- }
- }
+ // See AccessoriesController::getClone for the rationale, including
+ // the note on why these are explicit assignments not a foreach.
+ $prefill = $component->lastOrderPrefill();
+ $cloned_component->supplier_id = $prefill['supplier_id'];
+ $cloned_component->purchase_date = $prefill['purchase_date'];
+ $cloned_component->purchase_cost = $prefill['purchase_cost'];
+ $cloned_component->order_number = $prefill['order_number'];
// Show the page
return view('components/edit')
diff --git a/app/Http/Controllers/Consumables/ConsumablesController.php b/app/Http/Controllers/Consumables/ConsumablesController.php
index 4cb328c9c3..ed43e655d7 100644
--- a/app/Http/Controllers/Consumables/ConsumablesController.php
+++ b/app/Http/Controllers/Consumables/ConsumablesController.php
@@ -255,14 +255,13 @@ class ConsumablesController extends Controller
$consumable->id = null;
$consumable->created_by = null;
- // See AccessoriesController::getClone — same rationale for
- // carrying the source item's most recent acquisition context
- // onto the cloned create form.
- foreach ($consumable_to_close->lastOrderPrefill() as $field => $value) {
- if ($value !== null) {
- $consumable->{$field} = $value;
- }
- }
+ // See AccessoriesController::getClone for the rationale, including
+ // the note on why these are explicit assignments not a foreach.
+ $prefill = $consumable_to_close->lastOrderPrefill();
+ $consumable->supplier_id = $prefill['supplier_id'];
+ $consumable->purchase_date = $prefill['purchase_date'];
+ $consumable->purchase_cost = $prefill['purchase_cost'];
+ $consumable->order_number = $prefill['order_number'];
return view('consumables/edit')
->with('cloned_model', $consumable_to_close)
diff --git a/app/Models/Traits/HasOrders.php b/app/Models/Traits/HasOrders.php
index 3d372f0f7e..4cbbc16998 100644
--- a/app/Models/Traits/HasOrders.php
+++ b/app/Models/Traits/HasOrders.php
@@ -143,9 +143,7 @@ trait HasOrders
* Prefill values for the create / clone form's initial-acquisition
* fields. Distinct from lastOrderDefaults() because this shape
* includes `order_number` (per-shipment, not a "default" concept)
- * and matches the request keys the create form posts back, so a
- * controller can loop the return array to assign values directly
- * onto a cloned model's attributes.
+ * and matches the request keys the create form posts back.
*
* Used by getClone() on Accessories / Consumables / Components to
* carry the source item's most recent acquisition context onto the
@@ -154,26 +152,35 @@ trait HasOrders
* / price for a fast restock. Items with no order history return
* an all-null array.
*
+ * Returns native types (Carbon for purchase_date, float for
+ * purchase_cost) so getClone() can assign directly onto typed
+ * model properties without a coercion step and without tripping
+ * larastan's assign.propertyType on the cast-inferred property
+ * signatures. The @var below is needed because MorphMany::first()
+ * infers to Model|null; the annotation resolves $line to OrderItem
+ * so `->order` and `->price` accesses type through cleanly rather
+ * than falling into the Model::$order baseline ignore bucket.
+ *
* @return array{
* supplier_id: ?int,
- * purchase_date: ?string,
- * purchase_cost: ?string,
+ * purchase_date: ?\Carbon\Carbon,
+ * purchase_cost: ?float,
* order_number: ?string,
* }
*/
public function lastOrderPrefill(): array
{
+ /** @var \App\Models\OrderItem|null $line */
$line = $this->orderItems()
->with('order:id,order_number,supplier_id,purchase_date')
->latest('id')
->first();
- $order = $line?->order;
return [
- 'supplier_id' => $order?->supplier_id,
- 'purchase_date' => $order?->purchase_date?->toDateString(),
- 'purchase_cost' => $line?->price !== null ? (string) $line->price : null,
- 'order_number' => $order?->order_number,
+ 'supplier_id' => $line?->order?->supplier_id,
+ 'purchase_date' => $line?->order?->purchase_date,
+ 'purchase_cost' => $line?->price !== null ? (float) $line->price : null,
+ 'order_number' => $line?->order?->order_number,
];
}
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 92eeba3fd6..eb9f265124 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -1716,12 +1716,6 @@ parameters:
count: 3
path: app/Http/Controllers/Api/MaintenancesController.php
- -
- message: '#^Access to an undefined property App\\Models\\Maintenance\:\:\$asset\.$#'
- identifier: property.notFound
- count: 1
- path: app/Http/Controllers/Api/MaintenancesController.php
-
-
message: '#^Access to an undefined property App\\Models\\Maintenance\:\:\$created_by\.$#'
identifier: property.notFound
@@ -3294,12 +3288,6 @@ parameters:
count: 1
path: app/Http/Controllers/MaintenancesController.php
- -
- message: '#^Access to an undefined property App\\Models\\Maintenance\:\:\$asset\.$#'
- identifier: property.notFound
- count: 6
- path: app/Http/Controllers/MaintenancesController.php
-
-
message: '#^Access to an undefined property App\\Models\\Maintenance\:\:\$created_by\.$#'
identifier: property.notFound
@@ -4218,46 +4206,16 @@ parameters:
count: 2
path: app/Http/Transformers/LocationsTransformer.php
- -
- message: '#^Access to an undefined property App\\Models\\Maintenance\:\:\$asset\.$#'
- identifier: property.notFound
- count: 12
- path: app/Http/Transformers/MaintenancesTransformer.php
-
-
message: '#^Access to an undefined property App\\Models\\Maintenance\:\:\$checkedOutTo\.$#'
identifier: property.notFound
count: 1
path: app/Http/Transformers/MaintenancesTransformer.php
- -
- message: '#^Access to an undefined property App\\Models\\Maintenance\:\:\$completedByUser\.$#'
- identifier: property.notFound
- count: 2
- path: app/Http/Transformers/MaintenancesTransformer.php
-
- -
- message: '#^Access to an undefined property App\\Models\\Maintenance\:\:\$maintenanceType\.$#'
- identifier: property.notFound
- count: 2
- path: app/Http/Transformers/MaintenancesTransformer.php
-
- -
- message: '#^Access to an undefined property App\\Models\\Maintenance\:\:\$responsibleParty\.$#'
- identifier: property.notFound
- count: 2
- path: app/Http/Transformers/MaintenancesTransformer.php
-
- -
- message: '#^Access to an undefined property App\\Models\\Maintenance\:\:\$supplier\.$#'
- identifier: property.notFound
- count: 2
- path: app/Http/Transformers/MaintenancesTransformer.php
-
-
message: '#^Using nullsafe property access on non\-nullable type mixed\. Use \-\> instead\.$#'
identifier: nullsafe.neverNull
- count: 4
+ count: 3
path: app/Http/Transformers/MaintenancesTransformer.php
-
@@ -5253,19 +5211,7 @@ parameters:
-
message: '#^Call to an undefined method Illuminate\\Http\\Client\\Response\:\:getStatusCode\(\)\.$#'
identifier: method.notFound
- count: 4
- path: app/Livewire/SlackSettingsForm.php
-
- -
- message: '#^Result of method Illuminate\\Session\\Store\:\:flash\(\) \(void\) is used\.$#'
- identifier: method.void
- count: 8
- path: app/Livewire/SlackSettingsForm.php
-
- -
- message: '#^Unreachable statement \- code above always terminates\.$#'
- identifier: deadCode.unreachable
- count: 2
+ count: 1
path: app/Livewire/SlackSettingsForm.php
-
@@ -5760,6 +5706,12 @@ parameters:
count: 6
path: app/Models/Accessory.php
+ -
+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$order_number\.$#'
+ identifier: property.notFound
+ count: 1
+ path: app/Models/Accessory.php
+
-
message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$price\.$#'
identifier: property.notFound
@@ -5767,11 +5719,17 @@ parameters:
path: app/Models/Accessory.php
-
- message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$supplier_id\.$#'
+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$purchase_date\.$#'
identifier: property.notFound
count: 1
path: app/Models/Accessory.php
+ -
+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$supplier_id\.$#'
+ identifier: property.notFound
+ count: 2
+ path: app/Models/Accessory.php
+
-
message: '#^Call to function is_array\(\) with string will always evaluate to false\.$#'
identifier: function.impossibleType
@@ -6054,6 +6012,12 @@ parameters:
count: 6
path: app/Models/Asset.php
+ -
+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$order_number\.$#'
+ identifier: property.notFound
+ count: 1
+ path: app/Models/Asset.php
+
-
message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$price\.$#'
identifier: property.notFound
@@ -6061,11 +6025,17 @@ parameters:
path: app/Models/Asset.php
-
- message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$supplier_id\.$#'
+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$purchase_date\.$#'
identifier: property.notFound
count: 1
path: app/Models/Asset.php
+ -
+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$supplier_id\.$#'
+ identifier: property.notFound
+ count: 2
+ path: app/Models/Asset.php
+
-
message: '#^Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\Relation\:\:associate\(\)\.$#'
identifier: method.notFound
@@ -6954,6 +6924,12 @@ parameters:
count: 6
path: app/Models/Component.php
+ -
+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$order_number\.$#'
+ identifier: property.notFound
+ count: 1
+ path: app/Models/Component.php
+
-
message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$price\.$#'
identifier: property.notFound
@@ -6961,11 +6937,17 @@ parameters:
path: app/Models/Component.php
-
- message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$supplier_id\.$#'
+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$purchase_date\.$#'
identifier: property.notFound
count: 1
path: app/Models/Component.php
+ -
+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$supplier_id\.$#'
+ identifier: property.notFound
+ count: 2
+ path: app/Models/Component.php
+
-
message: '#^Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\Relation\:\:withTrashed\(\)\.$#'
identifier: method.notFound
@@ -7164,6 +7146,12 @@ parameters:
count: 6
path: app/Models/Consumable.php
+ -
+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$order_number\.$#'
+ identifier: property.notFound
+ count: 1
+ path: app/Models/Consumable.php
+
-
message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$price\.$#'
identifier: property.notFound
@@ -7171,11 +7159,17 @@ parameters:
path: app/Models/Consumable.php
-
- message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$supplier_id\.$#'
+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$purchase_date\.$#'
identifier: property.notFound
count: 1
path: app/Models/Consumable.php
+ -
+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$supplier_id\.$#'
+ identifier: property.notFound
+ count: 2
+ path: app/Models/Consumable.php
+
-
message: '#^Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\Relation\:\:withTrashed\(\)\.$#'
identifier: method.notFound
@@ -8328,12 +8322,6 @@ parameters:
count: 1
path: app/Models/Maintenance.php
- -
- message: '#^Access to an undefined property App\\Models\\MaintenanceType\:\:\$presenter\.$#'
- identifier: property.notFound
- count: 1
- path: app/Models/MaintenanceType.php
-
-
message: '#^Call to function is_array\(\) with string will always evaluate to false\.$#'
identifier: function.impossibleType
@@ -10230,12 +10218,6 @@ parameters:
count: 1
path: app/Policies/LocationPolicy.php
- -
- message: '#^Access to an undefined property App\\Models\\Maintenance\:\:\$asset\.$#'
- identifier: property.notFound
- count: 6
- path: app/Policies/MaintenancePolicy.php
-
-
message: '#^Method App\\Policies\\MaintenanceTypePolicy\:\:columnName\(\) should return bool but returns string\.$#'
identifier: return.type
diff --git a/routes/web.php b/routes/web.php
index 1f08bf25a6..47337ef12d 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -100,16 +100,6 @@ Route::middleware(['web', 'auth', 'authorize:superuser'])->prefix('oauth')->grou
});
Route::group(['middleware' => 'auth'], function () {
- /*
- * Calendar (unified view across every HasCalendarEvents source).
- * Companion API endpoint lives at /api/v1/calendar/events.
- */
- Route::get('calendar', [App\Http\Controllers\CalendarEventsController::class, 'index'])
- ->name('calendar.index')
- ->breadcrumbs(fn (Tabuna\Breadcrumbs\Trail $trail) => $trail->parent('home')
- ->push(trans('general.calendar'), route('calendar.index'))
- );
-
/*
* Companies
*/