@@ -278,7 +278,7 @@ protected function buildPath(string $class): string
278278 $ basePath = $ this ->getBasePath ($ namespace );
279279
280280 if ($ basePath === null ) {
281- CLI :: error (lang ('CLI.namespaceNotDefined ' , [$ namespace ]));
281+ $ this -> getOutput ()-> error (lang ('CLI.namespaceNotDefined ' , [$ namespace ]));
282282
283283 return '' ;
284284 }
@@ -323,8 +323,10 @@ protected function getNamespace(): string
323323 */
324324 private function generate (string $ class ): int
325325 {
326+ $ output = $ this ->getOutput ();
327+
326328 if (preg_match (self ::CLASS_NAME_PATTERN , $ class ) !== 1 ) {
327- CLI :: error (lang ('CLI.generator.invalidClassName ' , [$ class ]));
329+ $ output -> error (lang ('CLI.generator.invalidClassName ' , [$ class ]));
328330
329331 return EXIT_ERROR ;
330332 }
@@ -335,23 +337,23 @@ private function generate(string $class): int
335337 return EXIT_ERROR ;
336338 }
337339
338- return $ this ->generateFile ($ target , $ this ->buildContent ($ class ));
340+ return $ this ->generateFile ($ output , $ target , $ this ->buildContent ($ class ));
339341 }
340342
341343 /**
342344 * Writes the generated file to disk with all the safety checks around that.
343345 */
344- private function generateFile (string $ target , string $ content ): int
346+ private function generateFile (Output $ output , string $ target , string $ content ): int
345347 {
346- if (str_starts_with ($ target , SYSTEMPATH ) && ! $ this ->confirmCodeIgniterNamespaceOnce ()) {
348+ if (str_starts_with ($ target , SYSTEMPATH ) && ! $ this ->confirmCodeIgniterNamespaceOnce ($ output )) {
347349 return EXIT_SUCCESS ;
348350 }
349351
350352 $ isFile = is_file ($ target );
351353 $ force = $ this ->hasOption ('force ' ) && $ this ->getValidatedOption ('force ' ) === true ;
352354
353355 if (! $ force && $ isFile ) {
354- CLI :: error (lang ('CLI.generator.fileExist ' , [clean_path ($ target )]));
356+ $ output -> error (lang ('CLI.generator.fileExist ' , [clean_path ($ target )]));
355357
356358 return EXIT_ERROR ;
357359 }
@@ -366,31 +368,31 @@ private function generateFile(string $target, string $content): int
366368
367369 if (! write_file ($ target , $ content )) {
368370 // @codeCoverageIgnoreStart
369- CLI :: error (lang ('CLI.generator.fileError ' , [clean_path ($ target )]));
371+ $ output -> error (lang ('CLI.generator.fileError ' , [clean_path ($ target )]));
370372
371373 return EXIT_ERROR ;
372374 // @codeCoverageIgnoreEnd
373375 }
374376
375377 if ($ isFile ) {
376- CLI :: write (lang ('CLI.generator.fileOverwrite ' , [clean_path ($ target )]), 'yellow ' );
378+ $ output -> write (lang ('CLI.generator.fileOverwrite ' , [clean_path ($ target )]), 'yellow ' );
377379 } else {
378- CLI :: write (lang ('CLI.generator.fileCreate ' , [clean_path ($ target )]), 'green ' );
380+ $ output -> write (lang ('CLI.generator.fileCreate ' , [clean_path ($ target )]), 'green ' );
379381 }
380382
381383 return EXIT_SUCCESS ;
382384 }
383385
384- private function confirmCodeIgniterNamespaceOnce (): bool
386+ private function confirmCodeIgniterNamespaceOnce (Output $ output ): bool
385387 {
386388 if ($ this ->confirmedCodeIgniterNamespace !== null ) {
387389 return $ this ->confirmedCodeIgniterNamespace ;
388390 }
389391
390- CLI :: write (lang ('CLI.generator.usingCINamespace ' ), 'yellow ' );
392+ $ output -> write (lang ('CLI.generator.usingCINamespace ' ), 'yellow ' );
391393
392394 if ($ this ->isInteractive () && $ this ->getPrompt ()->ask (lang ('CLI.generator.confirmContinue ' ), ['y ' , 'n ' ], 'required ' ) === 'n ' ) {
393- CLI :: write (lang ('CLI.generator.cancelOperation ' ), 'yellow ' );
395+ $ output -> write (lang ('CLI.generator.cancelOperation ' ), 'yellow ' );
394396
395397 return $ this ->confirmedCodeIgniterNamespace = false ;
396398 }
0 commit comments