22
33declare (strict_types=1 );
44
5- namespace Mindee \CLI ;
5+ namespace Mindee \Cli ;
66
7- use Mindee \Error \MindeeHttpException ;
7+ use Exception ;
8+ use Mindee \Error \V1 \MindeeV1HttpException ;
89use Mindee \Input \InputSource ;
910use Mindee \Input \PageOptions ;
1011use Mindee \Input \PathInput ;
1920use Symfony \Component \Console \Input \InputInterface ;
2021use Symfony \Component \Console \Input \InputOption ;
2122use Symfony \Component \Console \Output \OutputInterface ;
22- use Exception ;
2323
2424use function count ;
2525use function in_array ;
@@ -253,7 +253,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
253253 }
254254
255255 $ filePathOrUrl = $ input ->getArgument ('file_path_or_url ' );
256- $ file = $ this ->getFileSource ($ filePathOrUrl , $ client , $ output );
256+ $ file = $ this ->getFileSource ($ filePathOrUrl , $ output );
257257 if (!$ file ) {
258258 return Command::FAILURE ;
259259 }
@@ -347,7 +347,7 @@ private function areMutuallyExclusivePagesOptions(InputInterface $input, OutputI
347347 $ pagesRemove = $ input ->getOption ('pages_remove ' );
348348 $ pagesKeep = $ input ->getOption ('pages_keep ' );
349349 if ($ pagesKeep && $ pagesRemove ) {
350- $ output ->writeln ("<error>Page cut & page keep operations are mutually exclusive.</error> " );
350+ $ output ->writeln ("<error>Page cut and page keep operations are mutually exclusive.</error> " );
351351 return true ;
352352 }
353353 return false ;
@@ -357,21 +357,20 @@ private function areMutuallyExclusivePagesOptions(InputInterface $input, OutputI
357357 * Retrieves a source file from a URL or a path.
358358 *
359359 * @param string $filePathOrUrl Path of the file, or URL if it's remote.
360- * @param Client $client Mindee Client.
361360 * @param OutputInterface $output Output interface of the CLI.
362361 * @return PathInput|UrlInputSource|null A valid InputSource.
363362 */
364- private function getFileSource (string $ filePathOrUrl , Client $ client , OutputInterface $ output )
363+ private function getFileSource (string $ filePathOrUrl , OutputInterface $ output ): PathInput | UrlInputSource | null
365364 {
366- if (substr ($ filePathOrUrl , 0 , 8 ) !== 'https:// ' ) {
365+ if (! str_starts_with ($ filePathOrUrl , 'https:// ' ) ) {
367366 if (@file_exists ($ filePathOrUrl ) || @file_get_contents ($ filePathOrUrl )) {
368- return $ client -> sourceFromPath ($ filePathOrUrl );
367+ return new PathInput ($ filePathOrUrl );
369368 } else {
370369 $ output ->writeln ("<error>Invalid path or url provided ' $ filePathOrUrl'.</error> " );
371370 return null ;
372371 }
373372 }
374- return $ client -> sourceFromUrl ($ filePathOrUrl );
373+ return new UrlInputSource ($ filePathOrUrl );
375374 }
376375
377376 /**
@@ -493,7 +492,7 @@ private function executePrediction(
493492 $ debug = $ input ->getOption ('debug ' );
494493 try {
495494 $ result = $ this ->runClientPrediction ($ client , $ product , $ file , $ predictMethodOptions , $ isAsync , $ debug );
496- } catch (MindeeHttpException $ e ) {
495+ } catch (MindeeV1HttpException $ e ) {
497496 $ output ->writeln ($ e ->getMessage ());
498497 return Command::FAILURE ;
499498 } catch (Exception $ e ) {
@@ -524,7 +523,7 @@ private function runClientPrediction(
524523 PredictMethodOptions $ predictMethodOptions ,
525524 bool $ isAsync ,
526525 bool $ debug
527- ) {
526+ ): AsyncPredictResponse | PredictResponse | string {
528527 if ($ debug ) {
529528 return "Command executed successfully. " ;
530529 }
@@ -544,7 +543,7 @@ private function runClientPrediction(
544543 * @return integer Command execution code return.
545544 */
546545 private function outputResult (
547- $ result ,
546+ PredictResponse | AsyncPredictResponse | string $ result ,
548547 ?string $ outputType ,
549548 OutputInterface $ output
550549 ): int {
0 commit comments