diff --git a/app/Http/Controllers/BucketController.php b/app/Http/Controllers/BucketController.php index e5f9997..f2e2341 100644 --- a/app/Http/Controllers/BucketController.php +++ b/app/Http/Controllers/BucketController.php @@ -33,6 +33,7 @@ public function store(Request $request, Scenario $scenario): JsonResponse 'type' => 'required|in:'.implode(',', BucketTypeEnum::values()), 'allocation_type' => 'required|in:'.implode(',', BucketAllocationTypeEnum::values()), 'allocation_value' => 'nullable|numeric', + 'buffer_multiplier' => 'sometimes|nullable|numeric|min:0', 'priority' => 'nullable|integer|min:1', ]); @@ -52,7 +53,8 @@ public function store(Request $request, Scenario $scenario): JsonResponse $allocationType, $type, $validated['allocation_value'] ?? null, - $validated['priority'] ?? null + $validated['priority'] ?? null, + isset($validated['buffer_multiplier']) ? (float) $validated['buffer_multiplier'] : null, ); return response()->json([ @@ -74,6 +76,7 @@ public function update(Request $request, Bucket $bucket): JsonResponse 'type' => 'required|in:'.implode(',', BucketTypeEnum::values()), 'allocation_type' => 'required|in:'.implode(',', BucketAllocationTypeEnum::values()), 'allocation_value' => 'nullable|numeric', + 'buffer_multiplier' => 'sometimes|nullable|numeric|min:0', 'priority' => 'nullable|integer|min:1', ]); @@ -105,6 +108,11 @@ public function update(Request $request, Bucket $bucket): JsonResponse $validated['allocation_value'] = null; } + // Buffer only applies to fixed_limit buckets — always reset on type change + if ($allocationType !== BucketAllocationTypeEnum::FIXED_LIMIT) { + $validated['buffer_multiplier'] = 0.0; + } + // Handle priority change if needed if (isset($validated['priority']) && $validated['priority'] !== $bucket->priority) { $this->updateBucketPriority($bucket, $validated['priority']); @@ -221,7 +229,8 @@ private function formatBucketResponse(Bucket $bucket): array 'allocation_type' => $bucket->allocation_type, 'allocation_value' => $bucket->allocation_value, 'allocation_type_label' => $bucket->getAllocationTypeLabel(), - 'formatted_allocation_value' => $bucket->getFormattedAllocationValue(), + 'buffer_multiplier' => (float) $bucket->buffer_multiplier, + 'effective_capacity' => $bucket->getEffectiveCapacity(), 'current_balance' => $bucket->getCurrentBalance(), 'has_available_space' => $bucket->hasAvailableSpace(), 'available_space' => $bucket->getAvailableSpace(), diff --git a/app/Http/Resources/BucketResource.php b/app/Http/Resources/BucketResource.php index 841d94f..ed08d94 100644 --- a/app/Http/Resources/BucketResource.php +++ b/app/Http/Resources/BucketResource.php @@ -19,7 +19,8 @@ public function toArray(Request $request): array 'allocation_type' => $this->allocation_type, 'allocation_value' => $this->allocation_value, 'allocation_type_label' => $this->getAllocationTypeLabel(), - 'formatted_allocation_value' => $this->getFormattedAllocationValue(), + 'buffer_multiplier' => (float) $this->buffer_multiplier, + 'effective_capacity' => $this->getEffectiveCapacity(), 'current_balance' => $this->getCurrentBalance(), 'has_available_space' => $this->hasAvailableSpace(), 'available_space' => $this->getAvailableSpace(), diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 38c065e..02f0b34 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -175,7 +175,13 @@ parameters: path: app/Http/Resources/BucketResource.php - - message: '#^Call to an undefined method App\\Http\\Resources\\BucketResource\:\:getFormattedAllocationValue\(\)\.$#' + message: '#^Access to an undefined property App\\Http\\Resources\\BucketResource\:\:\$buffer_multiplier\.$#' + identifier: property.notFound + count: 1 + path: app/Http/Resources/BucketResource.php + + - + message: '#^Call to an undefined method App\\Http\\Resources\\BucketResource\:\:getEffectiveCapacity\(\)\.$#' identifier: method.notFound count: 1 path: app/Http/Resources/BucketResource.php