1515
1616use CodeIgniter \Autoloader \FileLocator ;
1717use CodeIgniter \Autoloader \FileLocatorCached ;
18- use CodeIgniter \CLI \BaseCommand ;
18+ use CodeIgniter \CLI \AbstractCommand ;
19+ use CodeIgniter \CLI \Attributes \Command ;
1920use CodeIgniter \CLI \CLI ;
2021use CodeIgniter \Exceptions \RuntimeException ;
2122use CodeIgniter \Publisher \Publisher ;
2223
2324/**
2425 * Optimize for production.
2526 */
26- final class Optimize extends BaseCommand
27+ #[Command(name: 'optimize ' , description: 'Optimize for production. ' , group: 'CodeIgniter ' )]
28+ final class Optimize extends AbstractCommand
2729{
28- /**
29- * The group the command is lumped under
30- * when listing commands.
31- *
32- * @var string
33- */
34- protected $ group = 'CodeIgniter ' ;
35-
36- /**
37- * The Command's name
38- *
39- * @var string
40- */
41- protected $ name = 'optimize ' ;
42-
43- /**
44- * The Command's short description
45- *
46- * @var string
47- */
48- protected $ description = 'Optimize for production. ' ;
49-
50- /**
51- * The Command's usage
52- *
53- * @var string
54- */
55- protected $ usage = 'optimize ' ;
56-
57- /**
58- * @return int
59- */
60- public function run (array $ params )
30+ protected function execute (array $ arguments , array $ options ): int
6131 {
6232 try {
6333 $ this ->enableCaching ();
@@ -78,25 +48,24 @@ private function clearCache(): void
7848 $ locator ->deleteCache ();
7949 CLI ::write ('Removed FileLocatorCache. ' , 'green ' );
8050
81- $ cache = WRITEPATH . 'cache/FactoriesCache_config ' ;
82- $ this ->removeFile ($ cache );
51+ $ this ->removeFile (WRITEPATH . 'cache/FactoriesCache_config ' );
8352 }
8453
85- private function removeFile (string $ cache ): void
54+ private function removeFile (string $ file ): void
8655 {
87- if (is_file ($ cache )) {
88- $ result = unlink ($ cache );
56+ if (! is_file ($ file )) {
57+ return ;
58+ }
8959
90- if ($ result ) {
91- CLI ::write ('Removed " ' . clean_path ($ cache ) . ' ". ' , 'green ' );
60+ if (unlink ( $ file ) ) {
61+ CLI ::write (sprintf ( 'Removed "%s". ' , clean_path ($ file )) , 'green ' );
9262
93- return ;
94- }
63+ return ;
64+ }
9565
96- CLI ::error ('Error in removing file: ' . clean_path ($ cache ));
66+ CLI ::error (sprintf ( 'Error in removing file: %s ' , clean_path ($ file ) ));
9767
98- throw new RuntimeException (__METHOD__ );
99- }
68+ throw new RuntimeException (__METHOD__ );
10069 }
10170
10271 private function enableCaching (): void
@@ -122,7 +91,7 @@ private function enableCaching(): void
12291 return ;
12392 }
12493
125- CLI ::error ('Error in updating file: ' . clean_path ($ config ));
94+ CLI ::error (sprintf ( 'Error in updating file: %s ' , clean_path ($ config) ));
12695
12796 throw new RuntimeException (__METHOD__ );
12897 }
0 commit comments