@@ -65,7 +65,7 @@ public function run( array $input ): array|\WP_Error {
6565 }
6666
6767 $ ability = ( $ this ->ability_resolver )('datamachine-code/workspace-worktree-bounded-cleanup-eligible-apply ' );
68- if ( ! $ ability || ! is_callable (array ( $ ability , 'execute ' )) ) {
68+ if ( ! is_object ( $ ability) || ! is_callable (array ( $ ability , 'execute ' )) ) {
6969 return new \WP_Error ('cleanup_eligible_drain_ability_missing ' , 'Bounded cleanup-eligible apply ability is not available. ' , array ( 'status ' => 500 ));
7070 }
7171
@@ -130,18 +130,18 @@ public function run( array $input ): array|\WP_Error {
130130 $ continuation = (array ) ( $ pass_result ['continuation ' ] ?? array () );
131131 $ evidence = (array ) ( $ pass_result ['evidence ' ] ?? array () );
132132 $ pass_summary = array (
133- 'pass ' => $ pass ,
134- 'dry_run ' => ! empty ($ pass_result ['dry_run ' ]),
135- 'processed ' => (int ) ( $ summary ['processed ' ] ?? 0 ),
136- 'would_remove ' => ! empty ($ pass_result ['dry_run ' ]) ? count ( (array ) ( $ pass_result ['candidates ' ] ?? array () ) ) : 0 ,
137- 'removed ' => (int ) ( $ summary ['removed ' ] ?? 0 ),
138- 'skipped ' => (int ) ( $ summary ['skipped ' ] ?? 0 ),
139- 'bytes_reclaimed ' => (int ) ( $ summary ['bytes_reclaimed ' ] ?? 0 ),
140- 'remaining_total ' => (int ) ( $ continuation ['remaining_total ' ] ?? 0 ),
141- 'elapsed_ms ' => (int ) ( $ evidence ['elapsed_ms ' ] ?? 0 ),
142- 'removed_handles ' => array_values (array_filter (array_map (fn ( $ row ) => is_array ($ row ) ? (string ) ( $ row ['handle ' ] ?? '' ) : '' , (array ) ( $ pass_result ['removed ' ] ?? array () )))),
143- 'candidate_handles ' => array_values (array_filter (array_map (fn ( $ row ) => is_array ($ row ) ? (string ) ( $ row ['handle ' ] ?? '' ) : '' , (array ) ( $ pass_result ['candidates ' ] ?? array () )))),
144- 'skipped_by_reason ' => $ this ->summarize_skipped ((array ) ( $ pass_result ['skipped ' ] ?? array () )),
133+ 'pass ' => $ pass ,
134+ 'dry_run ' => ! empty ($ pass_result ['dry_run ' ]),
135+ 'processed ' => (int ) ( $ summary ['processed ' ] ?? 0 ),
136+ 'would_remove ' => ! empty ($ pass_result ['dry_run ' ]) ? count ( (array ) ( $ pass_result ['candidates ' ] ?? array () ) ) : 0 ,
137+ 'removed ' => (int ) ( $ summary ['removed ' ] ?? 0 ),
138+ 'skipped ' => (int ) ( $ summary ['skipped ' ] ?? 0 ),
139+ 'bytes_reclaimed ' => (int ) ( $ summary ['bytes_reclaimed ' ] ?? 0 ),
140+ 'remaining_total ' => (int ) ( $ continuation ['remaining_total ' ] ?? 0 ),
141+ 'elapsed_ms ' => (int ) ( $ evidence ['elapsed_ms ' ] ?? 0 ),
142+ 'removed_handles ' => array_values (array_filter (array_map (fn ( $ row ) => is_array ($ row ) ? (string ) ( $ row ['handle ' ] ?? '' ) : '' , (array ) ( $ pass_result ['removed ' ] ?? array () )))),
143+ 'candidate_handles ' => array_values (array_filter (array_map (fn ( $ row ) => is_array ($ row ) ? (string ) ( $ row ['handle ' ] ?? '' ) : '' , (array ) ( $ pass_result ['candidates ' ] ?? array () )))),
144+ 'skipped_by_reason ' => $ this ->summarize_skipped ( (array ) ( $ pass_result ['skipped ' ] ?? array () ) ),
145145 );
146146
147147 $ result ['pass_results ' ][] = $ pass_summary ;
@@ -213,7 +213,7 @@ private function budget_expired( ?float $deadline ): bool {
213213 private function summarize_skipped ( array $ rows ): array {
214214 $ summary = array ();
215215 foreach ( $ rows as $ row ) {
216- $ reason = is_array ( $ row ) ? (string ) ( $ row ['reason_code ' ] ?? 'unknown ' ) : ' unknown ' ;
216+ $ reason = (string ) ( $ row ['reason_code ' ] ?? 'unknown ' );
217217 $ summary [ $ reason ] = (int ) ( $ summary [ $ reason ] ?? 0 ) + 1 ;
218218 }
219219 return $ summary ;
@@ -235,16 +235,17 @@ private function build_disk_report( string $workspace_path ): array {
235235 return array (
236236 'path ' => $ workspace_path ,
237237 'free_bytes ' => false === $ free ? null : (int ) $ free ,
238- 'free_human ' => false === $ free ? 'unknown ' : $ this ->format_bytes ((int ) $ free ),
238+ 'free_human ' => false === $ free ? 'unknown ' : $ this ->format_bytes ( (int ) $ free ),
239239 'total_bytes ' => false === $ total ? null : (int ) $ total ,
240240 );
241241 }
242242
243243 private function format_bytes ( int $ bytes ): string {
244- $ units = array ( 'B ' , 'KiB ' , 'MiB ' , 'GiB ' , 'TiB ' );
245- $ value = (float ) max (0 , $ bytes );
246- $ unit = 0 ;
247- while ( $ value >= 1024 && $ unit < count ($ units ) - 1 ) {
244+ $ units = array ( 'B ' , 'KiB ' , 'MiB ' , 'GiB ' , 'TiB ' );
245+ $ value = (float ) max (0 , $ bytes );
246+ $ unit = 0 ;
247+ $ unit_count = count ($ units );
248+ while ( $ value >= 1024 && $ unit < $ unit_count - 1 ) {
248249 $ value /= 1024 ;
249250 ++$ unit ;
250251 }
0 commit comments