@@ -191,20 +191,15 @@ public static function getStatistics(): array
191191 // Sort pools by capacity for better readability
192192 ksort ($ poolsByCapacity );
193193
194- // Sort pool_sizes by extracting numeric capacity for consistent ordering
195- uksort (
196- $ poolSizes ,
197- function ($ a , $ b ) {
198- // Extract numeric capacity from formatted strings like "1.0KB (1024 bytes)"
199- preg_match ('/\((\d+) bytes\)/ ' , $ a , $ matchesA );
200- preg_match ('/\((\d+) bytes\)/ ' , $ b , $ matchesB );
201-
202- $ capacityA = isset ($ matchesA [1 ]) ? (int )$ matchesA [1 ] : 0 ;
203- $ capacityB = isset ($ matchesB [1 ]) ? (int )$ matchesB [1 ] : 0 ;
204-
205- return $ capacityA <=> $ capacityB ;
194+ // Sort pool_sizes based on numeric capacities from poolsByCapacity
195+ $ sortedPoolSizes = [];
196+ foreach (array_keys ($ poolsByCapacity ) as $ capacity ) {
197+ $ readableKey = $ poolsByCapacity [$ capacity ]['capacity_formatted ' ];
198+ if (isset ($ poolSizes [$ readableKey ])) {
199+ $ sortedPoolSizes [$ readableKey ] = $ poolSizes [$ readableKey ];
206200 }
207- );
201+ }
202+ $ poolSizes = $ sortedPoolSizes ;
208203
209204 return [
210205 'reuse_rate ' => round ($ reuseRate , 2 ),
@@ -281,11 +276,12 @@ private static function validateConfiguration(array $config): void
281276 {
282277 // Validate 'max_pool_size'
283278 if (isset ($ config ['max_pool_size ' ])) {
279+ // First check type
284280 if (!is_int ($ config ['max_pool_size ' ])) {
285- throw new \InvalidArgumentException (
286- "'max_pool_size' must be an integer, got: " . gettype ($ config ['max_pool_size ' ])
287- );
281+ throw new \InvalidArgumentException ("'max_pool_size' must be an integer " );
288282 }
283+
284+ // Then check range
289285 if ($ config ['max_pool_size ' ] <= 0 ) {
290286 throw new \InvalidArgumentException ("'max_pool_size' must be a positive integer " );
291287 }
@@ -298,11 +294,12 @@ private static function validateConfiguration(array $config): void
298294
299295 // Validate 'default_capacity'
300296 if (isset ($ config ['default_capacity ' ])) {
297+ // First check type
301298 if (!is_int ($ config ['default_capacity ' ])) {
302- throw new \InvalidArgumentException (
303- "'default_capacity' must be an integer, got: " . gettype ($ config ['default_capacity ' ])
304- );
299+ throw new \InvalidArgumentException ("'default_capacity' must be an integer " );
305300 }
301+
302+ // Then check range
306303 if ($ config ['default_capacity ' ] <= 0 ) {
307304 throw new \InvalidArgumentException ("'default_capacity' must be a positive integer " );
308305 }
@@ -315,10 +312,9 @@ private static function validateConfiguration(array $config): void
315312
316313 // Validate 'size_categories'
317314 if (isset ($ config ['size_categories ' ])) {
315+ // First check type
318316 if (!is_array ($ config ['size_categories ' ])) {
319- throw new \InvalidArgumentException (
320- "'size_categories' must be an array, got: " . gettype ($ config ['size_categories ' ])
321- );
317+ throw new \InvalidArgumentException ("'size_categories' must be an array " );
322318 }
323319
324320 if (empty ($ config ['size_categories ' ])) {
@@ -330,11 +326,14 @@ private static function validateConfiguration(array $config): void
330326 throw new \InvalidArgumentException ("Size category names must be non-empty strings " );
331327 }
332328
329+ // First check type for each capacity
333330 if (!is_int ($ capacity )) {
334331 throw new \InvalidArgumentException (
335- "Size category ' {$ name }' must have an integer capacity, got: " . gettype ( $ capacity )
332+ "Size category ' {$ name }' must have an integer capacity "
336333 );
337334 }
335+
336+ // Then check range
338337 if ($ capacity <= 0 ) {
339338 throw new \InvalidArgumentException (
340339 "Size category ' {$ name }' must have a positive integer capacity "
0 commit comments