11<?php
22
3+ declare (strict_types=1 );
4+
35namespace Mindee \CLI ;
46
57use Mindee \Error \MindeeHttpException ;
1719use Symfony \Component \Console \Input \InputInterface ;
1820use Symfony \Component \Console \Input \InputOption ;
1921use Symfony \Component \Console \Output \OutputInterface ;
22+ use Exception ;
23+
24+ use function count ;
25+ use function in_array ;
26+
2027use const Mindee \Input \KEEP_ONLY ;
2128use const Mindee \Input \REMOVE ;
2229use const Mindee \VERSION ;
@@ -54,7 +61,6 @@ public function __construct(array $documentList)
5461
5562 /**
5663 * @param string|null $product Selected product, for customisation of the help section.
57- * @return string
5864 */
5965 protected function formatHelp (string $ product = null ): string
6066 {
@@ -83,7 +89,7 @@ protected function formatHelp(string $product = null): string
8389 /**
8490 * @return void sets the main CLI properties.
8591 */
86- protected function configure ()
92+ protected function configure (): void
8793 {
8894 $ this
8995 ->setName ('mindee ' )
@@ -106,7 +112,7 @@ protected function configure()
106112 /**
107113 * @return void Sets main properties regarding polling/parsing.
108114 */
109- private function configureMainOptions ()
115+ private function configureMainOptions (): void
110116 {
111117 $ this ->addOption (
112118 'async ' ,
@@ -171,7 +177,7 @@ private function configureMainOptions()
171177 /**
172178 * @return void Sets custom options.
173179 */
174- private function configureCustomOptions ()
180+ private function configureCustomOptions (): void
175181 {
176182 $ this
177183 ->addOption (
@@ -197,11 +203,10 @@ private function configureCustomOptions()
197203 /**
198204 * Initializes the CLI runner, writes the help section if no argument nor option is given.
199205 *
200- * @param InputInterface $input Input interface given to the CLI.
206+ * @param InputInterface $input Input interface given to the CLI.
201207 * @param OutputInterface $output Output interface.
202- * @return void
203208 */
204- protected function initialize (InputInterface $ input , OutputInterface $ output )
209+ protected function initialize (InputInterface $ input , OutputInterface $ output ): void
205210 {
206211 $ args = $ input ->getArguments ();
207212 $ opts = $ input ->getOptions ();
@@ -215,7 +220,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
215220 /**
216221 * Runs a command (overload).
217222 *
218- * @param InputInterface $input Input interface given to the CLI.
223+ * @param InputInterface $input Input interface given to the CLI.
219224 * @param OutputInterface $output Output interface.
220225 * @return integer Command execution code return.
221226 */
@@ -276,7 +281,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
276281 /**
277282 * Checks whether the version was requested.
278283 *
279- * @param InputInterface $input Input interface of the CLI.
284+ * @param InputInterface $input Input interface of the CLI.
280285 * @param OutputInterface $output Output interface of the CLI.
281286 * @return boolean True if options are valid.
282287 */
@@ -292,16 +297,16 @@ private function handleVersionOption(InputInterface $input, OutputInterface $out
292297 /**
293298 * Checks whether a given product is valid for CLI use.
294299 *
295- * @param string $product Product class used.
296- * @param OutputInterface $output Output interface of the CLI.
300+ * @param string $product Product class used.
301+ * @param OutputInterface $output Output interface of the CLI.
297302 * @return boolean True if a product is valid.
298303 */
299304 private function isValidProduct (string $ product , OutputInterface $ output ): bool
300305 {
301- if (!in_array ($ product , $ this ->acceptableDocuments )) {
306+ if (!in_array ($ product , $ this ->acceptableDocuments , true )) {
302307 $ output ->writeln ("<error>Invalid product: $ product</error> " );
303- $ output ->writeln ('<error>Available products are: ' .
304- implode (', ' , $ this ->acceptableDocuments ) . '</error> ' );
308+ $ output ->writeln ('<error>Available products are: '
309+ . implode (', ' , $ this ->acceptableDocuments ) . '</error> ' );
305310 return false ;
306311 }
307312 return true ;
@@ -310,9 +315,9 @@ private function isValidProduct(string $product, OutputInterface $output): bool
310315 /**
311316 * Checks whether a polling method is valid for the current poll.
312317 *
313- * @param string $product Product class used.
314- * @param boolean $isAsync Whether the polling will be asynchronous.
315- * @param OutputInterface $output Output interface of the CLI.
318+ * @param string $product Product class used.
319+ * @param boolean $isAsync Whether the polling will be asynchronous.
320+ * @param OutputInterface $output Output interface of the CLI.
316321 * @return boolean True if the polling method exists for a given product.
317322 */
318323 private function isValidPollingMethod (string $ product , bool $ isAsync , OutputInterface $ output ): bool
@@ -333,7 +338,7 @@ private function isValidPollingMethod(string $product, bool $isAsync, OutputInte
333338 /**
334339 * Checks whether PageOptions for the current polling are possible.
335340 *
336- * @param InputInterface $input Input interface of the CLI.
341+ * @param InputInterface $input Input interface of the CLI.
337342 * @param OutputInterface $output Output interface of the CLI.
338343 * @return boolean True if the operations are possible.
339344 */
@@ -351,9 +356,9 @@ private function areMutuallyExclusivePagesOptions(InputInterface $input, OutputI
351356 /**
352357 * Retrieves a source file from a URL or a path.
353358 *
354- * @param string $filePathOrUrl Path of the file, or URL if it's remote.
355- * @param Client $client Mindee Client.
356- * @param OutputInterface $output Output interface of the CLI.
359+ * @param string $filePathOrUrl Path of the file, or URL if it's remote.
360+ * @param Client $client Mindee Client.
361+ * @param OutputInterface $output Output interface of the CLI.
357362 * @return PathInput|URLInputSource|null A valid InputSource.
358363 */
359364 private function getFileSource (string $ filePathOrUrl , Client $ client , OutputInterface $ output )
@@ -410,7 +415,7 @@ private function getPredictOptions(InputInterface $input): PredictOptions
410415 * Generates a valid PredictMethodOptions object for parsing.
411416 *
412417 * @param PredictOptions $predictOptions Valid PredictOptions.
413- * @param PageOptions $pageOptions Valid PageOptions.
418+ * @param PageOptions $pageOptions Valid PageOptions.
414419 * @return PredictMethodOptions Valid PredictMethod Options.
415420 */
416421 private function getPredictMethodOptions (
@@ -426,11 +431,11 @@ private function getPredictMethodOptions(
426431 /**
427432 * Handles options specific to Custom & Generated Products.
428433 *
429- * @param InputInterface $input Input interface of the CLI.
430- * @param OutputInterface $output Output interface of the CLI.
431- * @param Client $client Mindee Client.
434+ * @param InputInterface $input Input interface of the CLI.
435+ * @param OutputInterface $output Output interface of the CLI.
436+ * @param Client $client Mindee Client.
432437 * @param PredictMethodOptions $predictMethodOptions Valid PredictMethodOptions.
433- * @param string $product Product class used.
438+ * @param string $product Product class used.
434439 * @return boolean Whether the setting of options for custom/generated are valid.
435440 */
436441 private function handleCustomOrGeneratedProduct (
@@ -440,7 +445,7 @@ private function handleCustomOrGeneratedProduct(
440445 PredictMethodOptions $ predictMethodOptions ,
441446 string $ product
442447 ): bool {
443- if ($ product == "generated " ) {
448+ if ($ product === "generated " ) {
444449 $ accountName = $ input ->getOption ('account_name ' );
445450 $ endpointName = $ input ->getOption ('endpoint_name ' );
446451 $ endpointVersion = $ input ->getOption ('endpoint_version ' ) ?? '1 ' ;
@@ -465,14 +470,14 @@ private function handleCustomOrGeneratedProduct(
465470 }
466471
467472 /**
468- * @param Client $client Mindee Client.
469- * @param string $product Product class used.
470- * @param InputSource $file Input File.
473+ * @param Client $client Mindee Client.
474+ * @param string $product Product class used.
475+ * @param InputSource $file Input File.
471476 * @param PredictMethodOptions $predictMethodOptions Options for the polling.
472- * @param boolean $isAsync Whether the polling will be asynchronous.
473- * @param InputInterface $input Input interface of the CLI.
474- * @param OutputInterface $output Output interface of the CLI.
475- * @param string|null $outputType Type of output (raw, parsed or summary).
477+ * @param boolean $isAsync Whether the polling will be asynchronous.
478+ * @param InputInterface $input Input interface of the CLI.
479+ * @param OutputInterface $output Output interface of the CLI.
480+ * @param string|null $outputType Type of output (raw, parsed or summary).
476481 * @return integer Return code for the CLI
477482 */
478483 private function executePrediction (
@@ -491,7 +496,7 @@ private function executePrediction(
491496 } catch (MindeeHttpException $ e ) {
492497 $ output ->writeln ($ e ->getMessage ());
493498 return Command::FAILURE ;
494- } catch (\ Exception $ e ) {
499+ } catch (Exception $ e ) {
495500 $ output ->writeln ("Something went wrong, ' " . $ e ->getMessage () . "' was raised. " );
496501 return Command::FAILURE ;
497502 }
@@ -502,15 +507,15 @@ private function executePrediction(
502507 /**
503508 * Runs the prediction call.
504509 *
505- * @param Client $client Mindee client.
506- * @param string $product Product class used.
507- * @param InputSource $file Input File.
510+ * @param Client $client Mindee client.
511+ * @param string $product Product class used.
512+ * @param InputSource $file Input File.
508513 * @param PredictMethodOptions $predictMethodOptions Prediction method options.
509- * @param boolean $isAsync Whether the polling is asynchronous.
510- * @param boolean $debug Whether the command is running in debug mode.
514+ * @param boolean $isAsync Whether the polling is asynchronous.
515+ * @param boolean $debug Whether the command is running in debug mode.
511516 *
512517 * @return AsyncPredictResponse|PredictResponse|string Either a valid prediction response, or a message if the
513- * command is in debug mode.
518+ * command is in debug mode.
514519 */
515520 private function runClientPrediction (
516521 Client $ client ,
@@ -532,10 +537,10 @@ private function runClientPrediction(
532537 }
533538
534539 /**
535- * @param PredictResponse|AsyncPredictResponse|string $result Result of the parsing (or message if in debug
536- * mode).
537- * @param string|null $outputType Type of output (raw, parsed or summary).
538- * @param OutputInterface $output Output interface for the CLI.
540+ * @param PredictResponse|AsyncPredictResponse|string $result Result of the parsing (or message if in debug
541+ * mode).
542+ * @param string|null $outputType Type of output (raw, parsed or summary).
543+ * @param OutputInterface $output Output interface for the CLI.
539544 * @return integer Command execution code return.
540545 */
541546 private function outputResult (
0 commit comments