diff --git a/bin/MindeeCliDocuments.php b/bin/MindeeCliDocuments.php index 08550a2c..f0a12e4c 100644 --- a/bin/MindeeCliDocuments.php +++ b/bin/MindeeCliDocuments.php @@ -4,7 +4,6 @@ namespace Mindee\Cli; -use Mindee\V1\Product\BarcodeReader\BarcodeReaderV1; use Mindee\V1\Product\BusinessCard\BusinessCardV1; use Mindee\V1\Product\Cropper\CropperV1; use Mindee\V1\Product\DriverLicense\DriverLicenseV1; @@ -20,7 +19,6 @@ use Mindee\V1\Product\Passport\PassportV1; use Mindee\V1\Product\Receipt\ReceiptV5; use Mindee\V1\Product\Resume\ResumeV1; -use Mindee\V1\Product\Us\BankCheck\BankCheckV1; /** * Document specifications for CLI usage. @@ -40,12 +38,6 @@ public static function getSpecs(): array false, true ), - "barcode-reader" => new DocumentCommandConfig( - "Barcode Reader", - BarcodeReaderV1::class, - true, - false - ), "business-card" => new DocumentCommandConfig( "Business Card", BusinessCardV1::class, @@ -130,12 +122,6 @@ public static function getSpecs(): array false, true ), - "us-bank-check" => new DocumentCommandConfig( - "US Bank Check", - BankCheckV1::class, - true, - false - ), ]; } } diff --git a/docs/code_samples/bank_account_details_v1.txt b/docs/code_samples/bank_account_details_v1.txt deleted file mode 100644 index eaf56aa0..00000000 --- a/docs/code_samples/bank_account_details_v1.txt +++ /dev/null @@ -1,16 +0,0 @@ -parse(BankAccountDetailsV1::class, $inputSource); - -echo $apiResponse->document; \ No newline at end of file diff --git a/docs/code_samples/bank_check_v1.txt b/docs/code_samples/bank_check_v1.txt deleted file mode 100644 index 48c14547..00000000 --- a/docs/code_samples/bank_check_v1.txt +++ /dev/null @@ -1,16 +0,0 @@ -parse(BankCheckV1::class, $inputSource); - -echo $apiResponse->document; \ No newline at end of file diff --git a/docs/code_samples/barcode_reader_v1.txt b/docs/code_samples/barcode_reader_v1.txt deleted file mode 100644 index 2075e019..00000000 --- a/docs/code_samples/barcode_reader_v1.txt +++ /dev/null @@ -1,16 +0,0 @@ -parse(BarcodeReaderV1::class, $inputSource); - -echo $apiResponse->document; \ No newline at end of file diff --git a/docs/code_samples/idcard_fr_v1.txt b/docs/code_samples/idcard_fr_v1.txt deleted file mode 100644 index 574c3e21..00000000 --- a/docs/code_samples/idcard_fr_v1.txt +++ /dev/null @@ -1,16 +0,0 @@ -parse(IdCardV1::class, $inputSource); - -echo $apiResponse->document; \ No newline at end of file diff --git a/src/Image/ImageUtils.php b/src/Image/ImageUtils.php index 43fb6837..76d8dea1 100644 --- a/src/Image/ImageUtils.php +++ b/src/Image/ImageUtils.php @@ -76,7 +76,7 @@ public static function toMagickImage(mixed $image): Imagick * @param integer|null $height Height to comply with. * @throws ImagickException Throws if resizing fails. */ - public static function resizeImage(Imagick $image, ?int $width = null, int $height = null): void + public static function resizeImage(Imagick $image, ?int $width = null, ?int $height = null): void { $width ??= $image->getImageWidth(); $height ??= $image->getImageHeight(); diff --git a/src/V1/Product/BarcodeReader/BarcodeReaderV1.php b/src/V1/Product/BarcodeReader/BarcodeReaderV1.php deleted file mode 100644 index 15dc1256..00000000 --- a/src/V1/Product/BarcodeReader/BarcodeReaderV1.php +++ /dev/null @@ -1,42 +0,0 @@ -> $rawPrediction Raw prediction from the HTTP response. - */ - public function __construct(array $rawPrediction) - { - parent::__construct($rawPrediction); - $this->prediction = new BarcodeReaderV1Document($rawPrediction['prediction']); - $this->pages = []; - foreach ($rawPrediction['pages'] as $page) { - try { - $this->pages[] = new Page(BarcodeReaderV1Document::class, $page); - } catch (MindeeUnsetException) { - } - } - } -} diff --git a/src/V1/Product/BarcodeReader/BarcodeReaderV1Document.php b/src/V1/Product/BarcodeReader/BarcodeReaderV1Document.php deleted file mode 100644 index 22ce3d83..00000000 --- a/src/V1/Product/BarcodeReader/BarcodeReaderV1Document.php +++ /dev/null @@ -1,68 +0,0 @@ -> $rawPrediction Raw prediction from HTTP response. - * @param integer|null $pageId Page number for multi pages document. - * @throws MindeeUnsetException Throws if a field doesn't appear in the response. - */ - public function __construct(array $rawPrediction, ?int $pageId = null) - { - if (!isset($rawPrediction["codes_1d"])) { - throw new MindeeUnsetException(); - } - $this->codes1D = array_map( - static fn($prediction) => new StringField($prediction, $pageId), - $rawPrediction["codes_1d"] - ); - if (!isset($rawPrediction["codes_2d"])) { - throw new MindeeUnsetException(); - } - $this->codes2D = array_map( - static fn($prediction) => new StringField($prediction, $pageId), - $rawPrediction["codes_2d"] - ); - } - - /** - * @return string String representation. - */ - public function __toString(): string - { - $codes1D = implode( - "\n ", - $this->codes1D - ); - $codes2D = implode( - "\n ", - $this->codes2D - ); - - $outStr = ":Barcodes 1D: $codes1D -:Barcodes 2D: $codes2D -"; - return SummaryHelperV1::cleanOutString($outStr); - } -} diff --git a/src/V1/Product/Fr/BankAccountDetails/BankAccountDetailsV1.php b/src/V1/Product/Fr/BankAccountDetails/BankAccountDetailsV1.php deleted file mode 100644 index 291f4bfd..00000000 --- a/src/V1/Product/Fr/BankAccountDetails/BankAccountDetailsV1.php +++ /dev/null @@ -1,42 +0,0 @@ -> $rawPrediction Raw prediction from the HTTP response. - */ - public function __construct(array $rawPrediction) - { - parent::__construct($rawPrediction); - $this->prediction = new BankAccountDetailsV1Document($rawPrediction['prediction']); - $this->pages = []; - foreach ($rawPrediction['pages'] as $page) { - try { - $this->pages[] = new Page(BankAccountDetailsV1Document::class, $page); - } catch (MindeeUnsetException) { - } - } - } -} diff --git a/src/V1/Product/Fr/BankAccountDetails/BankAccountDetailsV1Document.php b/src/V1/Product/Fr/BankAccountDetails/BankAccountDetailsV1Document.php deleted file mode 100644 index dfc4666e..00000000 --- a/src/V1/Product/Fr/BankAccountDetails/BankAccountDetailsV1Document.php +++ /dev/null @@ -1,71 +0,0 @@ -> $rawPrediction Raw prediction from HTTP response. - * @param integer|null $pageId Page number for multi pages document. - * @throws MindeeUnsetException Throws if a field doesn't appear in the response. - */ - public function __construct(array $rawPrediction, ?int $pageId = null) - { - if (!isset($rawPrediction["account_holder_name"])) { - throw new MindeeUnsetException(); - } - $this->accountHolderName = new StringField( - $rawPrediction["account_holder_name"], - $pageId - ); - if (!isset($rawPrediction["iban"])) { - throw new MindeeUnsetException(); - } - $this->iban = new StringField( - $rawPrediction["iban"], - $pageId - ); - if (!isset($rawPrediction["swift"])) { - throw new MindeeUnsetException(); - } - $this->swift = new StringField( - $rawPrediction["swift"], - $pageId - ); - } - - /** - * @return string String representation. - */ - public function __toString(): string - { - - $outStr = ":IBAN: $this->iban -:Account Holder's Name: $this->accountHolderName -:SWIFT Code: $this->swift -"; - return SummaryHelperV1::cleanOutString($outStr); - } -} diff --git a/src/V1/Product/Fr/IdCard/IdCardV1.php b/src/V1/Product/Fr/IdCard/IdCardV1.php deleted file mode 100644 index c992ed76..00000000 --- a/src/V1/Product/Fr/IdCard/IdCardV1.php +++ /dev/null @@ -1,42 +0,0 @@ -> $rawPrediction Raw prediction from the HTTP response. - */ - public function __construct(array $rawPrediction) - { - parent::__construct($rawPrediction); - $this->prediction = new IdCardV1Document($rawPrediction['prediction']); - $this->pages = []; - foreach ($rawPrediction['pages'] as $page) { - try { - $this->pages[] = new Page(IdCardV1Page::class, $page); - } catch (MindeeUnsetException) { - } - } - } -} diff --git a/src/V1/Product/Fr/IdCard/IdCardV1Document.php b/src/V1/Product/Fr/IdCard/IdCardV1Document.php deleted file mode 100644 index d2a59608..00000000 --- a/src/V1/Product/Fr/IdCard/IdCardV1Document.php +++ /dev/null @@ -1,161 +0,0 @@ -> $rawPrediction Raw prediction from HTTP response. - * @param integer|null $pageId Page number for multi pages document. - * @throws MindeeUnsetException Throws if a field doesn't appear in the response. - */ - public function __construct(array $rawPrediction, ?int $pageId = null) - { - if (!isset($rawPrediction["authority"])) { - throw new MindeeUnsetException(); - } - $this->authority = new StringField( - $rawPrediction["authority"], - $pageId - ); - if (!isset($rawPrediction["birth_date"])) { - throw new MindeeUnsetException(); - } - $this->birthDate = new DateField( - $rawPrediction["birth_date"], - $pageId - ); - if (!isset($rawPrediction["birth_place"])) { - throw new MindeeUnsetException(); - } - $this->birthPlace = new StringField( - $rawPrediction["birth_place"], - $pageId - ); - if (!isset($rawPrediction["expiry_date"])) { - throw new MindeeUnsetException(); - } - $this->expiryDate = new DateField( - $rawPrediction["expiry_date"], - $pageId - ); - if (!isset($rawPrediction["gender"])) { - throw new MindeeUnsetException(); - } - $this->gender = new StringField( - $rawPrediction["gender"], - $pageId - ); - if (!isset($rawPrediction["given_names"])) { - throw new MindeeUnsetException(); - } - $this->givenNames = array_map( - static fn($prediction) => new StringField($prediction, $pageId), - $rawPrediction["given_names"] - ); - if (!isset($rawPrediction["id_number"])) { - throw new MindeeUnsetException(); - } - $this->idNumber = new StringField( - $rawPrediction["id_number"], - $pageId - ); - if (!isset($rawPrediction["mrz1"])) { - throw new MindeeUnsetException(); - } - $this->mrz1 = new StringField( - $rawPrediction["mrz1"], - $pageId - ); - if (!isset($rawPrediction["mrz2"])) { - throw new MindeeUnsetException(); - } - $this->mrz2 = new StringField( - $rawPrediction["mrz2"], - $pageId - ); - if (!isset($rawPrediction["surname"])) { - throw new MindeeUnsetException(); - } - $this->surname = new StringField( - $rawPrediction["surname"], - $pageId - ); - } - - /** - * @return string String representation. - */ - public function __toString(): string - { - $givenNames = implode( - "\n ", - $this->givenNames - ); - - $outStr = ":Identity Number: $this->idNumber -:Given Name(s): $givenNames -:Surname: $this->surname -:Date of Birth: $this->birthDate -:Place of Birth: $this->birthPlace -:Expiry Date: $this->expiryDate -:Issuing Authority: $this->authority -:Gender: $this->gender -:MRZ Line 1: $this->mrz1 -:MRZ Line 2: $this->mrz2 -"; - return SummaryHelperV1::cleanOutString($outStr); - } -} diff --git a/src/V1/Product/Fr/IdCard/IdCardV1Page.php b/src/V1/Product/Fr/IdCard/IdCardV1Page.php deleted file mode 100644 index 0b86f4f9..00000000 --- a/src/V1/Product/Fr/IdCard/IdCardV1Page.php +++ /dev/null @@ -1,43 +0,0 @@ -> $rawPrediction Raw prediction from HTTP response. - * @param integer|null $pageId Page number for multi pages document. - */ - public function __construct(array $rawPrediction, ?int $pageId = null) - { - parent::__construct($rawPrediction, $pageId); - $this->documentSide = new ClassificationField( - $rawPrediction["document_side"], - $pageId - ); - } - - /** - * @return string String representation. - */ - public function __toString(): string - { - - $outStr = ":Document Side: $this->documentSide -"; - $outStr .= parent::__toString(); - return SummaryHelperV1::cleanOutString($outStr); - } -} diff --git a/src/V1/Product/Us/BankCheck/BankCheckV1.php b/src/V1/Product/Us/BankCheck/BankCheckV1.php deleted file mode 100644 index 3bbdd107..00000000 --- a/src/V1/Product/Us/BankCheck/BankCheckV1.php +++ /dev/null @@ -1,42 +0,0 @@ -> $rawPrediction Raw prediction from the HTTP response. - */ - public function __construct(array $rawPrediction) - { - parent::__construct($rawPrediction); - $this->prediction = new BankCheckV1Document($rawPrediction['prediction']); - $this->pages = []; - foreach ($rawPrediction['pages'] as $page) { - try { - $this->pages[] = new Page(BankCheckV1Page::class, $page); - } catch (MindeeUnsetException) { - } - } - } -} diff --git a/src/V1/Product/Us/BankCheck/BankCheckV1Document.php b/src/V1/Product/Us/BankCheck/BankCheckV1Document.php deleted file mode 100644 index d8e73b8c..00000000 --- a/src/V1/Product/Us/BankCheck/BankCheckV1Document.php +++ /dev/null @@ -1,113 +0,0 @@ -> $rawPrediction Raw prediction from HTTP response. - * @param integer|null $pageId Page number for multi pages document. - * @throws MindeeUnsetException Throws if a field doesn't appear in the response. - */ - public function __construct(array $rawPrediction, ?int $pageId = null) - { - if (!isset($rawPrediction["account_number"])) { - throw new MindeeUnsetException(); - } - $this->accountNumber = new StringField( - $rawPrediction["account_number"], - $pageId - ); - if (!isset($rawPrediction["amount"])) { - throw new MindeeUnsetException(); - } - $this->amount = new AmountField( - $rawPrediction["amount"], - $pageId - ); - if (!isset($rawPrediction["check_number"])) { - throw new MindeeUnsetException(); - } - $this->checkNumber = new StringField( - $rawPrediction["check_number"], - $pageId - ); - if (!isset($rawPrediction["date"])) { - throw new MindeeUnsetException(); - } - $this->date = new DateField( - $rawPrediction["date"], - $pageId - ); - if (!isset($rawPrediction["payees"])) { - throw new MindeeUnsetException(); - } - $this->payees = array_map( - static fn($prediction) => new StringField($prediction, $pageId), - $rawPrediction["payees"] - ); - if (!isset($rawPrediction["routing_number"])) { - throw new MindeeUnsetException(); - } - $this->routingNumber = new StringField( - $rawPrediction["routing_number"], - $pageId - ); - } - - /** - * @return string String representation. - */ - public function __toString(): string - { - $payees = implode( - "\n ", - $this->payees - ); - - $outStr = ":Check Issue Date: $this->date -:Amount: $this->amount -:Payees: $payees -:Routing Number: $this->routingNumber -:Account Number: $this->accountNumber -:Check Number: $this->checkNumber -"; - return SummaryHelperV1::cleanOutString($outStr); - } -} diff --git a/src/V1/Product/Us/BankCheck/BankCheckV1Page.php b/src/V1/Product/Us/BankCheck/BankCheckV1Page.php deleted file mode 100644 index b70a8ac0..00000000 --- a/src/V1/Product/Us/BankCheck/BankCheckV1Page.php +++ /dev/null @@ -1,56 +0,0 @@ -> $rawPrediction Raw prediction from HTTP response. - * @param integer|null $pageId Page number for multi pages document. - */ - public function __construct(array $rawPrediction, ?int $pageId = null) - { - parent::__construct($rawPrediction, $pageId); - $this->checkPosition = new PositionField( - $rawPrediction["check_position"], - $pageId - ); - $this->signaturesPositions = array_map( - static fn($prediction) => new PositionField($prediction, $pageId), - $rawPrediction["signatures_positions"] - ); - } - - /** - * @return string String representation. - */ - public function __toString(): string - { - $signaturesPositions = implode( - "\n ", - $this->signaturesPositions - ); - - $outStr = ":Check Position: $this->checkPosition -:Signature Positions: $signaturesPositions -"; - $outStr .= parent::__toString(); - return SummaryHelperV1::cleanOutString($outStr); - } -} diff --git a/tests/V1/Image/ImageExtractorTest.php b/tests/V1/Image/ImageExtractorTest.php index d72f06a5..66dda447 100644 --- a/tests/V1/Image/ImageExtractorTest.php +++ b/tests/V1/Image/ImageExtractorTest.php @@ -8,7 +8,6 @@ use Mindee\Input\PathInput; use Mindee\V1\Client; use Mindee\V1\Image\ImageExtractor; -use Mindee\V1\Product\BarcodeReader\BarcodeReaderV1; use Mindee\V1\Product\MultiReceiptsDetector\MultiReceiptsDetectorV1; use PHPUnit\Framework\TestCase; use TestingUtilities; @@ -57,35 +56,6 @@ private function getMultiReceiptsDetectorPrediction($name) return $this->dummyClient->loadPrediction(MultiReceiptsDetectorV1::class, $localResponse); } - public function testGivenAnImageShouldExtractValueFields(): void - { - $image = new PathInput(TestingUtilities::getV1DataDir() . "/products/barcode_reader/default_sample.jpg"); - $response = $this->getBarcodeReaderPrediction("complete"); - $inference = $response->document->inference; - - $extractor = new ImageExtractor($image); - self::assertSame(1, $extractor->pageCount); - - foreach ($inference->pages as $page) { - $codes1D = $extractor->extractImagesFromPage($page->prediction->codes1D, $page->id, "barcodes_1D.jpg"); - foreach ($codes1D as $i => $extractedImage) { - self::assertNotNull($extractedImage->image); - $source = $extractedImage->asInputSource(); - self::assertSame( - sprintf("barcodes_1D.jpg_page0-%d.jpg", $i), - $source->fileName - ); - $extractedImage->writeToFile(TestingUtilities::getRootDataDir() . "/output"); - } - - $codes2D = $extractor->extractImagesFromPage($page->prediction->codes2D, $page->id, "barcodes_2D.jpg"); - foreach ($codes2D as $extractedImage) { - self::assertNotNull($extractedImage->image); - $extractedImage->writeToFile(TestingUtilities::getRootDataDir() . "/output"); - } - } - } - public function testGivenAPdfShouldExtractPositionFields(): void { $imageInput = new PathInput( @@ -114,12 +84,6 @@ public function testGivenAPdfShouldExtractPositionFields(): void } } - private function getBarcodeReaderPrediction($name) - { - $fileName = TestingUtilities::getV1DataDir() . "/products/barcode_reader/response_v1/{$name}.json"; - $localResponse = new LocalResponse($fileName); - return $this->dummyClient->loadPrediction(BarcodeReaderV1::class, $localResponse); - } protected function tearDown(): void { diff --git a/tests/V1/Product/BarcodeReader/BarcodeReaderV1Test.php b/tests/V1/Product/BarcodeReader/BarcodeReaderV1Test.php deleted file mode 100644 index bda66885..00000000 --- a/tests/V1/Product/BarcodeReader/BarcodeReaderV1Test.php +++ /dev/null @@ -1,41 +0,0 @@ -completeDoc = new Document(BarcodeReaderV1::class, $completeDocJSON["document"]); - $this->emptyDoc = new Document(BarcodeReaderV1::class, $emptyDocJSON["document"]); - $this->completeDocReference = file_get_contents($productDir . "summary_full.rst"); - } - - public function testCompleteDoc(): void - { - self::assertSame($this->completeDocReference, (string) ($this->completeDoc)); - } - - public function testEmptyDoc(): void - { - $prediction = $this->emptyDoc->inference->prediction; - self::assertCount(0, $prediction->codes1D); - self::assertCount(0, $prediction->codes2D); - } -} diff --git a/tests/V1/Product/Fr/BankAccountDetails/BankAccountDetailsV1Test.php b/tests/V1/Product/Fr/BankAccountDetails/BankAccountDetailsV1Test.php deleted file mode 100644 index 4233e042..00000000 --- a/tests/V1/Product/Fr/BankAccountDetails/BankAccountDetailsV1Test.php +++ /dev/null @@ -1,42 +0,0 @@ -completeDoc = new Document(BankAccountDetailsV1::class, $completeDocJSON["document"]); - $this->emptyDoc = new Document(BankAccountDetailsV1::class, $emptyDocJSON["document"]); - $this->completeDocReference = file_get_contents($productDir . "summary_full.rst"); - } - - public function testCompleteDoc(): void - { - self::assertSame($this->completeDocReference, (string) ($this->completeDoc)); - } - - public function testEmptyDoc(): void - { - $prediction = $this->emptyDoc->inference->prediction; - self::assertNull($prediction->iban->value); - self::assertNull($prediction->accountHolderName->value); - self::assertNull($prediction->swift->value); - } -} diff --git a/tests/V1/Product/Fr/IdCard/IdCardV1Test.php b/tests/V1/Product/Fr/IdCard/IdCardV1Test.php deleted file mode 100644 index 0db944aa..00000000 --- a/tests/V1/Product/Fr/IdCard/IdCardV1Test.php +++ /dev/null @@ -1,60 +0,0 @@ -completeDoc = new Document(IdCardV1::class, $completeDocJSON["document"]); - $this->emptyDoc = new Document(IdCardV1::class, $emptyDocJSON["document"]); - $this->completePage0 = new Page(IdCardV1Page::class, $completeDocJSON["document"]["inference"]["pages"][0]); - $this->completeDocReference = file_get_contents($productDir . "summary_full.rst"); - $this->completePage0Reference = file_get_contents($productDir . "summary_page0.rst"); - } - - public function testCompleteDoc(): void - { - self::assertSame($this->completeDocReference, (string) ($this->completeDoc)); - } - - public function testEmptyDoc(): void - { - $prediction = $this->emptyDoc->inference->prediction; - self::assertNull($prediction->idNumber->value); - self::assertCount(0, $prediction->givenNames); - self::assertNull($prediction->surname->value); - self::assertNull($prediction->birthDate->value); - self::assertNull($prediction->birthPlace->value); - self::assertNull($prediction->expiryDate->value); - self::assertNull($prediction->authority->value); - self::assertNull($prediction->gender->value); - self::assertNull($prediction->mrz1->value); - self::assertNull($prediction->mrz2->value); - } - public function testCompletePage0(): void - { - self::assertSame(0, $this->completePage0->id); - self::assertSame($this->completePage0Reference, (string) ($this->completePage0)); - } -} diff --git a/tests/V1/Product/Us/BankCheck/BankCheckV1Test.php b/tests/V1/Product/Us/BankCheck/BankCheckV1Test.php deleted file mode 100644 index 38e6d571..00000000 --- a/tests/V1/Product/Us/BankCheck/BankCheckV1Test.php +++ /dev/null @@ -1,56 +0,0 @@ -completeDoc = new Document(BankCheckV1::class, $completeDocJSON["document"]); - $this->emptyDoc = new Document(BankCheckV1::class, $emptyDocJSON["document"]); - $this->completePage0 = new Page(BankCheckV1Page::class, $completeDocJSON["document"]["inference"]["pages"][0]); - $this->completeDocReference = file_get_contents($productDir . "summary_full.rst"); - $this->completePage0Reference = file_get_contents($productDir . "summary_page0.rst"); - } - - public function testCompleteDoc(): void - { - self::assertSame($this->completeDocReference, (string) ($this->completeDoc)); - } - - public function testEmptyDoc(): void - { - $prediction = $this->emptyDoc->inference->prediction; - self::assertNull($prediction->date->value); - self::assertNull($prediction->amount->value); - self::assertCount(0, $prediction->payees); - self::assertNull($prediction->routingNumber->value); - self::assertNull($prediction->accountNumber->value); - self::assertNull($prediction->checkNumber->value); - } - public function testCompletePage0(): void - { - self::assertSame(0, $this->completePage0->id); - self::assertSame($this->completePage0Reference, (string) ($this->completePage0)); - } -}