Skip to content

Commit 1ea81b9

Browse files
♻️ cleanup lingering issues (#190)
1 parent 6740788 commit 1ea81b9

87 files changed

Lines changed: 282 additions & 341 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bin/DocumentCommandConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Mindee\CLI;
5+
namespace Mindee\Cli;
66

77
/**
88
* Document configuration class for CLI usage.

bin/MindeeCLICommand.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
declare(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;
89
use Mindee\Input\InputSource;
910
use Mindee\Input\PageOptions;
1011
use Mindee\Input\PathInput;
@@ -19,7 +20,6 @@
1920
use Symfony\Component\Console\Input\InputInterface;
2021
use Symfony\Component\Console\Input\InputOption;
2122
use Symfony\Component\Console\Output\OutputInterface;
22-
use Exception;
2323

2424
use function count;
2525
use 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 {

bin/MindeeCLIDocuments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Mindee\CLI;
5+
namespace Mindee\Cli;
66

77
use Mindee\V1\Product\BarcodeReader\BarcodeReaderV1;
88
use Mindee\V1\Product\BillOfLading\BillOfLadingV1;

bin/cli.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Mindee\CLI;
5+
namespace Mindee\Cli;
66

77
require __DIR__ . '/../vendor/autoload.php';
88
require __DIR__ . '/MindeeCLIDocuments.php';

docs/code_samples/bank_account_details_v1.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
22

33
use Mindee\V1\Client;
4+
use Mindee\Input\PathInput;
45
use Mindee\V1\Product\Fr\BankAccountDetails\BankAccountDetailsV1;
56

67
// Init a new client
78
$mindeeClient = new Client("my-api-key");
89

910
// Load a file from disk
10-
$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");
11+
$inputSource = new PathInput("/path/to/the/file.ext");
1112

1213
// Parse the file
1314
$apiResponse = $mindeeClient->parse(BankAccountDetailsV1::class, $inputSource);

docs/code_samples/bank_account_details_v2.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
22

33
use Mindee\V1\Client;
4+
use Mindee\Input\PathInput;
45
use Mindee\V1\Product\Fr\BankAccountDetails\BankAccountDetailsV2;
56

67
// Init a new client
78
$mindeeClient = new Client("my-api-key");
89

910
// Load a file from disk
10-
$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");
11+
$inputSource = new PathInput("/path/to/the/file.ext");
1112

1213
// Parse the file
1314
$apiResponse = $mindeeClient->parse(BankAccountDetailsV2::class, $inputSource);

docs/code_samples/bank_check_v1.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
22

33
use Mindee\V1\Client;
4+
use Mindee\Input\PathInput;
45
use Mindee\V1\Product\Us\BankCheck\BankCheckV1;
56

67
// Init a new client
78
$mindeeClient = new Client("my-api-key");
89

910
// Load a file from disk
10-
$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");
11+
$inputSource = new PathInput("/path/to/the/file.ext");
1112

1213
// Parse the file
1314
$apiResponse = $mindeeClient->parse(BankCheckV1::class, $inputSource);

docs/code_samples/barcode_reader_v1.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
22

33
use Mindee\V1\Client;
4+
use Mindee\Input\PathInput;
45
use Mindee\V1\Product\BarcodeReader\BarcodeReaderV1;
56

67
// Init a new client
78
$mindeeClient = new Client("my-api-key");
89

910
// Load a file from disk
10-
$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");
11+
$inputSource = new PathInput("/path/to/the/file.ext");
1112

1213
// Parse the file
1314
$apiResponse = $mindeeClient->parse(BarcodeReaderV1::class, $inputSource);

docs/code_samples/bill_of_lading_v1_async.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
22

33
use Mindee\V1\Client;
4+
use Mindee\Input\PathInput;
45
use Mindee\V1\Product\BillOfLading\BillOfLadingV1;
56

67
// Init a new client
78
$mindeeClient = new Client("my-api-key");
89

910
// Load a file from disk
10-
$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");
11+
$inputSource = new PathInput("/path/to/the/file.ext");
1112

1213
// Parse the file asynchronously
1314
$apiResponse = $mindeeClient->enqueueAndParse(BillOfLadingV1::class, $inputSource);

docs/code_samples/business_card_v1_async.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
22

33
use Mindee\V1\Client;
4+
use Mindee\Input\PathInput;
45
use Mindee\V1\Product\BusinessCard\BusinessCardV1;
56

67
// Init a new client
78
$mindeeClient = new Client("my-api-key");
89

910
// Load a file from disk
10-
$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");
11+
$inputSource = new PathInput("/path/to/the/file.ext");
1112

1213
// Parse the file asynchronously
1314
$apiResponse = $mindeeClient->enqueueAndParse(BusinessCardV1::class, $inputSource);

0 commit comments

Comments
 (0)