1515
1616use CodeIgniter \CLI \AbstractCommand ;
1717use CodeIgniter \CLI \Attributes \Command ;
18- use CodeIgniter \CLI \CLI ;
1918use CodeIgniter \CLI \Input \Option ;
19+ use CodeIgniter \CLI \Output ;
20+ use CodeIgniter \CLI \Table ;
2021use CodeIgniter \CLI \Verbosity ;
2122use CodeIgniter \Helpers \Array \ArrayHelper ;
2223use Config \App ;
@@ -67,14 +68,15 @@ protected function execute(array $arguments, array $options): int
6768 assert (is_string ($ dir ));
6869
6970 $ currentLocale = Locale ::getDefault ();
71+ $ output = $ this ->getOutput ();
7072
7173 ['currentDir ' => $ currentDir , 'languagePath ' => $ this ->languagePath ] = $ this ->resolvePaths ();
7274
7375 if ($ locale !== '' ) {
7476 $ supportedLocales = config (App::class)->supportedLocales ;
7577
7678 if (! in_array ($ locale , $ supportedLocales , true )) {
77- CLI :: error (
79+ $ output -> error (
7880 sprintf (
7981 'Error: "%s" is not supported. Supported locales: %s ' ,
8082 $ locale ,
@@ -94,23 +96,23 @@ protected function execute(array $arguments, array $options): int
9496 $ tempCurrentDir = realpath ($ currentDir . $ dir );
9597
9698 if ($ tempCurrentDir === false ) {
97- CLI :: error (sprintf ('Error: Directory must be located in "%s" ' , $ currentDir ), 'light_gray ' , 'red ' );
99+ $ output -> error (sprintf ('Error: Directory must be located in "%s" ' , $ currentDir ), 'light_gray ' , 'red ' );
98100
99101 return EXIT_USER_INPUT ;
100102 }
101103
102104 if ($ this ->isSubdirectory ($ tempCurrentDir , $ this ->languagePath )) {
103- CLI :: error (sprintf ('Error: Directory "%s" restricted to scan. ' , $ this ->languagePath ), 'light_gray ' , 'red ' );
105+ $ output -> error (sprintf ('Error: Directory "%s" restricted to scan. ' , $ this ->languagePath ), 'light_gray ' , 'red ' );
104106
105107 return EXIT_USER_INPUT ;
106108 }
107109
108110 $ currentDir = $ tempCurrentDir ;
109111 }
110112
111- $ this ->process ($ currentDir , $ currentLocale );
113+ $ this ->process ($ output , $ currentDir , $ currentLocale );
112114
113- CLI :: write ('All operations done! ' , 'green ' );
115+ $ output -> write ('All operations done! ' , 'green ' );
114116
115117 return EXIT_SUCCESS ;
116118 }
@@ -136,10 +138,9 @@ private function resolvePaths(): array
136138 ];
137139 }
138140
139- private function process (string $ currentDir , string $ currentLocale ): void
141+ private function process (Output $ output , string $ currentDir , string $ currentLocale ): void
140142 {
141143 $ showNew = $ this ->getValidatedOption ('show-new ' ) === true ;
142- $ output = $ this ->getOutput ();
143144
144145 $ tableRows = [];
145146 $ countNewKeys = 0 ;
@@ -152,7 +153,7 @@ private function process(string $currentDir, string $currentLocale): void
152153 'foundLanguageKeys ' => $ foundLanguageKeys ,
153154 'badLanguageKeys ' => $ badLanguageKeys ,
154155 'countFiles ' => $ countFiles ,
155- ] = $ this ->findLanguageKeysInFiles ($ files );
156+ ] = $ this ->findLanguageKeysInFiles ($ output , $ files );
156157
157158 ksort ($ foundLanguageKeys );
158159
@@ -189,11 +190,11 @@ private function process(string $currentDir, string $currentLocale): void
189190
190191 if ($ showNew && $ tableRows !== []) {
191192 sort ($ tableRows );
192- CLI :: table ( $ tableRows , ['File ' , 'Key ' ]);
193+ $ output -> write (( new Table ( $ tableRows , ['File ' , 'Key ' ]))-> render () );
193194 }
194195
195196 if (! $ showNew && $ countNewKeys > 0 ) {
196- CLI :: write ('Note: You need to run your linting tool to fix coding standards issues. ' , 'white ' , 'red ' );
197+ $ output -> write ('Note: You need to run your linting tool to fix coding standards issues. ' , 'white ' , 'red ' );
197198 }
198199
199200 $ output ->write (sprintf ('Files found: %d ' , $ countFiles ), verbosity: Verbosity::Verbose);
@@ -209,7 +210,7 @@ private function process(string $currentDir, string $currentLocale): void
209210
210211 ArrayHelper ::sortValuesByNatural ($ tableBadRows , 0 );
211212
212- CLI :: table ( $ tableBadRows , ['Bad Key ' , 'Filepath ' ]);
213+ $ output -> write (( new Table ( $ tableBadRows , ['Bad Key ' , 'Filepath ' ]))-> render () );
213214 }
214215 }
215216
@@ -423,12 +424,11 @@ private function isSubdirectory(string $directory, string $rootDirectory): bool
423424 *
424425 * @return array{'foundLanguageKeys': array<string, array<string, string>>, 'badLanguageKeys': array<int, array<int, string>>, 'countFiles': int}
425426 */
426- private function findLanguageKeysInFiles (array $ files ): array
427+ private function findLanguageKeysInFiles (Output $ output , array $ files ): array
427428 {
428429 $ foundLanguageKeys = [];
429430 $ badLanguageKeys = [];
430431 $ countFiles = 0 ;
431- $ output = $ this ->getOutput ();
432432
433433 foreach ($ files as $ file ) {
434434 if ($ this ->isIgnoredFile ($ file )) {
0 commit comments