diff --git a/.github/workflows/_static-analysis.yml b/.github/workflows/_static-analysis.yml index 510b2452..aaadd839 100644 --- a/.github/workflows/_static-analysis.yml +++ b/.github/workflows/_static-analysis.yml @@ -38,3 +38,7 @@ jobs: - name: Run PHPStan run: | composer phpstan + + - name: Run Rector + run: | + composer rector:check diff --git a/bin/MindeeCLICommand.php b/bin/MindeeCLICommand.php index c7c3744f..23c358ad 100644 --- a/bin/MindeeCLICommand.php +++ b/bin/MindeeCLICommand.php @@ -8,7 +8,7 @@ use Mindee\Input\InputSource; use Mindee\Input\PageOptions; use Mindee\Input\PathInput; -use Mindee\Input\URLInputSource; +use Mindee\Input\UrlInputSource; use Mindee\V1\Client; use Mindee\V1\ClientOptions\PredictMethodOptions; use Mindee\V1\ClientOptions\PredictOptions; @@ -359,7 +359,7 @@ private function areMutuallyExclusivePagesOptions(InputInterface $input, OutputI * @param string $filePathOrUrl Path of the file, or URL if it's remote. * @param Client $client Mindee Client. * @param OutputInterface $output Output interface of the CLI. - * @return PathInput|URLInputSource|null A valid InputSource. + * @return PathInput|UrlInputSource|null A valid InputSource. */ private function getFileSource(string $filePathOrUrl, Client $client, OutputInterface $output) { diff --git a/composer.json b/composer.json index 96a7daaf..f18cb53b 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,9 @@ "friendsofphp/php-cs-fixer": "^3.38", "phpunit/phpunit": "^9.6", "madewithlove/license-checker": "^v1.0", - "phpstan/phpstan": "^2.1" + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-deprecation-rules": "^2.0", + "rector/rector": "^2.4" }, "suggest": { "ext-imagick": "Required for PDF rasterization and image processing features", @@ -35,6 +37,8 @@ "scripts": { "lint": "php-cs-fixer fix --dry-run --diff", "phpstan": "phpstan analyse src --level 6", - "format": "php-cs-fixer fix" + "format": "php-cs-fixer fix", + "rector": "rector process src tests", + "rector:check": "rector process src tests --dry-run" } } diff --git a/docs/code_samples/v2_extraction_webhook.txt b/docs/code_samples/v2_extraction_webhook.txt index 63fe599e..28293a6b 100644 --- a/docs/code_samples/v2_extraction_webhook.txt +++ b/docs/code_samples/v2_extraction_webhook.txt @@ -16,7 +16,7 @@ $mindeeClient = new Client($apiKey); $inferenceParams = new ExtractionParameters( // ID of the model, required. $modelId, - webhooksIds: ["MY_WEBHOOK_ID"], + webhookIds: ["MY_WEBHOOK_ID"], // Options: set to `true` or `false` to override defaults diff --git a/docs/code_samples/v2_ocr.txt b/docs/code_samples/v2_ocr.txt index 3921f550..5beba83d 100644 --- a/docs/code_samples/v2_ocr.txt +++ b/docs/code_samples/v2_ocr.txt @@ -1,8 +1,8 @@ withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withPhpSets() + ->withTypeCoverageLevel(0) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0); diff --git a/src/Dependency/DependencyChecker.php b/src/Dependency/DependencyChecker.php index cde460a1..87cc8e12 100644 --- a/src/Dependency/DependencyChecker.php +++ b/src/Dependency/DependencyChecker.php @@ -48,7 +48,7 @@ public static function isGhostscriptAvailable(): void } else { $commandWasExecuted = (bool) shell_exec('which gs'); } - } catch (Exception $e) { + } catch (Exception) { throw new MindeeUnhandledException( "To enable full support of PDF features, you need " . "to enable Ghostscript on your PHP installation.", @@ -96,7 +96,7 @@ public static function isImageMagickPolicyAllowed(): void /** @phpstan-ignore-next-line */ TestingUtilities::getV1DataDir() . "/products/expense_receipts/default_sample.jpg" ); - } catch (Exception $e) { + } catch (Exception) { throw new MindeeUnhandledException( "To enable full support of PDF features, you need " . "to enable ImageMagick on your PHP installation. Also, you " diff --git a/src/Error/MindeeHttpException.php b/src/Error/MindeeHttpException.php index f83692d3..98384c81 100644 --- a/src/Error/MindeeHttpException.php +++ b/src/Error/MindeeHttpException.php @@ -20,10 +20,6 @@ */ class MindeeHttpException extends MindeeException { - /** - * @var integer Status code as sent by the server. - */ - public int $statusCode; /** * @var string|null API code as sent by the server. */ @@ -40,11 +36,10 @@ class MindeeHttpException extends MindeeException /** * @param array> $httpError Array containing the error data. * @param string $url Remote URL the error was found on. - * @param integer $code Error code. + * @param integer $statusCode Error code. */ - public function __construct(array $httpError, string $url, int $code) + public function __construct(array $httpError, string $url, public int $statusCode) { - $this->statusCode = $code; if (array_key_exists('code', $httpError)) { $this->apiCode = $httpError['code']; } else { diff --git a/src/Error/MindeePDFException.php b/src/Error/MindeePdfException.php similarity index 77% rename from src/Error/MindeePDFException.php rename to src/Error/MindeePdfException.php index 45b145ec..589b2844 100644 --- a/src/Error/MindeePDFException.php +++ b/src/Error/MindeePdfException.php @@ -12,4 +12,4 @@ /** * Exceptions relating to the handling of PDF documents. */ -class MindeePDFException extends MindeeException {} +class MindeePdfException extends MindeeException {} diff --git a/src/Extraction/ExtractedImage.php b/src/Extraction/ExtractedImage.php index d7a694e6..5ba66a81 100644 --- a/src/Extraction/ExtractedImage.php +++ b/src/Extraction/ExtractedImage.php @@ -19,51 +19,21 @@ */ class ExtractedImage { - /** - * @var Imagick Wrapper for the image. - */ - public Imagick $image; - - /** - * @var string Name of the file. - */ - public string $filename; - - /** - * @var integer Page ID of the image. - */ - public int $pageId; - - /** - * @var integer Element ID of the image. - */ - public int $elementId; - - /** - * @var string String representation of the save format. - */ - protected string $saveFormat; - /** * Initializes a new instance of the ExtractedImage class. * * @param Imagick $image The extracted image. * @param string $filename The filename for the image. * @param string $saveFormat The format to save the image. - * @param integer $pageIndex The page index of the image. - * @param integer $index The element index of the image. + * @param integer $pageId The page index of the image. + * @param integer $elementId The element index of the image. * * @throws MindeeUnhandledException Throws if PDF operations aren't supported. */ - public function __construct(Imagick $image, string $filename, string $saveFormat, int $pageIndex, int $index) + public function __construct(public Imagick $image, public string $filename, protected string $saveFormat, public int $pageId, public int $elementId) { DependencyChecker::isImageMagickAvailable(); DependencyChecker::isGhostscriptAvailable(); - $this->image = $image; - $this->filename = $filename; - $this->saveFormat = $saveFormat; - $this->pageId = $pageIndex; - $this->elementId = $index; } /** diff --git a/src/Extraction/ExtractedPDF.php b/src/Extraction/ExtractedPdf.php similarity index 82% rename from src/Extraction/ExtractedPDF.php rename to src/Extraction/ExtractedPdf.php index d2874e85..ba738442 100644 --- a/src/Extraction/ExtractedPDF.php +++ b/src/Extraction/ExtractedPdf.php @@ -6,7 +6,7 @@ use Mindee\Dependency\DependencyChecker; use Mindee\Error\ErrorCode; -use Mindee\Error\MindeePDFException; +use Mindee\Error\MindeePdfException; use Mindee\Error\MindeeUnhandledException; use Mindee\Input\BytesInput; use setasign\Fpdi\Fpdi; @@ -17,18 +17,8 @@ /** * An extracted sub-Pdf. */ -class ExtractedPDF +class ExtractedPdf { - /** - * @var string name of the original file - */ - public string $filename; - - /** - * @var string File object for an ExtractedPdf. - */ - protected string $pdfBytes; - /** * Initializes a new instance of the ExtractedPdf class. * @@ -37,12 +27,10 @@ class ExtractedPDF * * @throws MindeeUnhandledException Throws if PDF operations aren't supported. */ - public function __construct(string $pdfBytes, string $filename) + public function __construct(protected string $pdfBytes, public string $filename) { DependencyChecker::isImageMagickAvailable(); DependencyChecker::isGhostscriptAvailable(); - $this->pdfBytes = $pdfBytes; - $this->filename = $filename; } /** @@ -50,7 +38,7 @@ public function __construct(string $pdfBytes, string $filename) * * @return integer the number of pages in the file * - * @throws MindeePDFException Throws if FPDI is unable to process the file. + * @throws MindeePdfException Throws if FPDI is unable to process the file. */ public function getPageCount(): int { @@ -62,7 +50,7 @@ public function getPageCount(): int return $pdfHandle->setSourceFile($tempFilename); } catch (PdfParserException $e) { - throw new MindeePDFException( + throw new MindeePdfException( "Couldn't open PDF file.", ErrorCode::PDF_CANT_CREATE, $e @@ -102,7 +90,7 @@ public function asInputSource(): BytesInput /** * @return string the pdf bytes */ - public function getPDFBytes(): string + public function getPdfBytes(): string { return $this->pdfBytes; } diff --git a/src/Extraction/ImageExtractor.php b/src/Extraction/ImageExtractor.php index 80512d48..764922e4 100644 --- a/src/Extraction/ImageExtractor.php +++ b/src/Extraction/ImageExtractor.php @@ -9,7 +9,7 @@ use Mindee\Error\ErrorCode; use Mindee\Error\MindeeGeometryException; use Mindee\Error\MindeeImageException; -use Mindee\Error\MindeePDFException; +use Mindee\Error\MindeePdfException; use Mindee\Geometry\BBox; use Mindee\Geometry\BBoxUtils; use Mindee\Geometry\Point; @@ -51,7 +51,7 @@ class ImageExtractor * @param LocalInputSource $localInput Local input, accepts all compatible formats. * @param null|string $saveFormat Save format, will be coerced to jpg by default. * - * @throws MindeePDFException Throws if PDF operations aren't supported, or if the file can't be read, respectively. + * @throws MindeePdfException Throws if PDF operations aren't supported, or if the file can't be read, respectively. */ public function __construct(LocalInputSource $localInput, ?string $saveFormat = null) { @@ -71,14 +71,14 @@ public function __construct(LocalInputSource $localInput, ?string $saveFormat = $this->saveFormat = $saveFormat; } - if ($this->inputSource->isPDF()) { - $this->pageImages = $this->pdfToImages($this->inputSource->readContents()[1]); + if ($this->inputSource->isPdf()) { + $this->pageImages = static::pdfToImages($this->inputSource->readContents()[1]); } else { try { $image = new Imagick(); $image->readImageBlob($this->inputSource->readContents()[1]); } catch (ImagickException $e) { - throw new MindeePDFException( + throw new MindeePdfException( "Image couldn't be processed.", ErrorCode::IMAGE_CANT_PROCESS, $e diff --git a/src/Extraction/PDFExtractor.php b/src/Extraction/PdfExtractor.php similarity index 89% rename from src/Extraction/PDFExtractor.php rename to src/Extraction/PdfExtractor.php index bffe885c..25bf10cb 100644 --- a/src/Extraction/PDFExtractor.php +++ b/src/Extraction/PdfExtractor.php @@ -5,7 +5,7 @@ namespace Mindee\Extraction; use Mindee\Dependency\DependencyChecker; -use Mindee\Error\MindeePDFException; +use Mindee\Error\MindeePdfException; use Mindee\Input\LocalInputSource; use Mindee\V1\Product\InvoiceSplitter\InvoiceSplitterV1InvoicePageGroups; use setasign\Fpdi\Fpdi; @@ -24,7 +24,7 @@ /** * PDF extraction class. */ -class PDFExtractor +class PdfExtractor { /** * @var string bytes representation of a file @@ -34,12 +34,12 @@ class PDFExtractor /** * @var string name of the file */ - private string $fileName; + private readonly string $fileName; /** * @param LocalInputSource $localInput Local Input, accepts all compatible formats. * - * @throws MindeePDFException Throws if PDF operations aren't supported, or if the file + * @throws MindeePdfException Throws if PDF operations aren't supported, or if the file * can't be read, respectively. */ public function __construct(LocalInputSource $localInput) @@ -48,13 +48,13 @@ public function __construct(LocalInputSource $localInput) DependencyChecker::isGhostscriptAvailable(); $this->fileName = $localInput->fileName; - if ($localInput->isPDF()) { + if ($localInput->isPdf()) { $this->pdfBytes = $localInput->readContents()[1]; } else { try { $image = new Imagick(); } catch (ImagickException $e) { - throw new MindeePDFException("Imagick could not process this file.\n", 0, $e); + throw new MindeePdfException("Imagick could not process this file.\n", 0, $e); } $image->readImageBlob($localInput->readContents()[1]); $image->setImageFormat('pdf'); @@ -67,7 +67,7 @@ public function __construct(LocalInputSource $localInput) * * @return integer The number of pages in the file. * - * @throws MindeePDFException Throws if FPDI is unable to process the file. + * @throws MindeePdfException Throws if FPDI is unable to process the file. */ public function getPageCount(): int { @@ -79,7 +79,7 @@ public function getPageCount(): int return $pdfHandle->setSourceFile($tempFilename); } catch (PdfParserException $e) { - throw new MindeePDFException("Couldn't open PDF file. FPDI sent the following: ", 0, $e); + throw new MindeePdfException("Couldn't open PDF file. FPDI sent the following: ", 0, $e); } } @@ -88,9 +88,9 @@ public function getPageCount(): int * * @param array>|InvoiceSplitterV1InvoicePageGroups $pageIndexes List of sub-lists of pages to keep. * - * @return ExtractedPDF[] list of extracted documents + * @return ExtractedPdf[] list of extracted documents * - * @throws MindeePDFException Throws if FDPF/FPDI wasn't able to handle the pdf during the extraction. + * @throws MindeePdfException Throws if FDPF/FPDI wasn't able to handle the pdf during the extraction. * @throws InvalidArgumentException Throws if invalid indexes are provided. */ public function extractSubDocuments(array|InvoiceSplitterV1InvoicePageGroups $pageIndexes): array @@ -130,9 +130,9 @@ public function extractSubDocuments(array|InvoiceSplitterV1InvoicePageGroups $pa PdfParserException| PdfReaderException $e ) { - throw new MindeePDFException("PDF file couldn't be processed during extraction.", 0, $e); + throw new MindeePdfException("PDF file couldn't be processed during extraction.", 0, $e); } - $extractedPdfs[] = new ExtractedPDF($mergedPdfBytes, $fieldFilename); + $extractedPdfs[] = new ExtractedPdf($mergedPdfBytes, $fieldFilename); } return $extractedPdfs; @@ -144,7 +144,7 @@ public function extractSubDocuments(array|InvoiceSplitterV1InvoicePageGroups $pa * @param array>|InvoiceSplitterV1InvoicePageGroups $pageIndexes List of sub-lists of pages to keep. * @param boolean $strict Whether to trust confidence scores or not. * - * @return ExtractedPDF[] a list of extracted invoices + * @return ExtractedPdf[] a list of extracted invoices */ public function extractInvoices(array|InvoiceSplitterV1InvoicePageGroups $pageIndexes, bool $strict = false): array { diff --git a/src/Geometry/BBox.php b/src/Geometry/BBox.php index dd0c6d32..5a930b7e 100644 --- a/src/Geometry/BBox.php +++ b/src/Geometry/BBox.php @@ -9,40 +9,13 @@ */ class BBox { - /** - * @var float Minimum X coordinate. - */ - private float $minX; - /** - * @var float Maximum X coordinate. - */ - private float $maxX; - /** - * @var float Minimum Y coordinate. - */ - private float $minY; - /** - * @var float Maximum Y coordinate. - */ - private float $maxY; - /** * @param float $minX Input minimum X coordinate. * @param float $maxX Input maximum X coordinate. * @param float $minY Input minimum Y coordinate. * @param float $maxY Input maximum Y coordinate. */ - public function __construct( - float $minX, - float $maxX, - float $minY, - float $maxY - ) { - $this->minX = $minX; - $this->maxX = $maxX; - $this->minY = $minY; - $this->maxY = $maxY; - } + public function __construct(private float $minX, private float $maxX, private float $minY, private float $maxY) {} /** * Retrieves the minimum x coordinate. diff --git a/src/Geometry/MinMax.php b/src/Geometry/MinMax.php index 3e04e6ae..84787df3 100644 --- a/src/Geometry/MinMax.php +++ b/src/Geometry/MinMax.php @@ -9,24 +9,11 @@ */ class MinMax { - /** - * @var float Minimum. - */ - private float $min; - /** - * @var float Maximum. - */ - private float $max; - /** * @param float $min Input minimum. * @param float $max Input maximum. */ - public function __construct(float $min, float $max) - { - $this->min = $min; - $this->max = $max; - } + public function __construct(private readonly float $min, private readonly float $max) {} /** * @return float Retrieves the minimum. diff --git a/src/Geometry/Point.php b/src/Geometry/Point.php index 57906202..f94ad890 100644 --- a/src/Geometry/Point.php +++ b/src/Geometry/Point.php @@ -15,24 +15,11 @@ */ class Point implements ArrayAccess { - /** - * @var float X coordinate. - */ - private float $x; - /** - * @var float Y coordinate. - */ - private float $y; - /** * @param float $x Input x coordinate. * @param float $y Input y coordinate. */ - public function __construct(float $x, float $y) - { - $this->x = $x; - $this->y = $y; - } + public function __construct(private float $x, private float $y) {} /** * Retrieves the x coordinate. diff --git a/src/Geometry/Polygon.php b/src/Geometry/Polygon.php index 75aad681..7db2bd3d 100644 --- a/src/Geometry/Polygon.php +++ b/src/Geometry/Polygon.php @@ -4,12 +4,14 @@ namespace Mindee\Geometry; +use Stringable; + use function count; /** * Polygon represented as a set of coordinates (vertices/points). */ -class Polygon +class Polygon implements Stringable { /** * @var array|null Vertices of the polygon. diff --git a/src/Input/LocalInputSource.php b/src/Input/LocalInputSource.php index 968a29b4..9963f2b0 100644 --- a/src/Input/LocalInputSource.php +++ b/src/Input/LocalInputSource.php @@ -12,11 +12,11 @@ use Exception; use Mindee\Error\ErrorCode; use Mindee\Error\MindeeMimeTypeException; -use Mindee\Error\MindeePDFException; +use Mindee\Error\MindeePdfException; use Mindee\Error\MindeeSourceException; use Mindee\Image\ImageCompressor; -use Mindee\PDF\PDFCompressor; -use Mindee\PDF\PDFUtils; +use Mindee\Pdf\PdfCompressor; +use Mindee\Pdf\PdfUtils; use setasign\Fpdi\Fpdi; use setasign\Fpdi\PdfParser\PdfParserException; use setasign\Fpdi\PdfReader\PdfReaderException; @@ -61,7 +61,7 @@ abstract class LocalInputSource extends InputSource /** * @var string|null Path of the file for files retrieved from a path. */ - public ?string $filePath; + public ?string $filePath = null; /** * Checks if the file needs fixing. @@ -108,7 +108,7 @@ public function __construct() * * @return boolean */ - public function isPDF(): bool + public function isPdf(): bool { $this->checkMimeType(); return $this->fileMimetype === 'application/pdf'; @@ -118,12 +118,12 @@ public function isPDF(): bool * Counts the amount of pages in a PDF. * * @return integer - * @throws MindeePDFException Throws if the source pdf can't be properly processed. + * @throws MindeePdfException Throws if the source pdf can't be properly processed. * @throws MindeeSourceException Throws if the source isn't a pdf. */ public function getPageCount(): int { - if (!$this->isPDF()) { + if (!$this->isPdf()) { throw new MindeeSourceException( "File is not a PDF.", ErrorCode::USER_OPERATION_ERROR @@ -133,7 +133,7 @@ public function getPageCount(): int try { return $pdf->setSourceFile($this->fileObject->getFilename()); } catch (PdfParserException $e) { - throw new MindeePDFException( + throw new MindeePdfException( "Failed to read PDF file.", ErrorCode::PDF_CANT_PROCESS, $e @@ -164,9 +164,9 @@ private function saveBytesAsFile(string $fileBytes): void /** * Create a new PDF from pages and set it as the main file object. * @param array $pageNumbers Array of page numbers to add to the newly created PDF. - * @throws MindeePDFException Throws if the pdf file can't be processed. + * @throws MindeePdfException Throws if the pdf file can't be processed. */ - public function mergePDFPages(array $pageNumbers): void + public function mergePdfPages(array $pageNumbers): void { try { $pdf = new Fpdi(); @@ -178,7 +178,7 @@ public function mergePDFPages(array $pageNumbers): void $this->saveBytesAsFile($pdf->Output($this->fileName, 'S')); $pdf->Close(); } catch (PdfParserException|PdfReaderException $e) { - throw new MindeePDFException( + throw new MindeePdfException( "Failed to read PDF file.", ErrorCode::PDF_CANT_PROCESS, $e @@ -191,9 +191,9 @@ public function mergePDFPages(array $pageNumbers): void * @param integer $threshold Semi-arbitrary threshold of minimum bytes on the page for it to be considered empty. * * @return boolean - * @throws MindeePDFException Throws if the pdf file can't be processed. + * @throws MindeePdfException Throws if the pdf file can't be processed. */ - public function isPDFEmpty(int $threshold = 1024): bool + public function isPdfEmpty(int $threshold = 1024): bool { try { $pdf = new Fpdi(); @@ -204,14 +204,14 @@ public function isPDFEmpty(int $threshold = 1024): bool $pdfPage->setSourceFile($this->fileObject->getFilename()); $pdfPage->AddPage(); $pdfPage->useTemplate($pdfPage->importPage($pageNumber + 1)); - if (strlen($pdfPage->Output('', 'S')) > $threshold) { + if (strlen((string) $pdfPage->Output('', 'S')) > $threshold) { $pdfPage->Close(); return false; } $pdfPage->Close(); } } catch (PdfParserException|PdfReaderException $e) { - throw new MindeePDFException( + throw new MindeePdfException( "Failed to read PDF file.", ErrorCode::PDF_CANT_PROCESS, $e @@ -237,7 +237,7 @@ public function readContents(): array * * @throws MindeeSourceException Throws if the file couldn't be fixed. */ - public function fixPDF(): void + public function fixPdf(): void { if (str_starts_with($this->fileMimetype, "image/")) { error_log("Input file is an image, skipping PDF fix."); @@ -283,15 +283,15 @@ public function compress( bool $forceSourceTextCompression = false, bool $disableSourceText = true ): void { - if ($this->isPDF()) { - $this->fileObject = PDFCompressor::compress( + if ($this->isPdf()) { + $this->fileObject = PdfCompressor::compress( $this->fileObject, $quality, $forceSourceTextCompression, $disableSourceText ); $this->fileMimetype = 'application/pdf'; - $pathInfo = pathinfo($this->filePath); + $pathInfo = pathinfo((string) $this->filePath); $this->filePath = $pathInfo['dirname'] . DIRECTORY_SEPARATOR . $pathInfo['filename'] . '.pdf'; } else { $this->fileObject = ImageCompressor::compress( @@ -301,7 +301,7 @@ public function compress( $maxHeight ); $this->fileMimetype = 'image/jpeg'; - $pathInfo = pathinfo($this->filePath); + $pathInfo = pathinfo((string) $this->filePath); $this->filePath = $pathInfo['dirname'] . DIRECTORY_SEPARATOR . $pathInfo['filename'] . '.jpg'; } } @@ -314,10 +314,10 @@ public function compress( */ public function hasSourceText(): bool { - if (!$this->isPDF()) { + if (!$this->isPdf()) { return false; } - return PDFUtils::hasSourceText($this->filePath); + return PdfUtils::hasSourceText($this->filePath); } @@ -325,12 +325,12 @@ public function hasSourceText(): bool * Applies PDF-specific operations on the current file based on the specified PageOptions. * * @param PageOptions|null $pageOptions The options specifying which pages to modify or retain in the PDF file. - * @throws MindeePDFException If a PDF processing error occurs during the operation. + * @throws MindeePdfException If a PDF processing error occurs during the operation. */ public function applyPageOptions(?PageOptions $pageOptions): void { - if ($this->isPDFEmpty()) { - throw new MindeePDFException( + if ($this->isPdfEmpty()) { + throw new MindeePdfException( "Pages are empty in PDF file.", ErrorCode::USER_INPUT_ERROR ); @@ -365,17 +365,17 @@ public function applyPageOptions(?PageOptions $pageOptions): void } $pagesToKeep = array_diff($allPages, $pagesToRemove); } else { - throw new MindeePDFException( + throw new MindeePdfException( "Unknown operation '" . $pageOptions->operation . "'.", ErrorCode::USER_OPERATION_ERROR ); } if (count($pagesToKeep) < 1) { - throw new MindeePDFException( + throw new MindeePdfException( "Resulting PDF would have no pages left.", ErrorCode::USER_OPERATION_ERROR ); } - $this->mergePDFPages($pagesToKeep); + $this->mergePdfPages($pagesToKeep); } } diff --git a/src/Input/PageOptions.php b/src/Input/PageOptions.php index 999c6867..1f211217 100644 --- a/src/Input/PageOptions.php +++ b/src/Input/PageOptions.php @@ -22,33 +22,12 @@ */ class PageOptions { - /** - * @var array|null Indexes of the page to apply the transformations to. - */ - public ?array $pageIndexes; - /** - * @var string Operation to apply to the page. - */ - public string $operation; - /** - * @var integer Apply the operation only if the document has at least this many pages. - */ - public int $onMinPage; - /** * @param array|null $pageIndexes Indexes of the page. * @param string $operation Operation to apply. * @param integer $onMinPage Minimum page amount. */ - public function __construct( - ?array $pageIndexes = null, - string $operation = KEEP_ONLY, - int $onMinPage = 0 - ) { - $this->pageIndexes = $pageIndexes; - $this->operation = $operation; - $this->onMinPage = $onMinPage; - } + public function __construct(public ?array $pageIndexes = null, public string $operation = KEEP_ONLY, public int $onMinPage = 0) {} /** diff --git a/src/Input/URLInputSource.php b/src/Input/UrlInputSource.php similarity index 98% rename from src/Input/URLInputSource.php rename to src/Input/UrlInputSource.php index 30f9c3c7..41116abf 100644 --- a/src/Input/URLInputSource.php +++ b/src/Input/UrlInputSource.php @@ -10,7 +10,7 @@ /** * A local or distant URL input. */ -class URLInputSource extends InputSource +class UrlInputSource extends InputSource { /** * @var string The Uniform Resource Locator. @@ -70,7 +70,7 @@ public function asLocalInputSource( */ private static function getFileExtension(?string $filename): ?string { - $extension = pathinfo($filename, PATHINFO_EXTENSION); + $extension = pathinfo((string) $filename, PATHINFO_EXTENSION); return $extension ? "." . strtolower($extension) : null; } diff --git a/src/PDF/CustomFPDI.php b/src/Pdf/CustomFpdi.php similarity index 97% rename from src/PDF/CustomFPDI.php rename to src/Pdf/CustomFpdi.php index b72e8645..96551c12 100644 --- a/src/PDF/CustomFPDI.php +++ b/src/Pdf/CustomFpdi.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Mindee\PDF; +namespace Mindee\Pdf; use setasign\Fpdi\Fpdi; use setasign\Fpdi\FpdiTrait; @@ -12,7 +12,7 @@ /** * Custom wrapper to add text rotation to FPDI. */ -class CustomFPDI extends Fpdi +class CustomFpdi extends Fpdi { use FpdiTrait; diff --git a/src/PDF/PDFCompressor.php b/src/Pdf/PdfCompressor.php similarity index 83% rename from src/PDF/PDFCompressor.php rename to src/Pdf/PdfCompressor.php index a2681a6f..8c474157 100644 --- a/src/PDF/PDFCompressor.php +++ b/src/Pdf/PdfCompressor.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace Mindee\PDF; +namespace Mindee\Pdf; use Mindee\Dependency\DependencyChecker; use Mindee\Error\ErrorCode; -use Mindee\Error\MindeePDFException; +use Mindee\Error\MindeePdfException; use Mindee\Error\MindeeUnhandledException; use setasign\Fpdi\Fpdi; use setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException; @@ -21,7 +21,7 @@ /** * PDF compression class. */ -class PDFCompressor +class PdfCompressor { /** * Compresses each page of a provided PDF stream. Skips if force_source_text isn't set and source text is detected. @@ -30,7 +30,7 @@ class PDFCompressor * @param integer $quality Compression quality (70-100 for most JPG images in the test dataset). * @param boolean $forceSourceTextCompression If true, attempts to re-write detected text. * @param boolean $disableSourceText If true, doesn't re-apply source text to the original PDF. - * @throws MindeePDFException Throws if the operation fails at any step. + * @throws MindeePdfException Throws if the operation fails at any step. * //phpcs:disable * @throws MindeeUnhandledException Throws if one of the dependencies isn't installed. */ @@ -44,7 +44,7 @@ public static function compress( DependencyChecker::isImageMagickAvailable(); DependencyChecker::isGhostscriptAvailable(); try { - $pdfPath = PDFUtils::extractFilePath($input); + $pdfPath = PdfUtils::extractFilePath($input); $initialFileSize = filesize($pdfPath); $config = new Config(); $config->setDataTmFontInfoHasToBeIncluded(true); @@ -63,25 +63,25 @@ public static function compress( error_log("[WARNING] Source-text detected in input PDF '$pdfPath'. Aborting operation."); $outputPath = tempnam(sys_get_temp_dir(), 'compressed_pdf_') . '.pdf'; copy($pdfPath, $outputPath); - return PDFUtils::toCURLFile($outputPath); + return PdfUtils::toCURLFile($outputPath); } } try { - $fpdi = new CustomFPDI(); + $fpdi = new CustomFpdi(); $pageCount = $fpdi->setSourceFile($pdfPath); } catch (CrossReferenceException) { error_log("[WARNING] PDF format for '$pdfPath' is not directly supported." . " Output PDF will be rasterized and source text won't be available."); - $pdfPath = PDFUtils::downgradePDFVersion($pdfPath); - $fpdi = new CustomFPDI(); + $pdfPath = PdfUtils::downgradePdfVersion($pdfPath); + $fpdi = new CustomFpdi(); $pdf = $parser->parseFile($pdfPath); $pageCount = $fpdi->setSourceFile($pdfPath); } - $outPdf = new CustomFPDI(); + $outPdf = new CustomFpdi(); for ($i = 1; $i <= $pageCount; $i++) { - [$tempJpegFile, $orientation] = static::processPDFPage($pdfPath, $i, $quality); + [$tempJpegFile, $orientation] = static::processPdfPage($pdfPath, $i, $quality); [$width, $height] = getimagesize($tempJpegFile); $outPdf->AddPage($orientation, [$width, $height]); $outPdf->Image($tempJpegFile, 0, 0, $width, $height); @@ -94,16 +94,16 @@ public static function compress( $outputPath = tempnam(sys_get_temp_dir(), 'compressed_pdf_') . '.pdf'; $outPdf->Output('F', $outputPath); - $finalPDFSize = filesize($outputPath); + $finalPdfSize = filesize($outputPath); - if ($initialFileSize < $finalPDFSize) { + if ($initialFileSize < $finalPdfSize) { error_log("[WARNING] Compressed PDF for '$pdfPath' would be larger than input." . " Aborting operation."); - return PDFUtils::toCURLFile(PDFUtils::extractFilePath($input)); + return PdfUtils::toCURLFile(PdfUtils::extractFilePath($input)); } - return PDFUtils::toCURLFile($outputPath); + return PdfUtils::toCURLFile($outputPath); } catch (Exception $e) { - throw new MindeePDFException( + throw new MindeePdfException( "Couldn't compress PDF.", ErrorCode::FILE_OPERATION_ABORTED, $e @@ -113,18 +113,18 @@ public static function compress( /** * @param Page $inputPage Input page. - * @param CustomFPDI $outputPdf Output PDF handle. - * @throws MindeePDFException Throws if text can't be inserted into the page. + * @param CustomFpdi $outputPdf Output PDF handle. + * @throws MindeePdfException Throws if text can't be inserted into the page. */ - protected static function injectTextForPage(Page $inputPage, CustomFPDI $outputPdf): void + protected static function injectTextForPage(Page $inputPage, CustomFpdi $outputPdf): void { try { - $textElements = PDFUtils::extractTextElements($inputPage); + $textElements = PdfUtils::extractTextElements($inputPage); foreach ($textElements as $element) { - PDFUtils::addTextElement($outputPdf, $element); + PdfUtils::addTextElement($outputPdf, $element); } } catch (Exception $e) { - throw new MindeePDFException( + throw new MindeePdfException( "Couldn't inject text into the new file.", ErrorCode::PDF_CANT_EDIT, $e @@ -139,9 +139,9 @@ protected static function injectTextForPage(Page $inputPage, CustomFPDI $outputP * @param integer $pageIndex The index of the page to process. * @param integer $imageQuality The quality setting for JPEG compression. * @return array{0: string, 1: string} Path to the temporary JPEG file and orientation of the page. - * @throws MindeePDFException If there's an error processing the page. + * @throws MindeePdfException If there's an error processing the page. */ - protected static function processPDFPage(string $sourcePdfPath, int $pageIndex, int $imageQuality): array + protected static function processPdfPage(string $sourcePdfPath, int $pageIndex, int $imageQuality): array { try { $singlePagePdf = new Fpdi(); @@ -169,7 +169,7 @@ protected static function processPDFPage(string $sourcePdfPath, int $pageIndex, return [$tempJpegFile, $size['orientation']]; } catch (Exception $e) { - throw new MindeePDFException( + throw new MindeePdfException( "Couldn't process PDF page $pageIndex.", ErrorCode::PDF_CANT_PROCESS, $e diff --git a/src/PDF/PDFUtils.php b/src/Pdf/PdfUtils.php similarity index 89% rename from src/PDF/PDFUtils.php rename to src/Pdf/PdfUtils.php index 1eb6718c..1e0aefca 100644 --- a/src/PDF/PDFUtils.php +++ b/src/Pdf/PdfUtils.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace Mindee\PDF; +namespace Mindee\Pdf; use CURLFile; use Exception; use Mindee\Error\ErrorCode; use Mindee\Error\MindeeImageException; -use Mindee\Error\MindeePDFException; +use Mindee\Error\MindeePdfException; use Smalot\PdfParser\Config; use Smalot\PdfParser\Font; use Smalot\PdfParser\Page; @@ -23,12 +23,12 @@ /** * PDF utility class. */ -class PDFUtils +class PdfUtils { /** * @param SplFileObject|Imagick|CURLFile|string|resource $input Input file. Accepts SplFileObject, Imagick, Curl, resources & paths. * @return string Path of the file. - * @throws MindeePDFException Throws if a path can't be extracted from the input. + * @throws MindeePdfException Throws if a path can't be extracted from the input. */ public static function extractFilePath(mixed $input): string { @@ -53,12 +53,12 @@ public static function extractFilePath(mixed $input): string return $tempPath; } else { - throw new MindeePDFException('Input PDF must be a SplFileObject, path, resource or Imagick handle.'); + throw new MindeePdfException('Input PDF must be a SplFileObject, path, resource or Imagick handle.'); } - } catch (MindeePDFException $e) { + } catch (MindeePdfException $e) { throw $e; } catch (Exception $e) { - throw new MindeePDFException( + throw new MindeePdfException( "Conversion to MagickImage failed.\n", ErrorCode::IMAGE_CANT_PROCESS, $e @@ -87,7 +87,7 @@ public static function hasSourceText(string $pdfPath): bool * @param string $pdfPath Path to the PDF file. * @return array A page-indexed array of text elements. * Each text element includes text content, position, font, size, and color. - * @throws MindeePDFException Throws if the PDF can't be parsed or text elements can't be extracted. + * @throws MindeePdfException Throws if the PDF can't be parsed or text elements can't be extracted. */ public static function extractPagesTextElements(string $pdfPath): array { @@ -106,7 +106,7 @@ public static function extractPagesTextElements(string $pdfPath): array return $allPagesTextElements; } catch (Exception $e) { - throw new MindeePDFException( + throw new MindeePdfException( 'Failed to parse PDF or extract text elements: ', ErrorCode::PDF_CANT_PROCESS, $e @@ -120,10 +120,10 @@ public static function extractPagesTextElements(string $pdfPath): array * * @param string $inputPath Input PDF path. * @return string Output path. - * @throws MindeePDFException Throws if the file can't be handled through Imagick. - * @throws Exception Will be thrown as MindeePDFException, this is just for PHPCS linting purposes. + * @throws MindeePdfException Throws if the file can't be handled through ghostscript. + * @throws Exception Will be thrown as MindeePdfException, this is just for PHPCS linting purposes. */ - public static function downgradePDFVersion(string $inputPath): string + public static function downgradePdfVersion(string $inputPath): string { try { $outputPath = tempnam(sys_get_temp_dir(), 'downgrade_pdf_') . '.pdf'; @@ -139,7 +139,7 @@ public static function downgradePDFVersion(string $inputPath): string return $outputPath; } catch (Exception $e) { - throw new MindeePDFException( + throw new MindeePdfException( "Cannot downgrade PDF version.", ErrorCode::PDF_CANT_PROCESS, $e @@ -154,7 +154,7 @@ public static function downgradePDFVersion(string $inputPath): string * @param Page $page Page object. * @return array> An array of text elements, each containing text content, * position, font, size, and color. - * @throws MindeePDFException Throws if the text elements can't be extracted. + * @throws MindeePdfException Throws if the text elements can't be extracted. */ public static function extractTextElements(Page $page): array { @@ -180,7 +180,7 @@ public static function extractTextElements(Page $page): array return $textElements; } catch (Exception $e) { - throw new MindeePDFException( + throw new MindeePdfException( 'Failed to parse text elements: ', ErrorCode::PDF_CANT_PROCESS, $e @@ -195,7 +195,7 @@ public static function extractTextElements(Page $page): array protected static function standardizeFontName(string $fontName): array { $cleanName = preg_replace('/^.*?\+/', '', $fontName); - $parts = explode('-', $cleanName, 2); + $parts = explode('-', (string) $cleanName, 2); $fontFamily = $parts[0]; $fontStyle = $parts[1] ?? ''; @@ -217,10 +217,10 @@ protected static function standardizeFontName(string $fontName): array /** * Adds a text element to the output PDF. * - * @param CustomFPDI $pdf The output PDF object. + * @param CustomFpdi $pdf The output PDF object. * @param array $element Text element array containing text, position, font, size, and color. */ - public static function addTextElement(CustomFPDI $pdf, array $element): void + public static function addTextElement(CustomFpdi $pdf, array $element): void { $fontInfo = static::standardizeFontName($element['font']->getName()); $pageHeight = $pdf->GetPageHeight(); diff --git a/src/V1/Client.php b/src/V1/Client.php index c07f9dc3..b187b962 100644 --- a/src/V1/Client.php +++ b/src/V1/Client.php @@ -27,14 +27,14 @@ use Mindee\Input\LocalResponse; use Mindee\Input\PageOptions; use Mindee\Input\PathInput; -use Mindee\Input\URLInputSource; +use Mindee\Input\UrlInputSource; use Mindee\V1\ClientOptions\PredictMethodOptions; use Mindee\V1\ClientOptions\WorkflowOptions; -use Mindee\V1\HTTP\Endpoint; -use Mindee\V1\HTTP\MindeeAPI; -use Mindee\V1\HTTP\MindeeWorkflowAPI; -use Mindee\V1\HTTP\ResponseValidation; -use Mindee\V1\HTTP\WorkflowEndpoint; +use Mindee\V1\Http\Endpoint; +use Mindee\V1\Http\MindeeApi; +use Mindee\V1\Http\MindeeWorkflowApi; +use Mindee\V1\Http\ResponseValidation; +use Mindee\V1\Http\WorkflowEndpoint; use Mindee\V1\Parsing\Common\AsyncPredictResponse; use Mindee\V1\Parsing\Common\PredictResponse; use Mindee\V1\Parsing\Common\WorkflowResponse; @@ -77,13 +77,13 @@ public function __construct(?string $apiKey = null) * Load a document from an absolute path, as a string. * * @param string $filePath Path of the file. - * @param boolean $fixPDF Whether the PDF should be fixed or not. + * @param boolean $fixPdf Whether the PDF should be fixed or not. */ - public function sourceFromPath(string $filePath, bool $fixPDF = false): PathInput + public function sourceFromPath(string $filePath, bool $fixPdf = false): PathInput { $input = new PathInput($filePath); - if ($fixPDF) { - $input->fixPDF(); + if ($fixPdf) { + $input->fixPdf(); } return $input; } @@ -92,13 +92,13 @@ public function sourceFromPath(string $filePath, bool $fixPDF = false): PathInpu * Load a document from a normal PHP file object. * * @param SplFileObject|CURLFile|string|resource $file File object as created from the file() function. - * @param boolean $fixPDF Whether the PDF should be fixed or not. + * @param boolean $fixPdf Whether the PDF should be fixed or not. */ - public function sourceFromFile(mixed $file, bool $fixPDF = false): FileInput + public function sourceFromFile(mixed $file, bool $fixPdf = false): FileInput { $input = new FileInput($file); - if ($fixPDF) { - $input->fixPDF(); + if ($fixPdf) { + $input->fixPdf(); } return $input; } @@ -108,13 +108,13 @@ public function sourceFromFile(mixed $file, bool $fixPDF = false): FileInput * * @param string $fileBytes File object in raw bytes. * @param string $fileName File name, mandatory. - * @param boolean $fixPDF Whether the PDF should be fixed or not. + * @param boolean $fixPdf Whether the PDF should be fixed or not. */ - public function sourceFromBytes(string $fileBytes, string $fileName, bool $fixPDF = false): BytesInput + public function sourceFromBytes(string $fileBytes, string $fileName, bool $fixPdf = false): BytesInput { $input = new BytesInput($fileBytes, $fileName); - if ($fixPDF) { - $input->fixPDF(); + if ($fixPdf) { + $input->fixPdf(); } return $input; } @@ -124,13 +124,13 @@ public function sourceFromBytes(string $fileBytes, string $fileName, bool $fixPD * * @param string $fileB64 File object in Base64. * @param string $fileName File name, mandatory. - * @param boolean $fixPDF Whether the PDF should be fixed or not. + * @param boolean $fixPdf Whether the PDF should be fixed or not. */ - public function sourceFromB64String(string $fileB64, string $fileName, bool $fixPDF = false): Base64Input + public function sourceFromB64String(string $fileB64, string $fileName, bool $fixPdf = false): Base64Input { $input = new Base64Input($fileB64, $fileName); - if ($fixPDF) { - $input->fixPDF(); + if ($fixPdf) { + $input->fixPdf(); } return $input; } @@ -140,9 +140,9 @@ public function sourceFromB64String(string $fileB64, string $fileName, bool $fix * * @param string $url File URL. Must start with "https://". */ - public function sourceFromUrl(string $url): URLInputSource + public function sourceFromUrl(string $url): UrlInputSource { - return new URLInputSource($url); + return new UrlInputSource($url); } /** @@ -159,7 +159,7 @@ private function constructEndpoint( ): Endpoint { $endpointVersion = $endpointVersion !== '' ? $endpointVersion : '1'; - $endpointSettings = new MindeeAPI($this->apiKey, $endpointName, $endpointOwner, $endpointVersion); + $endpointSettings = new MindeeApi($this->apiKey, $endpointName, $endpointOwner, $endpointVersion); return new Endpoint($endpointName, $endpointOwner, $endpointVersion, $endpointSettings); } @@ -324,7 +324,7 @@ private function makeWorkflowExecutionRequest( string $workflowId, PredictMethodOptions $options ): WorkflowResponse { - $workflowRouterSettings = new MindeeWorkflowAPI($this->apiKey, $workflowId); + $workflowRouterSettings = new MindeeWorkflowApi($this->apiKey, $workflowId); $options->endpoint = new WorkflowEndpoint($workflowRouterSettings); if (!$options->pageOptions->isEmpty()) { if ($inputDoc instanceof LocalInputSource) { @@ -412,7 +412,7 @@ public function parse( if (null === $options) { $options = new PredictMethodOptions(); } - if ($pageOptions !== null && $inputDoc instanceof LocalInputSource && $inputDoc->isPDF()) { + if ($pageOptions !== null && $inputDoc instanceof LocalInputSource && $inputDoc->isPdf()) { $this->cutDocPages($inputDoc, $pageOptions); } $options->endpoint ??= $this->constructOTSEndpoint( @@ -497,7 +497,7 @@ public function enqueue( if (null === $options) { $options = new PredictMethodOptions(); } - if ($pageOptions !== null && $inputDoc instanceof LocalInputSource && $inputDoc->isPDF()) { + if ($pageOptions !== null && $inputDoc instanceof LocalInputSource && $inputDoc->isPdf()) { $this->cutDocPages($inputDoc, $pageOptions); } $options->endpoint ??= $this->constructOTSEndpoint( @@ -566,7 +566,7 @@ public function executeWorkflow( if (null === $options) { $options = new WorkflowOptions(); } - if ($pageOptions !== null && $inputDoc instanceof LocalInputSource && $inputDoc->isPDF()) { + if ($pageOptions !== null && $inputDoc instanceof LocalInputSource && $inputDoc->isPdf()) { $this->cutDocPages($inputDoc, $pageOptions); } diff --git a/src/V1/ClientOptions/CommonOptions.php b/src/V1/ClientOptions/CommonOptions.php index 531cbfbb..e6493c76 100644 --- a/src/V1/ClientOptions/CommonOptions.php +++ b/src/V1/ClientOptions/CommonOptions.php @@ -9,21 +9,12 @@ */ abstract class CommonOptions { - /** - * @var boolean Whether to include the full OCR text response in compatible APIs. - * This performs a full OCR operation on the server and will increase response time. - */ - public bool $fullText; - /** * Prediction options. - * @param boolean $fullText Whether to include the full OCR text response in compatible APIs. - * This performs a full OCR operation on the server and will increase response time. + * @param boolean $fullText Whether to include the full Ocr text response in compatible APIs. + * This performs a full Ocr operation on the server and will increase response time. */ - public function __construct(bool $fullText = false) - { - $this->fullText = $fullText; - } + public function __construct(public bool $fullText = false) {} /** * @param boolean $fullText Whether to include the full text. diff --git a/src/V1/ClientOptions/PredictMethodOptions.php b/src/V1/ClientOptions/PredictMethodOptions.php index 076918bb..360215b4 100644 --- a/src/V1/ClientOptions/PredictMethodOptions.php +++ b/src/V1/ClientOptions/PredictMethodOptions.php @@ -5,8 +5,8 @@ namespace Mindee\V1\ClientOptions; use Mindee\Input\PageOptions; -use Mindee\V1\HTTP\Endpoint; -use Mindee\V1\HTTP\WorkflowEndpoint; +use Mindee\V1\Http\Endpoint; +use Mindee\V1\Http\WorkflowEndpoint; /** * Handles options tied to prediction method. diff --git a/src/V1/ClientOptions/PredictOptions.php b/src/V1/ClientOptions/PredictOptions.php index 99ccb908..26276199 100644 --- a/src/V1/ClientOptions/PredictOptions.php +++ b/src/V1/ClientOptions/PredictOptions.php @@ -9,35 +9,21 @@ */ class PredictOptions extends CommonOptions { - /** - * @var boolean Whether to include the full text for each page. - * This performs a full OCR operation on the server and will increase response time. - */ - public bool $includeWords; - - /** - * @var boolean Whether to include cropper results for each page. - * This performs a cropping operation on the server and may increase response time. - */ - public bool $cropper; - /** * Prediction options. - * @param boolean $fullText Whether to include the full OCR text response in compatible APIs. - * This performs a full OCR operation on the server and will increase response time. + * @param boolean $fullText Whether to include the full Ocr text response in compatible APIs. + * This performs a full Ocr operation on the server and will increase response time. * @param boolean $includeWords Whether to include the full text for each page. - * This performs a full OCR operation on the server and will increase response time. + * This performs a full Ocr operation on the server and will increase response time. * @param boolean $cropper Whether to include cropper results for each page. * This performs a cropping operation on the server and may increase response time. */ public function __construct( bool $fullText = false, - bool $includeWords = false, - bool $cropper = false + public bool $includeWords = false, + public bool $cropper = false ) { parent::__construct($fullText); - $this->includeWords = $includeWords; - $this->cropper = $cropper; } /** diff --git a/src/V1/ClientOptions/WorkflowOptions.php b/src/V1/ClientOptions/WorkflowOptions.php index 051ae962..45d70e63 100644 --- a/src/V1/ClientOptions/WorkflowOptions.php +++ b/src/V1/ClientOptions/WorkflowOptions.php @@ -9,27 +9,6 @@ */ class WorkflowOptions extends CommonOptions { - /** - * @var string|null Alias to give to the document. - */ - public ?string $alias; - - /** - * @var string|null Priority to give to the document. - */ - public ?string $priority; - - /** - * @var string|null A unique, encrypted URL for accessing the document validation interface without requiring - * authentication. - */ - public ?string $publicUrl; - - /** - * @var boolean|null Whether to enable Retrieval-Augmented Generation. - */ - public ?bool $rag; - /** * @param string|null $alias Alias for the document. * @param string|null $priority Priority for the document. @@ -38,16 +17,12 @@ class WorkflowOptions extends CommonOptions * @param boolean $rag Whether to enable Retrieval-Augmented Generation. */ public function __construct( - ?string $alias = null, - ?string $priority = null, + public ?string $alias = null, + public ?string $priority = null, bool $fullTextOcr = false, - ?string $publicUrl = null, - bool $rag = false + public ?string $publicUrl = null, + public ?bool $rag = false ) { parent::__construct($fullTextOcr); - $this->alias = $alias; - $this->priority = $priority; - $this->publicUrl = $publicUrl; - $this->rag = $rag; } } diff --git a/src/V1/HTTP/BaseAPI.php b/src/V1/Http/BaseApi.php similarity index 86% rename from src/V1/HTTP/BaseAPI.php rename to src/V1/Http/BaseApi.php index 457dca2e..fafb1b4f 100644 --- a/src/V1/HTTP/BaseAPI.php +++ b/src/V1/Http/BaseApi.php @@ -6,7 +6,7 @@ * Settings and variables linked to all API usage. */ -namespace Mindee\V1\HTTP; +namespace Mindee\V1\Http; /** * Default key name for the API key entry in environment variables. @@ -45,25 +45,22 @@ */ function getUserAgent(): string { - switch (PHP_OS_FAMILY) { - case "Darwin": - $os = "macos"; - break; - default: - $os = strtolower(PHP_OS_FAMILY); - } + $os = match (PHP_OS_FAMILY) { + "Darwin" => "macos", + default => strtolower(PHP_OS_FAMILY), + }; return 'mindee-api-php@v' . VERSION . ' php-v' . PHP_VERSION . ' ' . $os; } /** * Base class for API settings. */ -abstract class BaseAPI +abstract class BaseApi { /** * @var string|null API key. */ - public ?string $apiKey; + public ?string $apiKey = null; /** * @var integer Timeout for the request, in ms. */ @@ -104,8 +101,8 @@ protected function setTimeout(int $value): void protected function setFromEnv(): void { $envVars = [ - BASE_URL_ENV_NAME => [$this, 'setBaseUrl'], - REQUEST_TIMEOUT_ENV_NAME => [$this, 'setTimeout'], + BASE_URL_ENV_NAME => $this->setBaseUrl(...), + REQUEST_TIMEOUT_ENV_NAME => $this->setTimeout(...), ]; foreach ($envVars as $key => $func) { $envVal = getenv($key) ?: ''; @@ -121,7 +118,7 @@ protected function setFromEnv(): void * * @param string|null $apiKey Optional API key. */ - protected function setApiKey(?string $apiKey = null): void + protected function setAPIKey(?string $apiKey = null): void { $envVal = !getenv(API_KEY_ENV_NAME) ? '' : getenv(API_KEY_ENV_NAME); if (!$apiKey) { @@ -138,7 +135,7 @@ protected function setApiKey(?string $apiKey = null): void public function __construct( ?string $apiKey ) { - $this->setApiKey($apiKey); + $this->setAPIKey($apiKey); $this->baseUrl = BASE_URL_DEFAULT; $this->requestTimeout = TIMEOUT_DEFAULT; $this->setFromEnv(); diff --git a/src/V1/HTTP/BaseEndpoint.php b/src/V1/Http/BaseEndpoint.php similarity index 87% rename from src/V1/HTTP/BaseEndpoint.php rename to src/V1/Http/BaseEndpoint.php index 1c360253..1439f57e 100644 --- a/src/V1/HTTP/BaseEndpoint.php +++ b/src/V1/Http/BaseEndpoint.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Mindee\V1\HTTP; +namespace Mindee\V1\Http; use CurlHandle; @@ -12,17 +12,9 @@ abstract class BaseEndpoint { /** - * @var MindeeAPI|MindeeWorkflowAPI Settings of the endpoint. + * @param MindeeApi|MindeeWorkflowApi $settings Input settings. */ - public MindeeAPI|MindeeWorkflowAPI $settings; - - /** - * @param MindeeAPI|MindeeWorkflowAPI $settings Input settings. - */ - public function __construct(MindeeAPI|MindeeWorkflowAPI $settings) - { - $this->settings = $settings; - } + public function __construct(public MindeeApi|MindeeWorkflowApi $settings) {} /** * Starts a CURL session using GET. diff --git a/src/V1/HTTP/Endpoint.php b/src/V1/Http/Endpoint.php similarity index 85% rename from src/V1/HTTP/Endpoint.php rename to src/V1/Http/Endpoint.php index 9b10b6fa..94a87c6e 100644 --- a/src/V1/HTTP/Endpoint.php +++ b/src/V1/Http/Endpoint.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace Mindee\V1\HTTP; +namespace Mindee\V1\Http; use Mindee\Error\MindeeException; use Mindee\Input\InputSource; use Mindee\Input\LocalInputSource; -use Mindee\Input\URLInputSource; +use Mindee\Input\UrlInputSource; use Mindee\V1\ClientOptions\PredictMethodOptions; /** @@ -15,35 +15,19 @@ */ class Endpoint extends BaseEndpoint { - /** - * @var string Url (name) of then endpoint. - */ - public string $urlName; - /** - * @var string Name of the endpoint's owner. - */ - public string $owner; - /** - * @var string Version of the endpoint. - */ - public string $version; - /** * @param string $urlName Url (name) of the endpoint. * @param string $owner Name of the endpoint's owner. * @param string $version Version of the endpoint. - * @param MindeeAPI $settings Settings for the endpoint. + * @param MindeeApi $settings Settings for the endpoint. */ public function __construct( - string $urlName, - string $owner, - string $version, - MindeeAPI $settings + public string $urlName, + public string $owner, + public string $version, + MindeeApi $settings ) { parent::__construct($settings); - $this->urlName = $urlName; - $this->owner = $owner; - $this->version = $version; } /** @@ -119,7 +103,7 @@ private function initCurlSessionPost( curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); $postFields = null; - if ($inputSource instanceof URLInputSource) { + if ($inputSource instanceof UrlInputSource) { $postFields = ['document' => $inputSource->url]; } elseif ($inputSource instanceof LocalInputSource) { $inputSource->checkNeedsFix(); diff --git a/src/V1/HTTP/MindeeAPI.php b/src/V1/Http/MindeeApi.php similarity index 96% rename from src/V1/HTTP/MindeeAPI.php rename to src/V1/Http/MindeeApi.php index 89f14fa9..af0b7f06 100644 --- a/src/V1/HTTP/MindeeAPI.php +++ b/src/V1/Http/MindeeApi.php @@ -6,7 +6,7 @@ * Settings and variables linked to endpoint calling & API usage. */ -namespace Mindee\V1\HTTP; +namespace Mindee\V1\Http; use Mindee\Error\ErrorCode; use Mindee\Error\MindeeException; @@ -15,7 +15,7 @@ /** * Data class containing settings for endpoints. */ -class MindeeAPI extends BaseAPI +class MindeeApi extends BaseApi { /** * @var string Name of the endpoint. diff --git a/src/V1/HTTP/MindeeWorkflowAPI.php b/src/V1/Http/MindeeWorkflowApi.php similarity index 81% rename from src/V1/HTTP/MindeeWorkflowAPI.php rename to src/V1/Http/MindeeWorkflowApi.php index 3f5af199..bff07d07 100644 --- a/src/V1/HTTP/MindeeWorkflowAPI.php +++ b/src/V1/Http/MindeeWorkflowApi.php @@ -6,7 +6,7 @@ * Settings and variables linked to endpoint calling & API usage. */ -namespace Mindee\V1\HTTP; +namespace Mindee\V1\Http; use Mindee\Error\ErrorCode; use Mindee\Error\MindeeException; @@ -14,12 +14,8 @@ /** * Data class containing settings for workflows. */ -class MindeeWorkflowAPI extends BaseAPI +class MindeeWorkflowApi extends BaseApi { - /** - * @var string ID of the workflow. - */ - public string $workflowId; /** * @param string|null $apiKey API key. * @param string $workflowId ID of the workflow. @@ -27,7 +23,7 @@ class MindeeWorkflowAPI extends BaseAPI */ public function __construct( ?string $apiKey, - string $workflowId + public string $workflowId ) { parent::__construct($apiKey); if (empty($this->apiKey)) { @@ -37,7 +33,6 @@ public function __construct( ErrorCode::USER_INPUT_ERROR ); } - $this->workflowId = $workflowId; $this->urlRoot = rtrim( $this->baseUrl, "/" diff --git a/src/V1/HTTP/ResponseValidation.php b/src/V1/Http/ResponseValidation.php similarity index 99% rename from src/V1/HTTP/ResponseValidation.php rename to src/V1/Http/ResponseValidation.php index bd8501c0..7a3c585e 100644 --- a/src/V1/HTTP/ResponseValidation.php +++ b/src/V1/Http/ResponseValidation.php @@ -6,7 +6,7 @@ * Settings and variables linked to endpoint calling & API usage. */ -namespace Mindee\V1\HTTP; +namespace Mindee\V1\Http; use function count; use function is_string; diff --git a/src/V1/HTTP/WorkflowEndpoint.php b/src/V1/Http/WorkflowEndpoint.php similarity index 92% rename from src/V1/HTTP/WorkflowEndpoint.php rename to src/V1/Http/WorkflowEndpoint.php index 87568786..cb8120fa 100644 --- a/src/V1/HTTP/WorkflowEndpoint.php +++ b/src/V1/Http/WorkflowEndpoint.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace Mindee\V1\HTTP; +namespace Mindee\V1\Http; use Mindee\Error\MindeeException; use Mindee\Input\InputSource; use Mindee\Input\LocalInputSource; -use Mindee\Input\URLInputSource; +use Mindee\Input\UrlInputSource; use Mindee\V1\ClientOptions\WorkflowOptions; /** @@ -16,10 +16,10 @@ class WorkflowEndpoint extends BaseEndpoint { /** - * @param MindeeWorkflowAPI $settings Settings for the endpoint. + * @param MindeeWorkflowApi $settings Settings for the endpoint. */ public function __construct( - MindeeWorkflowAPI $settings + MindeeWorkflowApi $settings ) { parent::__construct($settings); } @@ -64,7 +64,7 @@ private function initCurlSessionPost( curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->settings->requestTimeout); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); - if ($fileCurl instanceof URLInputSource) { + if ($fileCurl instanceof UrlInputSource) { $postFields = ['document' => $fileCurl->url]; } elseif ($fileCurl instanceof LocalInputSource) { $postFields = ['document' => $fileCurl->fileObject]; diff --git a/src/V1/Parsing/Common/ApiResponse.php b/src/V1/Parsing/Common/ApiResponse.php index 71f5a8a6..f09cb7b5 100644 --- a/src/V1/Parsing/Common/ApiResponse.php +++ b/src/V1/Parsing/Common/ApiResponse.php @@ -16,7 +16,7 @@ abstract class ApiResponse /** * @var array> Raw http result. Used for debugging purposes. */ - private array $rawHttp; + private readonly array $rawHttp; /** * @param array> $rawResponse Raw prediction array. diff --git a/src/V1/Parsing/Common/Document.php b/src/V1/Parsing/Common/Document.php index 57b97bcf..0a5075fb 100644 --- a/src/V1/Parsing/Common/Document.php +++ b/src/V1/Parsing/Common/Document.php @@ -7,16 +7,17 @@ use Mindee\Error\ErrorCode; use Mindee\Error\MindeeApiException; use Mindee\V1\Parsing\Common\Extras\Extras; -use Mindee\V1\Parsing\Common\OCR\OCR; +use Mindee\V1\Parsing\Common\Ocr\Ocr; use ReflectionClass; use ReflectionException; +use Stringable; use function array_key_exists; /** * Base class for all predictions. */ -class Document +class Document implements Stringable { /** * @var string Name of the input document. @@ -39,9 +40,9 @@ class Document */ public ?Extras $extras; /** - * @var OCR|null Potential raw text results read by the OCR (limited feature) + * @var Ocr|null Potential raw text results read by the Ocr (limited feature) */ - public ?OCR $ocr; + public ?Ocr $ocr; /** * @param string $predictionType Type of prediction. @@ -64,12 +65,12 @@ public function __construct(string $predictionType, array $rawResponse) ); } if (array_key_exists('ocr', $rawResponse) && $rawResponse['ocr']) { - $this->ocr = new OCR($rawResponse['ocr']); + $this->ocr = new Ocr($rawResponse['ocr']); } if (array_key_exists("extras", $rawResponse['inference']) && $rawResponse['inference']['extras']) { $this->extras = new Extras($rawResponse['inference']['extras']); } - $this->injectFullTextOCR($rawResponse); + $this->injectFullTextOcr($rawResponse); } /** @@ -91,7 +92,7 @@ public function __toString(): string * * @param array> $rawResponse Raw HTTP response. */ - private function injectFullTextOCR(array $rawResponse): void + private function injectFullTextOcr(array $rawResponse): void { $pages = $rawResponse['inference']['pages'] ?? []; diff --git a/src/V1/Parsing/Common/Execution.php b/src/V1/Parsing/Common/Execution.php index a7837197..ec0e24e2 100644 --- a/src/V1/Parsing/Common/Execution.php +++ b/src/V1/Parsing/Common/Execution.php @@ -11,11 +11,12 @@ use Mindee\V1\Product\Generated\GeneratedV1Document; use ReflectionClass; use ReflectionException; +use Stringable; /** * Representation of a workflow execution. */ -class Execution +class Execution implements Stringable { /** * Identifier for the batch to which the execution belongs. @@ -127,6 +128,6 @@ public function __toString(): string $objAsArray = get_object_vars($this); ksort($objAsArray); - return json_encode($objAsArray, JSON_PRETTY_PRINT); + return (string) json_encode($objAsArray, JSON_PRETTY_PRINT); } } diff --git a/src/V1/Parsing/Common/Extras/CropperExtra.php b/src/V1/Parsing/Common/Extras/CropperExtra.php index 316c1aad..112bf18b 100644 --- a/src/V1/Parsing/Common/Extras/CropperExtra.php +++ b/src/V1/Parsing/Common/Extras/CropperExtra.php @@ -5,13 +5,14 @@ namespace Mindee\V1\Parsing\Common\Extras; use Mindee\V1\Parsing\Standard\PositionField; +use Stringable; use function array_key_exists; /** * Contains information on the cropping of a prediction. */ -class CropperExtra +class CropperExtra implements Stringable { /** * @var array List of all croppings coordiantes. diff --git a/src/V1/Parsing/Common/Extras/Extras.php b/src/V1/Parsing/Common/Extras/Extras.php index cd053a4b..4e51521e 100644 --- a/src/V1/Parsing/Common/Extras/Extras.php +++ b/src/V1/Parsing/Common/Extras/Extras.php @@ -4,6 +4,8 @@ namespace Mindee\V1\Parsing\Common\Extras; +use Stringable; + use function is_scalar; /** @@ -11,20 +13,20 @@ * * Is roughly equivalent to an array of Extras, with a bit more utility. */ -class Extras +class Extras implements Stringable { /** * @var CropperExtra|null Cropper extra. */ public ?CropperExtra $cropper; /** - * @var FullTextOCRExtra|null Full text OCR extra. + * @var FullTextOcrExtra|null Full text Ocr extra. */ - public ?FullTextOCRExtra $fullTextOcr; + public ?FullTextOcrExtra $fullTextOcr; /** - * @var RAGExtra|null Rag Extra. + * @var RagExtra|null Rag Extra. */ - public ?RAGExtra $rag; + public ?RagExtra $rag; /** * @var array> Other extras. */ @@ -50,9 +52,9 @@ public function __construct(array $rawPrediction) if ($key === 'cropper' && isset($rawPrediction['cropper'])) { $this->cropper = new CropperExtra($rawPrediction['cropper']); } elseif ($key === 'full_text_ocr' && isset($rawPrediction['full_text_ocr'])) { - $this->fullTextOcr = new FullTextOCRExtra($rawPrediction['full_text_ocr']); + $this->fullTextOcr = new FullTextOcrExtra($rawPrediction['full_text_ocr']); } elseif ($key === 'rag' && isset($rawPrediction['rag'])) { - $this->rag = new RAGExtra($rawPrediction['rag']); + $this->rag = new RagExtra($rawPrediction['rag']); } else { $this->__set($key, $extra); } @@ -68,14 +70,13 @@ public function __construct(array $rawPrediction) public function addArtificialExtra(array $rawPrediction): void { if (!empty($rawPrediction['full_text_ocr'])) { - $this->fullTextOcr = new FullTextOCRExtra($rawPrediction['full_text_ocr']); + $this->fullTextOcr = new FullTextOcrExtra($rawPrediction['full_text_ocr']); } } /** - * @return string */ - public function __toString() + public function __toString(): string { $resStr = ''; foreach ($this->data as $key => $extra) { diff --git a/src/V1/Parsing/Common/Extras/FullTextOCRExtra.php b/src/V1/Parsing/Common/Extras/FullTextOcrExtra.php similarity index 86% rename from src/V1/Parsing/Common/Extras/FullTextOCRExtra.php rename to src/V1/Parsing/Common/Extras/FullTextOcrExtra.php index 869d8358..05635db3 100644 --- a/src/V1/Parsing/Common/Extras/FullTextOCRExtra.php +++ b/src/V1/Parsing/Common/Extras/FullTextOcrExtra.php @@ -4,10 +4,12 @@ namespace Mindee\V1\Parsing\Common\Extras; +use Stringable; + /** - * Full Text OCR result. + * Full Text Ocr result. */ -class FullTextOCRExtra +class FullTextOcrExtra implements Stringable { /** * @var string|null Text content of the full text ocr reading. @@ -34,9 +36,8 @@ public function __construct(array $rawPrediction) } /** - * @return string */ - public function __toString() + public function __toString(): string { return $this->content ?? ''; } diff --git a/src/V1/Parsing/Common/Extras/RAGExtra.php b/src/V1/Parsing/Common/Extras/RagExtra.php similarity index 93% rename from src/V1/Parsing/Common/Extras/RAGExtra.php rename to src/V1/Parsing/Common/Extras/RagExtra.php index 4d469c1b..351ea48b 100644 --- a/src/V1/Parsing/Common/Extras/RAGExtra.php +++ b/src/V1/Parsing/Common/Extras/RagExtra.php @@ -4,10 +4,12 @@ namespace Mindee\V1\Parsing\Common\Extras; +use Stringable; + /** * Contains information on the Retrieval-Augmented-Generation of a prediction. */ -class RAGExtra +class RagExtra implements Stringable { /** * @var string|null The document ID of the matching document. diff --git a/src/V1/Parsing/Common/Inference.php b/src/V1/Parsing/Common/Inference.php index 0875c344..ca2713c9 100644 --- a/src/V1/Parsing/Common/Inference.php +++ b/src/V1/Parsing/Common/Inference.php @@ -5,6 +5,7 @@ namespace Mindee\V1\Parsing\Common; use Mindee\V1\Parsing\Common\Extras\Extras; +use Stringable; use function array_key_exists; use function count; @@ -12,7 +13,7 @@ /** * Base Inference class for all predictions. */ -abstract class Inference +abstract class Inference implements Stringable { /** * @var Product Name and version of a given product, as sent back by the API. diff --git a/src/V1/Parsing/Common/Job.php b/src/V1/Parsing/Common/Job.php index e159e495..e21f711f 100644 --- a/src/V1/Parsing/Common/Job.php +++ b/src/V1/Parsing/Common/Job.php @@ -8,6 +8,7 @@ use Mindee\Error\ErrorCode; use Mindee\Error\MindeeApiException; use Exception; +use Stringable; use function array_key_exists; @@ -16,7 +17,7 @@ * * Will hold information on the queue a document has been submitted to. */ -class Job +class Job implements Stringable { /** * @var string|null ID of the job sent by the API in response to an enqueue request. @@ -41,7 +42,7 @@ class Job /** * @var array>|null Information about an error that occurred during the job processing. */ - public ?array $error; + public ?array $error = null; /** * @param array> $rawResponse Raw prediction array. @@ -81,7 +82,7 @@ public function __construct(array $rawResponse) throw new Exception("Invalid date format"); } $this->availableAt = new DateTimeImmutable('@' . $timestamp); - } catch (Exception $e2) { + } catch (Exception) { throw new MindeeApiException( "Could not create date from " . $rawResponse['available_at'], ErrorCode::API_UNPROCESSABLE_ENTITY, @@ -105,6 +106,6 @@ public function __toString(): string $objAsJson = get_object_vars($this); ksort($objAsJson); - return json_encode($objAsJson, JSON_PRETTY_PRINT); + return (string) json_encode($objAsJson, JSON_PRETTY_PRINT); } } diff --git a/src/V1/Parsing/Common/OCR/MVisionV1.php b/src/V1/Parsing/Common/Ocr/MVisionV1.php similarity index 76% rename from src/V1/Parsing/Common/OCR/MVisionV1.php rename to src/V1/Parsing/Common/Ocr/MVisionV1.php index b31688b3..95f23d62 100644 --- a/src/V1/Parsing/Common/OCR/MVisionV1.php +++ b/src/V1/Parsing/Common/Ocr/MVisionV1.php @@ -2,15 +2,17 @@ declare(strict_types=1); -namespace Mindee\V1\Parsing\Common\OCR; +namespace Mindee\V1\Parsing\Common\Ocr; + +use Stringable; /** * Mindee Vision V1. */ -class MVisionV1 +class MVisionV1 implements Stringable { /** - * @var array List of pages. + * @var array List of pages. */ public array $pages; @@ -21,7 +23,7 @@ public function __construct(array $rawPrediction) { $this->pages = []; foreach ($rawPrediction['pages'] as $pagePrediction) { - $this->pages[] = new OCRPage($pagePrediction); + $this->pages[] = new OcrPage($pagePrediction); } } diff --git a/src/V1/Parsing/Common/OCR/OCR.php b/src/V1/Parsing/Common/Ocr/Ocr.php similarity index 83% rename from src/V1/Parsing/Common/OCR/OCR.php rename to src/V1/Parsing/Common/Ocr/Ocr.php index afc4746a..c0b5bbfc 100644 --- a/src/V1/Parsing/Common/OCR/OCR.php +++ b/src/V1/Parsing/Common/Ocr/Ocr.php @@ -2,15 +2,17 @@ declare(strict_types=1); -namespace Mindee\V1\Parsing\Common\OCR; +namespace Mindee\V1\Parsing\Common\Ocr; + +use Stringable; use function array_key_exists; use function count; /** - * OCR extraction from the entire document. + * Ocr extraction from the entire document. */ -class OCR +class Ocr implements Stringable { /** * @var MVisionV1 Mindee Vision v1 results. @@ -33,10 +35,10 @@ public function __toString(): string } /** - * Finds all lines matching the given regex in the OCR data, indexed by their page. + * Finds all lines matching the given regex in the Ocr data, indexed by their page. * * @param string $regex The regular expression to match against. - * @return array> All lines that match the regex, indexed by their page. + * @return array> All lines that match the regex, indexed by their page. */ public function findLineByRegex(string $regex): array { diff --git a/src/V1/Parsing/Common/OCR/OCRLine.php b/src/V1/Parsing/Common/Ocr/OcrLine.php similarity index 63% rename from src/V1/Parsing/Common/OCR/OCRLine.php rename to src/V1/Parsing/Common/Ocr/OcrLine.php index 68480840..c86672da 100644 --- a/src/V1/Parsing/Common/OCR/OCRLine.php +++ b/src/V1/Parsing/Common/Ocr/OcrLine.php @@ -2,27 +2,21 @@ declare(strict_types=1); -namespace Mindee\V1\Parsing\Common\OCR; +namespace Mindee\V1\Parsing\Common\Ocr; + +use Stringable; use function count; /** * A list of words which are on the same line. */ -class OCRLine +class OcrLine implements Stringable { /** - * @var array Words in the line. - */ - private array $words; - - /** - * @param array $words Words to insert in the line. + * @param array $words Words to insert in the line. */ - public function __construct(array $words = []) - { - $this->words = $words; - } + public function __construct(private array $words = []) {} /** * Sort the words on the line from left to right. @@ -30,15 +24,15 @@ public function __construct(array $words = []) */ public function sortOnX(): void { - usort($this->words, "Mindee\\V1\\Parsing\\Common\\OCR\\OCRPage::getMinMaxX"); + usort($this->words, OcrPage::getMinMaxX(...)); } /** * Appends a word to the line. * - * @param OCRWord $word Word to add. + * @param OcrWord $word Word to add. */ - public function add(OCRWord $word): void + public function add(OcrWord $word): void { $this->words[] = $word; } diff --git a/src/V1/Parsing/Common/OCR/OCRPage.php b/src/V1/Parsing/Common/Ocr/OcrPage.php similarity index 70% rename from src/V1/Parsing/Common/OCR/OCRPage.php rename to src/V1/Parsing/Common/Ocr/OcrPage.php index 3cc1f80a..37a8478a 100644 --- a/src/V1/Parsing/Common/OCR/OCRPage.php +++ b/src/V1/Parsing/Common/Ocr/OcrPage.php @@ -2,33 +2,35 @@ declare(strict_types=1); -namespace Mindee\V1\Parsing\Common\OCR; +namespace Mindee\V1\Parsing\Common\Ocr; + +use Stringable; use function count; use function in_array; /** - * OCR extraction for a single page. + * Ocr extraction for a single page. */ -class OCRPage +class OcrPage implements Stringable { /** - * @var array List of all words. + * @var array List of all words. */ private array $allWords; /** - * @var array List of lines. + * @var array List of lines. */ private array $lines; /** * Checks whether the words are on the same line. * - * @param OCRWord $currentWord Reference word to compare. - * @param OCRWord $nextWord Next word to compare. + * @param OcrWord $currentWord Reference word to compare. + * @param OcrWord $nextWord Next word to compare. * @return boolean */ - private static function areWordsOnSameLine(OCRWord $currentWord, OCRWord $nextWord): bool + private static function areWordsOnSameLine(OcrWord $currentWord, OcrWord $nextWord): bool { $currentInNext = $nextWord->polygon->isPointInY($currentWord->polygon->getCentroid()); $nextInCurrent = $currentWord->polygon->isPointInY($nextWord->polygon->getCentroid()); @@ -38,40 +40,34 @@ private static function areWordsOnSameLine(OCRWord $currentWord, OCRWord $nextWo /** * Compares word positions on the X axis. Returns a sort-compliant result (0;-1;1). * - * @param OCRWord $word1 First word. - * @param OCRWord $word2 Second word. + * @param OcrWord $word1 First word. + * @param OcrWord $word2 Second word. * @return integer */ - public static function getMinMaxX(OCRWord $word1, OCRWord $word2): int + public static function getMinMaxX(OcrWord $word1, OcrWord $word2): int { $word1X = $word1->polygon->getMinMaxX()->getMin(); $word2X = $word2->polygon->getMinMaxX()->getMin(); - if ($word1X === $word2X) { - return 0; - } - return $word1X < $word2X ? -1 : 1; + return $word1X <=> $word2X; } /** * Compares word positions on the Y axis. Returns a sort-compliant result (0;-1;1). * - * @param OCRWord $word1 First word. - * @param OCRWord $word2 Second word. + * @param OcrWord $word1 First word. + * @param OcrWord $word2 Second word. * @return integer */ - public static function getMinMaxY(OCRWord $word1, OCRWord $word2): int + public static function getMinMaxY(OcrWord $word1, OcrWord $word2): int { $word1Y = $word1->polygon->getMinMaxY()->getMin(); $word2Y = $word2->polygon->getMinMaxY()->getMin(); - if ($word1Y === $word2Y) { - return 0; - } - return $word1Y < $word2Y ? -1 : 1; + return $word1Y <=> $word2Y; } /** * Puts all words on the page into an array of lines. - * @return array + * @return array */ private function toLines(): array { @@ -79,17 +75,17 @@ private function toLines(): array $indexes = []; $lines = []; foreach ($this->allWords as $_) { - $line = new OCRLine(); + $line = new OcrLine(); for ($idx = 0; $idx < count($this->allWords); $idx++) { $word = $this->allWords[$idx]; if (!in_array($idx, $indexes, true)) { if (null === $current) { $current = $word; $indexes[] = $idx; - $line = new OCRLine(); + $line = new OcrLine(); $line->add($word); } else { - if ($this->areWordsOnSameLine($current, $word)) { + if (self::areWordsOnSameLine($current, $word)) { $line->add($word); $indexes[] = $idx; } @@ -107,7 +103,7 @@ private function toLines(): array /** * Retrieves all lines on the page. - * @return array + * @return array */ public function getAllLines(): array { @@ -119,7 +115,7 @@ public function getAllLines(): array /** * Retrieves all words on the page. - * @return array + * @return array */ public function getAllWords(): array { @@ -133,9 +129,9 @@ public function __construct(array $rawPrediction) { $this->allWords = []; foreach ($rawPrediction['all_words'] as $wordPrediction) { - $this->allWords[] = new OCRWord($wordPrediction); + $this->allWords[] = new OcrWord($wordPrediction); } - usort($this->allWords, "self::getMinMaxY"); + usort($this->allWords, self::getMinMaxY(...)); } /** diff --git a/src/V1/Parsing/Common/OCR/OCRWord.php b/src/V1/Parsing/Common/Ocr/OcrWord.php similarity index 89% rename from src/V1/Parsing/Common/OCR/OCRWord.php rename to src/V1/Parsing/Common/Ocr/OcrWord.php index 62d8e634..622b4c2d 100644 --- a/src/V1/Parsing/Common/OCR/OCRWord.php +++ b/src/V1/Parsing/Common/Ocr/OcrWord.php @@ -2,14 +2,15 @@ declare(strict_types=1); -namespace Mindee\V1\Parsing\Common\OCR; +namespace Mindee\V1\Parsing\Common\Ocr; use Mindee\V1\Parsing\Standard\FieldPositionMixin; +use Stringable; /** * A single word. */ -class OCRWord +class OcrWord implements Stringable { use FieldPositionMixin; diff --git a/src/V1/Parsing/Common/Page.php b/src/V1/Parsing/Common/Page.php index 1fefe6e6..bdef85fc 100644 --- a/src/V1/Parsing/Common/Page.php +++ b/src/V1/Parsing/Common/Page.php @@ -8,6 +8,7 @@ use Mindee\Error\MindeeApiException; use Mindee\Error\MindeeUnsetException; use Mindee\V1\Parsing\Common\Extras\Extras; +use Stringable; use function array_key_exists; use function is_subclass_of; @@ -15,7 +16,7 @@ /** * Base Page object for predictions. */ -class Page +class Page implements Stringable { /** * @var integer ID of the current page. diff --git a/src/V1/Parsing/Common/Prediction.php b/src/V1/Parsing/Common/Prediction.php index 3608c13c..94d4c8a0 100644 --- a/src/V1/Parsing/Common/Prediction.php +++ b/src/V1/Parsing/Common/Prediction.php @@ -4,10 +4,12 @@ namespace Mindee\V1\Parsing\Common; +use Stringable; + /** * Base class for prediction responses. */ -abstract class Prediction +abstract class Prediction implements Stringable { /** * @return string String representation. diff --git a/src/V1/Parsing/Common/Product.php b/src/V1/Parsing/Common/Product.php index f5b9fa90..82edf9f5 100644 --- a/src/V1/Parsing/Common/Product.php +++ b/src/V1/Parsing/Common/Product.php @@ -4,10 +4,12 @@ namespace Mindee\V1\Parsing\Common; +use Stringable; + /** * Class for keeping track of a product's info. */ -class Product +class Product implements Stringable { /** * @var string Product's name. @@ -30,7 +32,7 @@ public function __construct(array $rawPrediction) /** * @return string String representation. */ - public function __toString() + public function __toString(): string { return "$this->name v$this->version"; } diff --git a/src/V1/Parsing/Generated/GeneratedListField.php b/src/V1/Parsing/Generated/GeneratedListField.php index dfba11bf..2ed9b6b0 100644 --- a/src/V1/Parsing/Generated/GeneratedListField.php +++ b/src/V1/Parsing/Generated/GeneratedListField.php @@ -5,6 +5,7 @@ namespace Mindee\V1\Parsing\Generated; use Mindee\V1\Parsing\Standard\StringField; +use Stringable; use function is_float; use function is_int; @@ -12,11 +13,8 @@ /** * A list of value or words for generated APIs. */ -class GeneratedListField +class GeneratedListField implements Stringable { - /** @var integer|null ID of the page the object was found on */ - public ?int $pageId; - /** @var array List of values */ public array $values = []; @@ -26,10 +24,8 @@ class GeneratedListField * @param list>> $rawPrediction Array containing the list elements. * @param integer|null $pageId ID of the page. */ - public function __construct(array $rawPrediction, ?int $pageId = null) + public function __construct(array $rawPrediction, public ?int $pageId = null) { - $this->pageId = $pageId; - foreach ($rawPrediction as $value) { if (isset($value['page_id']) && is_int($value['page_id'])) { $this->pageId = $value['page_id']; diff --git a/src/V1/Parsing/Generated/GeneratedObjectField.php b/src/V1/Parsing/Generated/GeneratedObjectField.php index 17f6ff9b..28f05842 100644 --- a/src/V1/Parsing/Generated/GeneratedObjectField.php +++ b/src/V1/Parsing/Generated/GeneratedObjectField.php @@ -7,6 +7,7 @@ use Mindee\Geometry\Polygon; use Mindee\V1\Parsing\Standard\BaseField; use Mindee\V1\Parsing\Standard\PositionField; +use Stringable; use function in_array; use function is_array; @@ -20,7 +21,7 @@ * @property PositionField|null $quadrangle * @property PositionField|null $rectangle */ -class GeneratedObjectField +class GeneratedObjectField implements Stringable { /** @var integer|null ID of the page the object was found on */ public ?int $pageId; diff --git a/src/V1/Parsing/Standard/BaseField.php b/src/V1/Parsing/Standard/BaseField.php index 467f844a..0118e142 100644 --- a/src/V1/Parsing/Standard/BaseField.php +++ b/src/V1/Parsing/Standard/BaseField.php @@ -5,6 +5,7 @@ namespace Mindee\V1\Parsing\Standard; use Mindee\Geometry\Polygon; +use Stringable; use function array_key_exists; @@ -12,7 +13,7 @@ * Base class for most fields. * @template T Generic typing for value type handling. */ -abstract class BaseField +abstract class BaseField implements Stringable { use FieldConfidenceMixin; @@ -20,10 +21,6 @@ abstract class BaseField * @var T|null Raw field value. */ public mixed $value; - /** - * @var boolean Whether the field was reconstructed from other fields. - */ - public bool $reconstructed; /** * @var integer|null The document page on which the information was found. */ @@ -38,7 +35,7 @@ abstract class BaseField public function __construct( array $rawPrediction, ?int $pageId = null, - bool $reconstructed = false, + public bool $reconstructed = false, string $valueKey = 'value' ) { if (!isset($pageId) && (array_key_exists('page_id', $rawPrediction) && isset($rawPrediction['page_id']))) { @@ -46,7 +43,6 @@ public function __construct( } else { $this->pageId = $pageId; } - $this->reconstructed = $reconstructed; if (array_key_exists($valueKey, $rawPrediction) && $rawPrediction[$valueKey] !== 'N/A') { $this->value = $rawPrediction[$valueKey]; $this->setConfidence($rawPrediction); diff --git a/src/V1/Parsing/Standard/Taxes.php b/src/V1/Parsing/Standard/Taxes.php index 60479542..496aceba 100644 --- a/src/V1/Parsing/Standard/Taxes.php +++ b/src/V1/Parsing/Standard/Taxes.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Parsing\Standard; use ArrayObject; +use Stringable; /** * List of tax lines information. * @extends ArrayObject */ -class Taxes extends ArrayObject +class Taxes extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. @@ -43,7 +44,7 @@ private static function lineSeparator(string $char): string /** * @return string String representation. */ - public function __toString() + public function __toString(): string { $outStr = "\n" . self::lineSeparator('-') . "\n"; $outStr .= " | Base | Code | Rate (%) | Amount |\n"; diff --git a/src/V1/Product/BillOfLading/BillOfLadingV1Carrier.php b/src/V1/Product/BillOfLading/BillOfLadingV1Carrier.php index c420113d..59e75647 100644 --- a/src/V1/Product/BillOfLading/BillOfLadingV1Carrier.php +++ b/src/V1/Product/BillOfLading/BillOfLadingV1Carrier.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The shipping company responsible for transporting the goods. */ -class BillOfLadingV1Carrier +class BillOfLadingV1Carrier implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -28,23 +29,18 @@ class BillOfLadingV1Carrier * @var string|null The Standard Carrier Alpha Code (SCAC) of the carrier. */ public ?string $scac; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); $this->name = $rawPrediction["name"] ?? null; $this->professionalNumber = $rawPrediction["professional_number"] ?? null; $this->scac = $rawPrediction["scac"] ?? null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/BillOfLading/BillOfLadingV1CarrierItem.php b/src/V1/Product/BillOfLading/BillOfLadingV1CarrierItem.php index 484a287a..2df1d83a 100644 --- a/src/V1/Product/BillOfLading/BillOfLadingV1CarrierItem.php +++ b/src/V1/Product/BillOfLading/BillOfLadingV1CarrierItem.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The goods being shipped. */ -class BillOfLadingV1CarrierItem +class BillOfLadingV1CarrierItem implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -40,16 +41,12 @@ class BillOfLadingV1CarrierItem * @var string|null The unit of measurement for weights. */ public ?string $weightUnit; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -62,7 +59,6 @@ public function __construct(array $rawPrediction, ?int $pageId) $this->quantity = isset($rawPrediction["quantity"]) ? (float) ($rawPrediction["quantity"]) : null; $this->weightUnit = $rawPrediction["weight_unit"] ?? null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/BillOfLading/BillOfLadingV1CarrierItems.php b/src/V1/Product/BillOfLading/BillOfLadingV1CarrierItems.php index 25b1d410..73d953af 100644 --- a/src/V1/Product/BillOfLading/BillOfLadingV1CarrierItems.php +++ b/src/V1/Product/BillOfLading/BillOfLadingV1CarrierItems.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\BillOfLading; use ArrayObject; +use Stringable; /** * The goods being shipped. * @extends ArrayObject */ -class BillOfLadingV1CarrierItems extends ArrayObject +class BillOfLadingV1CarrierItems extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/BillOfLading/BillOfLadingV1Consignee.php b/src/V1/Product/BillOfLading/BillOfLadingV1Consignee.php index e3e1c70b..be1fa8ba 100644 --- a/src/V1/Product/BillOfLading/BillOfLadingV1Consignee.php +++ b/src/V1/Product/BillOfLading/BillOfLadingV1Consignee.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The party to whom the goods are being shipped. */ -class BillOfLadingV1Consignee +class BillOfLadingV1Consignee implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -32,16 +33,12 @@ class BillOfLadingV1Consignee * @var string|null The phone number of the consignee. */ public ?string $phone; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -49,7 +46,6 @@ public function __construct(array $rawPrediction, ?int $pageId) $this->email = $rawPrediction["email"] ?? null; $this->name = $rawPrediction["name"] ?? null; $this->phone = $rawPrediction["phone"] ?? null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/BillOfLading/BillOfLadingV1NotifyParty.php b/src/V1/Product/BillOfLading/BillOfLadingV1NotifyParty.php index d1ae412d..d27b5bf4 100644 --- a/src/V1/Product/BillOfLading/BillOfLadingV1NotifyParty.php +++ b/src/V1/Product/BillOfLading/BillOfLadingV1NotifyParty.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The party to be notified of the arrival of the goods. */ -class BillOfLadingV1NotifyParty +class BillOfLadingV1NotifyParty implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -32,16 +33,12 @@ class BillOfLadingV1NotifyParty * @var string|null The phone number of the notify party. */ public ?string $phone; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -49,7 +46,6 @@ public function __construct(array $rawPrediction, ?int $pageId) $this->email = $rawPrediction["email"] ?? null; $this->name = $rawPrediction["name"] ?? null; $this->phone = $rawPrediction["phone"] ?? null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/BillOfLading/BillOfLadingV1Shipper.php b/src/V1/Product/BillOfLading/BillOfLadingV1Shipper.php index 9b0f7b0b..a893209b 100644 --- a/src/V1/Product/BillOfLading/BillOfLadingV1Shipper.php +++ b/src/V1/Product/BillOfLading/BillOfLadingV1Shipper.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The party responsible for shipping the goods. */ -class BillOfLadingV1Shipper +class BillOfLadingV1Shipper implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -32,16 +33,12 @@ class BillOfLadingV1Shipper * @var string|null The phone number of the shipper. */ public ?string $phone; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -49,7 +46,6 @@ public function __construct(array $rawPrediction, ?int $pageId) $this->email = $rawPrediction["email"] ?? null; $this->name = $rawPrediction["name"] ?? null; $this->phone = $rawPrediction["phone"] ?? null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/FinancialDocument/FinancialDocumentV1LineItem.php b/src/V1/Product/FinancialDocument/FinancialDocumentV1LineItem.php index 08822185..665934ec 100644 --- a/src/V1/Product/FinancialDocument/FinancialDocumentV1LineItem.php +++ b/src/V1/Product/FinancialDocument/FinancialDocumentV1LineItem.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * List of line item present on the document. */ -class FinancialDocumentV1LineItem +class FinancialDocumentV1LineItem implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -48,16 +49,12 @@ class FinancialDocumentV1LineItem * @var float|null The item unit price. */ public ?float $unitPrice; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -74,7 +71,6 @@ public function __construct(array $rawPrediction, ?int $pageId) $this->unitMeasure = $rawPrediction["unit_measure"] ?? null; $this->unitPrice = isset($rawPrediction["unit_price"]) ? (float) ($rawPrediction["unit_price"]) : null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/FinancialDocument/FinancialDocumentV1LineItems.php b/src/V1/Product/FinancialDocument/FinancialDocumentV1LineItems.php index ef29c697..cffcc2a2 100644 --- a/src/V1/Product/FinancialDocument/FinancialDocumentV1LineItems.php +++ b/src/V1/Product/FinancialDocument/FinancialDocumentV1LineItems.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\FinancialDocument; use ArrayObject; +use Stringable; /** * List of line item present on the document. * @extends ArrayObject */ -class FinancialDocumentV1LineItems extends ArrayObject +class FinancialDocumentV1LineItems extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/Fr/BankAccountDetails/BankAccountDetailsV2Bban.php b/src/V1/Product/Fr/BankAccountDetails/BankAccountDetailsV2Bban.php index 3b54ac2a..045676a7 100644 --- a/src/V1/Product/Fr/BankAccountDetails/BankAccountDetailsV2Bban.php +++ b/src/V1/Product/Fr/BankAccountDetails/BankAccountDetailsV2Bban.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * Full extraction of BBAN, including: branch code, bank code, account and key. */ -class BankAccountDetailsV2Bban +class BankAccountDetailsV2Bban implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -32,16 +33,12 @@ class BankAccountDetailsV2Bban * @var string|null The BBAN Account number outputted as a string. */ public ?string $bbanNumber; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -49,7 +46,6 @@ public function __construct(array $rawPrediction, ?int $pageId) $this->bbanBranchCode = $rawPrediction["bban_branch_code"] ?? null; $this->bbanKey = $rawPrediction["bban_key"] ?? null; $this->bbanNumber = $rawPrediction["bban_number"] ?? null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergyConsumer.php b/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergyConsumer.php index ea53b24b..7d4edd8b 100644 --- a/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergyConsumer.php +++ b/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergyConsumer.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The entity that consumes the energy. */ -class EnergyBillV1EnergyConsumer +class EnergyBillV1EnergyConsumer implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -24,22 +25,17 @@ class EnergyBillV1EnergyConsumer * @var string|null The name of the energy consumer. */ public ?string $name; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); $this->address = $rawPrediction["address"] ?? null; $this->name = $rawPrediction["name"] ?? null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergySupplier.php b/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergySupplier.php index cd0c1df5..fbd394a3 100644 --- a/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergySupplier.php +++ b/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergySupplier.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The company that supplies the energy. */ -class EnergyBillV1EnergySupplier +class EnergyBillV1EnergySupplier implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -24,22 +25,17 @@ class EnergyBillV1EnergySupplier * @var string|null The name of the energy supplier. */ public ?string $name; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); $this->address = $rawPrediction["address"] ?? null; $this->name = $rawPrediction["name"] ?? null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergyUsage.php b/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergyUsage.php index d0d6a1c1..8587380c 100644 --- a/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergyUsage.php +++ b/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergyUsage.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * Details of energy consumption. */ -class EnergyBillV1EnergyUsage +class EnergyBillV1EnergyUsage implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -48,16 +49,12 @@ class EnergyBillV1EnergyUsage * @var float|null The price per unit of energy consumed. */ public ?float $unitPrice; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -66,7 +63,6 @@ public function __construct(array $rawPrediction, ?int $pageId) $this->description = $rawPrediction["description"] ?? null; $this->endDate = $rawPrediction["end_date"] ?? null; $this->startDate = $rawPrediction["start_date"] ?? null; - $this->pageId = $pageId; $this->taxRate = isset($rawPrediction["tax_rate"]) ? (float) ($rawPrediction["tax_rate"]) : null; $this->total = isset($rawPrediction["total"]) diff --git a/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergyUsages.php b/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergyUsages.php index 889ffbd1..9dc7dbfe 100644 --- a/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergyUsages.php +++ b/src/V1/Product/Fr/EnergyBill/EnergyBillV1EnergyUsages.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\Fr\EnergyBill; use ArrayObject; +use Stringable; /** * Details of energy consumption. * @extends ArrayObject */ -class EnergyBillV1EnergyUsages extends ArrayObject +class EnergyBillV1EnergyUsages extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/Fr/EnergyBill/EnergyBillV1MeterDetail.php b/src/V1/Product/Fr/EnergyBill/EnergyBillV1MeterDetail.php index 2946189f..00dd1112 100644 --- a/src/V1/Product/Fr/EnergyBill/EnergyBillV1MeterDetail.php +++ b/src/V1/Product/Fr/EnergyBill/EnergyBillV1MeterDetail.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * Information about the energy meter. */ -class EnergyBillV1MeterDetail +class EnergyBillV1MeterDetail implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -28,23 +29,18 @@ class EnergyBillV1MeterDetail * @var string|null The unit of power for energy consumption. */ public ?string $unit; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); $this->meterNumber = $rawPrediction["meter_number"] ?? null; $this->meterType = $rawPrediction["meter_type"] ?? null; $this->unit = $rawPrediction["unit"] ?? null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/Fr/EnergyBill/EnergyBillV1Subscription.php b/src/V1/Product/Fr/EnergyBill/EnergyBillV1Subscription.php index 9ce540ba..aa106d59 100644 --- a/src/V1/Product/Fr/EnergyBill/EnergyBillV1Subscription.php +++ b/src/V1/Product/Fr/EnergyBill/EnergyBillV1Subscription.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The subscription details fee for the energy service. */ -class EnergyBillV1Subscription +class EnergyBillV1Subscription implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -40,16 +41,12 @@ class EnergyBillV1Subscription * @var float|null The price per unit of subscription. */ public ?float $unitPrice; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -62,7 +59,6 @@ public function __construct(array $rawPrediction, ?int $pageId) ? (float) ($rawPrediction["total"]) : null; $this->unitPrice = isset($rawPrediction["unit_price"]) ? (float) ($rawPrediction["unit_price"]) : null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/Fr/EnergyBill/EnergyBillV1Subscriptions.php b/src/V1/Product/Fr/EnergyBill/EnergyBillV1Subscriptions.php index f9500b5e..040ca44e 100644 --- a/src/V1/Product/Fr/EnergyBill/EnergyBillV1Subscriptions.php +++ b/src/V1/Product/Fr/EnergyBill/EnergyBillV1Subscriptions.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\Fr\EnergyBill; use ArrayObject; +use Stringable; /** * The subscription details fee for the energy service. * @extends ArrayObject */ -class EnergyBillV1Subscriptions extends ArrayObject +class EnergyBillV1Subscriptions extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/Fr/EnergyBill/EnergyBillV1TaxesAndContribution.php b/src/V1/Product/Fr/EnergyBill/EnergyBillV1TaxesAndContribution.php index 9a3c0daf..b7119cbe 100644 --- a/src/V1/Product/Fr/EnergyBill/EnergyBillV1TaxesAndContribution.php +++ b/src/V1/Product/Fr/EnergyBill/EnergyBillV1TaxesAndContribution.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * Details of Taxes and Contributions. */ -class EnergyBillV1TaxesAndContribution +class EnergyBillV1TaxesAndContribution implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -40,23 +41,18 @@ class EnergyBillV1TaxesAndContribution * @var float|null The price per unit of Taxes and Contributions. */ public ?float $unitPrice; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); $this->description = $rawPrediction["description"] ?? null; $this->endDate = $rawPrediction["end_date"] ?? null; $this->startDate = $rawPrediction["start_date"] ?? null; - $this->pageId = $pageId; $this->taxRate = isset($rawPrediction["tax_rate"]) ? (float) ($rawPrediction["tax_rate"]) : null; $this->total = isset($rawPrediction["total"]) diff --git a/src/V1/Product/Fr/EnergyBill/EnergyBillV1TaxesAndContributions.php b/src/V1/Product/Fr/EnergyBill/EnergyBillV1TaxesAndContributions.php index 207029ed..4604115a 100644 --- a/src/V1/Product/Fr/EnergyBill/EnergyBillV1TaxesAndContributions.php +++ b/src/V1/Product/Fr/EnergyBill/EnergyBillV1TaxesAndContributions.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\Fr\EnergyBill; use ArrayObject; +use Stringable; /** * Details of Taxes and Contributions. * @extends ArrayObject */ -class EnergyBillV1TaxesAndContributions extends ArrayObject +class EnergyBillV1TaxesAndContributions extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/Fr/Payslip/PayslipV3BankAccountDetail.php b/src/V1/Product/Fr/Payslip/PayslipV3BankAccountDetail.php index 60abe46b..ead83953 100644 --- a/src/V1/Product/Fr/Payslip/PayslipV3BankAccountDetail.php +++ b/src/V1/Product/Fr/Payslip/PayslipV3BankAccountDetail.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * Information about the employee's bank account. */ -class PayslipV3BankAccountDetail +class PayslipV3BankAccountDetail implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -28,23 +29,18 @@ class PayslipV3BankAccountDetail * @var string|null The SWIFT code of the bank. */ public ?string $swift; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); $this->bankName = $rawPrediction["bank_name"] ?? null; $this->iban = $rawPrediction["iban"] ?? null; $this->swift = $rawPrediction["swift"] ?? null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/Fr/Payslip/PayslipV3Employee.php b/src/V1/Product/Fr/Payslip/PayslipV3Employee.php index cf1a2059..2cc9ae3b 100644 --- a/src/V1/Product/Fr/Payslip/PayslipV3Employee.php +++ b/src/V1/Product/Fr/Payslip/PayslipV3Employee.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * Information about the employee. */ -class PayslipV3Employee +class PayslipV3Employee implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -44,16 +45,12 @@ class PayslipV3Employee * @var string|null The social security number of the employee. */ public ?string $socialSecurityNumber; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -61,7 +58,6 @@ public function __construct(array $rawPrediction, ?int $pageId) $this->dateOfBirth = $rawPrediction["date_of_birth"] ?? null; $this->firstName = $rawPrediction["first_name"] ?? null; $this->lastName = $rawPrediction["last_name"] ?? null; - $this->pageId = $pageId; $this->phoneNumber = $rawPrediction["phone_number"] ?? null; $this->registrationNumber = $rawPrediction["registration_number"] ?? null; $this->socialSecurityNumber = $rawPrediction["social_security_number"] ?? null; diff --git a/src/V1/Product/Fr/Payslip/PayslipV3Employer.php b/src/V1/Product/Fr/Payslip/PayslipV3Employer.php index 81fbed17..9b34639e 100644 --- a/src/V1/Product/Fr/Payslip/PayslipV3Employer.php +++ b/src/V1/Product/Fr/Payslip/PayslipV3Employer.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * Information about the employer. */ -class PayslipV3Employer +class PayslipV3Employer implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -44,16 +45,12 @@ class PayslipV3Employer * @var string|null The URSSAF number of the employer. */ public ?string $urssafNumber; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -64,7 +61,6 @@ public function __construct(array $rawPrediction, ?int $pageId) $this->name = $rawPrediction["name"] ?? null; $this->phoneNumber = $rawPrediction["phone_number"] ?? null; $this->urssafNumber = $rawPrediction["urssaf_number"] ?? null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/Fr/Payslip/PayslipV3Employment.php b/src/V1/Product/Fr/Payslip/PayslipV3Employment.php index 7dd5ce1d..27390d5f 100644 --- a/src/V1/Product/Fr/Payslip/PayslipV3Employment.php +++ b/src/V1/Product/Fr/Payslip/PayslipV3Employment.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * Information about the employment. */ -class PayslipV3Employment +class PayslipV3Employment implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -44,16 +45,12 @@ class PayslipV3Employment * @var string|null The start date of the employment. */ public ?string $startDate; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -64,7 +61,6 @@ public function __construct(array $rawPrediction, ?int $pageId) $this->positionLevel = $rawPrediction["position_level"] ?? null; $this->seniorityDate = $rawPrediction["seniority_date"] ?? null; $this->startDate = $rawPrediction["start_date"] ?? null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/Fr/Payslip/PayslipV3PaidTimeOff.php b/src/V1/Product/Fr/Payslip/PayslipV3PaidTimeOff.php index 364a9043..fa691052 100644 --- a/src/V1/Product/Fr/Payslip/PayslipV3PaidTimeOff.php +++ b/src/V1/Product/Fr/Payslip/PayslipV3PaidTimeOff.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * Information about paid time off. */ -class PayslipV3PaidTimeOff +class PayslipV3PaidTimeOff implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -36,16 +37,12 @@ class PayslipV3PaidTimeOff * @var float|null The amount of paid time off used in the period. */ public ?float $used; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -57,7 +54,6 @@ public function __construct(array $rawPrediction, ?int $pageId) ? (float) ($rawPrediction["remaining"]) : null; $this->used = isset($rawPrediction["used"]) ? (float) ($rawPrediction["used"]) : null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/Fr/Payslip/PayslipV3PaidTimeOffs.php b/src/V1/Product/Fr/Payslip/PayslipV3PaidTimeOffs.php index a7bbbe48..8fc8dc9c 100644 --- a/src/V1/Product/Fr/Payslip/PayslipV3PaidTimeOffs.php +++ b/src/V1/Product/Fr/Payslip/PayslipV3PaidTimeOffs.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\Fr\Payslip; use ArrayObject; +use Stringable; /** * Information about paid time off. * @extends ArrayObject */ -class PayslipV3PaidTimeOffs extends ArrayObject +class PayslipV3PaidTimeOffs extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/Fr/Payslip/PayslipV3PayDetail.php b/src/V1/Product/Fr/Payslip/PayslipV3PayDetail.php index 293191a1..795781da 100644 --- a/src/V1/Product/Fr/Payslip/PayslipV3PayDetail.php +++ b/src/V1/Product/Fr/Payslip/PayslipV3PayDetail.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * Detailed information about the pay. */ -class PayslipV3PayDetail +class PayslipV3PayDetail implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -56,16 +57,12 @@ class PayslipV3PayDetail * @var float|null The total taxes and deductions of the employee. */ public ?float $totalTaxesAndDeductions; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -89,7 +86,6 @@ public function __construct(array $rawPrediction, ?int $pageId) ? (float) ($rawPrediction["total_cost_employer"]) : null; $this->totalTaxesAndDeductions = isset($rawPrediction["total_taxes_and_deductions"]) ? (float) ($rawPrediction["total_taxes_and_deductions"]) : null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/Fr/Payslip/PayslipV3PayPeriod.php b/src/V1/Product/Fr/Payslip/PayslipV3PayPeriod.php index 5b498b84..a3550b72 100644 --- a/src/V1/Product/Fr/Payslip/PayslipV3PayPeriod.php +++ b/src/V1/Product/Fr/Payslip/PayslipV3PayPeriod.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * Information about the pay period. */ -class PayslipV3PayPeriod +class PayslipV3PayPeriod implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -36,16 +37,12 @@ class PayslipV3PayPeriod * @var string|null The year of the pay period. */ public ?string $year; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -54,7 +51,6 @@ public function __construct(array $rawPrediction, ?int $pageId) $this->paymentDate = $rawPrediction["payment_date"] ?? null; $this->startDate = $rawPrediction["start_date"] ?? null; $this->year = $rawPrediction["year"] ?? null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/Fr/Payslip/PayslipV3SalaryDetail.php b/src/V1/Product/Fr/Payslip/PayslipV3SalaryDetail.php index 06d1bc95..8705c39d 100644 --- a/src/V1/Product/Fr/Payslip/PayslipV3SalaryDetail.php +++ b/src/V1/Product/Fr/Payslip/PayslipV3SalaryDetail.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * Detailed information about the earnings. */ -class PayslipV3SalaryDetail +class PayslipV3SalaryDetail implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -36,16 +37,12 @@ class PayslipV3SalaryDetail * @var float|null The rate of the earning. */ public ?float $rate; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -58,7 +55,6 @@ public function __construct(array $rawPrediction, ?int $pageId) ? (float) ($rawPrediction["number"]) : null; $this->rate = isset($rawPrediction["rate"]) ? (float) ($rawPrediction["rate"]) : null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/Fr/Payslip/PayslipV3SalaryDetails.php b/src/V1/Product/Fr/Payslip/PayslipV3SalaryDetails.php index e36b6814..833a56da 100644 --- a/src/V1/Product/Fr/Payslip/PayslipV3SalaryDetails.php +++ b/src/V1/Product/Fr/Payslip/PayslipV3SalaryDetails.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\Fr\Payslip; use ArrayObject; +use Stringable; /** * Detailed information about the earnings. * @extends ArrayObject */ -class PayslipV3SalaryDetails extends ArrayObject +class PayslipV3SalaryDetails extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/Invoice/InvoiceV4LineItem.php b/src/V1/Product/Invoice/InvoiceV4LineItem.php index b2e0be1a..29cae4ca 100644 --- a/src/V1/Product/Invoice/InvoiceV4LineItem.php +++ b/src/V1/Product/Invoice/InvoiceV4LineItem.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * List of all the line items present on the invoice. */ -class InvoiceV4LineItem +class InvoiceV4LineItem implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -48,16 +49,12 @@ class InvoiceV4LineItem * @var float|null The item unit price. */ public ?float $unitPrice; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -74,7 +71,6 @@ public function __construct(array $rawPrediction, ?int $pageId) $this->unitMeasure = $rawPrediction["unit_measure"] ?? null; $this->unitPrice = isset($rawPrediction["unit_price"]) ? (float) ($rawPrediction["unit_price"]) : null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/Invoice/InvoiceV4LineItems.php b/src/V1/Product/Invoice/InvoiceV4LineItems.php index 2fbbde2c..fdc203c7 100644 --- a/src/V1/Product/Invoice/InvoiceV4LineItems.php +++ b/src/V1/Product/Invoice/InvoiceV4LineItems.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\Invoice; use ArrayObject; +use Stringable; /** * List of all the line items present on the invoice. * @extends ArrayObject */ -class InvoiceV4LineItems extends ArrayObject +class InvoiceV4LineItems extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/InvoiceSplitter/InvoiceSplitterV1InvoicePageGroup.php b/src/V1/Product/InvoiceSplitter/InvoiceSplitterV1InvoicePageGroup.php index 4ff4da1f..acbcd207 100644 --- a/src/V1/Product/InvoiceSplitter/InvoiceSplitterV1InvoicePageGroup.php +++ b/src/V1/Product/InvoiceSplitter/InvoiceSplitterV1InvoicePageGroup.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * List of page groups. Each group represents a single invoice within a multi-invoice document. */ -class InvoiceSplitterV1InvoicePageGroup +class InvoiceSplitterV1InvoicePageGroup implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -20,21 +21,16 @@ class InvoiceSplitterV1InvoicePageGroup * @var int[] List of page indexes that belong to the same invoice (group). */ public array $pageIndexes; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); $this->pageIndexes = $rawPrediction["page_indexes"] ?? []; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/InvoiceSplitter/InvoiceSplitterV1InvoicePageGroups.php b/src/V1/Product/InvoiceSplitter/InvoiceSplitterV1InvoicePageGroups.php index 2b94383e..55cf7711 100644 --- a/src/V1/Product/InvoiceSplitter/InvoiceSplitterV1InvoicePageGroups.php +++ b/src/V1/Product/InvoiceSplitter/InvoiceSplitterV1InvoicePageGroups.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\InvoiceSplitter; use ArrayObject; +use Stringable; /** * List of page groups. Each group represents a single invoice within a multi-invoice document. * @extends ArrayObject */ -class InvoiceSplitterV1InvoicePageGroups extends ArrayObject +class InvoiceSplitterV1InvoicePageGroups extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1AddedSugar.php b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1AddedSugar.php index be259d4a..45523691 100644 --- a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1AddedSugar.php +++ b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1AddedSugar.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The amount of added sugars in the product. */ -class NutritionFactsLabelV1AddedSugar +class NutritionFactsLabelV1AddedSugar implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -28,16 +29,12 @@ class NutritionFactsLabelV1AddedSugar * @var float|null The amount of added sugars per serving of the product. */ public ?float $perServing; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -47,7 +44,6 @@ public function __construct(array $rawPrediction, ?int $pageId) ? (float) ($rawPrediction["per_100g"]) : null; $this->perServing = isset($rawPrediction["per_serving"]) ? (float) ($rawPrediction["per_serving"]) : null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Calorie.php b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Calorie.php index 38c0f12a..546a123f 100644 --- a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Calorie.php +++ b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Calorie.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The amount of calories in the product. */ -class NutritionFactsLabelV1Calorie +class NutritionFactsLabelV1Calorie implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -28,16 +29,12 @@ class NutritionFactsLabelV1Calorie * @var float|null The amount of calories per serving of the product. */ public ?float $perServing; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); @@ -47,7 +44,6 @@ public function __construct(array $rawPrediction, ?int $pageId) ? (float) ($rawPrediction["per_100g"]) : null; $this->perServing = isset($rawPrediction["per_serving"]) ? (float) ($rawPrediction["per_serving"]) : null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Cholesterol.php b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Cholesterol.php index 001b1eaa..6fba6887 100644 --- a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Cholesterol.php +++ b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Cholesterol.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The amount of cholesterol in the product. */ -class NutritionFactsLabelV1Cholesterol +class NutritionFactsLabelV1Cholesterol implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -28,20 +29,15 @@ class NutritionFactsLabelV1Cholesterol * @var float|null The amount of cholesterol per serving of the product. */ public ?float $perServing; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->dailyValue = isset($rawPrediction["daily_value"]) ? (float) ($rawPrediction["daily_value"]) : null; $this->per100G = isset($rawPrediction["per_100g"]) diff --git a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1DietaryFiber.php b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1DietaryFiber.php index a43d850c..b86ca06f 100644 --- a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1DietaryFiber.php +++ b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1DietaryFiber.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The amount of dietary fiber in the product. */ -class NutritionFactsLabelV1DietaryFiber +class NutritionFactsLabelV1DietaryFiber implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -28,20 +29,15 @@ class NutritionFactsLabelV1DietaryFiber * @var float|null The amount of dietary fiber per serving of the product. */ public ?float $perServing; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->dailyValue = isset($rawPrediction["daily_value"]) ? (float) ($rawPrediction["daily_value"]) : null; $this->per100G = isset($rawPrediction["per_100g"]) diff --git a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Nutrient.php b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Nutrient.php index 12ce0a9b..8d85aa46 100644 --- a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Nutrient.php +++ b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Nutrient.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The amount of nutrients in the product. */ -class NutritionFactsLabelV1Nutrient +class NutritionFactsLabelV1Nutrient implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -36,20 +37,15 @@ class NutritionFactsLabelV1Nutrient * @var string|null The unit of measurement for the amount of nutrients. */ public ?string $unit; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->dailyValue = isset($rawPrediction["daily_value"]) ? (float) ($rawPrediction["daily_value"]) : null; $this->name = $rawPrediction["name"] ?? null; diff --git a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Nutrients.php b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Nutrients.php index 52560227..82ed28cd 100644 --- a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Nutrients.php +++ b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Nutrients.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\NutritionFactsLabel; use ArrayObject; +use Stringable; /** * The amount of nutrients in the product. * @extends ArrayObject */ -class NutritionFactsLabelV1Nutrients extends ArrayObject +class NutritionFactsLabelV1Nutrients extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Protein.php b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Protein.php index ee911866..88e7122e 100644 --- a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Protein.php +++ b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Protein.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The amount of protein in the product. */ -class NutritionFactsLabelV1Protein +class NutritionFactsLabelV1Protein implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -28,20 +29,15 @@ class NutritionFactsLabelV1Protein * @var float|null The amount of protein per serving of the product. */ public ?float $perServing; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->dailyValue = isset($rawPrediction["daily_value"]) ? (float) ($rawPrediction["daily_value"]) : null; $this->per100G = isset($rawPrediction["per_100g"]) diff --git a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1SaturatedFat.php b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1SaturatedFat.php index f35b9369..7233bb43 100644 --- a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1SaturatedFat.php +++ b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1SaturatedFat.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The amount of saturated fat in the product. */ -class NutritionFactsLabelV1SaturatedFat +class NutritionFactsLabelV1SaturatedFat implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -28,20 +29,15 @@ class NutritionFactsLabelV1SaturatedFat * @var float|null The amount of saturated fat per serving of the product. */ public ?float $perServing; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->dailyValue = isset($rawPrediction["daily_value"]) ? (float) ($rawPrediction["daily_value"]) : null; $this->per100G = isset($rawPrediction["per_100g"]) diff --git a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1ServingSize.php b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1ServingSize.php index 430b015a..84bc8ece 100644 --- a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1ServingSize.php +++ b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1ServingSize.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The size of a single serving of the product. */ -class NutritionFactsLabelV1ServingSize +class NutritionFactsLabelV1ServingSize implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -24,23 +25,18 @@ class NutritionFactsLabelV1ServingSize * @var string|null The unit for the amount of a single serving. */ public ?string $unit; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); $this->amount = isset($rawPrediction["amount"]) ? (float) ($rawPrediction["amount"]) : null; $this->unit = $rawPrediction["unit"] ?? null; - $this->pageId = $pageId; } /** diff --git a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Sodium.php b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Sodium.php index 95835782..7fffe0ef 100644 --- a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Sodium.php +++ b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1Sodium.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The amount of sodium in the product. */ -class NutritionFactsLabelV1Sodium +class NutritionFactsLabelV1Sodium implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -32,20 +33,15 @@ class NutritionFactsLabelV1Sodium * @var string|null The unit of measurement for the amount of sodium. */ public ?string $unit; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->dailyValue = isset($rawPrediction["daily_value"]) ? (float) ($rawPrediction["daily_value"]) : null; $this->per100G = isset($rawPrediction["per_100g"]) diff --git a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TotalCarbohydrate.php b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TotalCarbohydrate.php index c08cdbeb..281b2967 100644 --- a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TotalCarbohydrate.php +++ b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TotalCarbohydrate.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The total amount of carbohydrates in the product. */ -class NutritionFactsLabelV1TotalCarbohydrate +class NutritionFactsLabelV1TotalCarbohydrate implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -28,20 +29,15 @@ class NutritionFactsLabelV1TotalCarbohydrate * @var float|null The amount of total carbohydrates per serving of the product. */ public ?float $perServing; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->dailyValue = isset($rawPrediction["daily_value"]) ? (float) ($rawPrediction["daily_value"]) : null; $this->per100G = isset($rawPrediction["per_100g"]) diff --git a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TotalFat.php b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TotalFat.php index 15e37df0..5407464e 100644 --- a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TotalFat.php +++ b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TotalFat.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The total amount of fat in the product. */ -class NutritionFactsLabelV1TotalFat +class NutritionFactsLabelV1TotalFat implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -28,20 +29,15 @@ class NutritionFactsLabelV1TotalFat * @var float|null The amount of total fat per serving of the product. */ public ?float $perServing; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->dailyValue = isset($rawPrediction["daily_value"]) ? (float) ($rawPrediction["daily_value"]) : null; $this->per100G = isset($rawPrediction["per_100g"]) diff --git a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TotalSugar.php b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TotalSugar.php index e0d18e01..0ee3b05a 100644 --- a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TotalSugar.php +++ b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TotalSugar.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The total amount of sugars in the product. */ -class NutritionFactsLabelV1TotalSugar +class NutritionFactsLabelV1TotalSugar implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -28,20 +29,15 @@ class NutritionFactsLabelV1TotalSugar * @var float|null The amount of total sugars per serving of the product. */ public ?float $perServing; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->dailyValue = isset($rawPrediction["daily_value"]) ? (float) ($rawPrediction["daily_value"]) : null; $this->per100G = isset($rawPrediction["per_100g"]) diff --git a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TransFat.php b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TransFat.php index dbdfbcd0..981dc5d8 100644 --- a/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TransFat.php +++ b/src/V1/Product/NutritionFactsLabel/NutritionFactsLabelV1TransFat.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The amount of trans fat in the product. */ -class NutritionFactsLabelV1TransFat +class NutritionFactsLabelV1TransFat implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -28,20 +29,15 @@ class NutritionFactsLabelV1TransFat * @var float|null The amount of trans fat per serving of the product. */ public ?float $perServing; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->dailyValue = isset($rawPrediction["daily_value"]) ? (float) ($rawPrediction["daily_value"]) : null; $this->per100G = isset($rawPrediction["per_100g"]) diff --git a/src/V1/Product/Receipt/ReceiptV5LineItem.php b/src/V1/Product/Receipt/ReceiptV5LineItem.php index fbd7e649..0f50da48 100644 --- a/src/V1/Product/Receipt/ReceiptV5LineItem.php +++ b/src/V1/Product/Receipt/ReceiptV5LineItem.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * List of all line items on the receipt. */ -class ReceiptV5LineItem +class ReceiptV5LineItem implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -32,20 +33,15 @@ class ReceiptV5LineItem * @var float|null The item unit price. */ public ?float $unitPrice; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->description = $rawPrediction["description"] ?? null; $this->quantity = isset($rawPrediction["quantity"]) ? (float) ($rawPrediction["quantity"]) : null; diff --git a/src/V1/Product/Receipt/ReceiptV5LineItems.php b/src/V1/Product/Receipt/ReceiptV5LineItems.php index cfc4ceb9..40171070 100644 --- a/src/V1/Product/Receipt/ReceiptV5LineItems.php +++ b/src/V1/Product/Receipt/ReceiptV5LineItems.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\Receipt; use ArrayObject; +use Stringable; /** * List of all line items on the receipt. * @extends ArrayObject */ -class ReceiptV5LineItems extends ArrayObject +class ReceiptV5LineItems extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/Resume/ResumeV1Certificate.php b/src/V1/Product/Resume/ResumeV1Certificate.php index 455398e5..deeeea2c 100644 --- a/src/V1/Product/Resume/ResumeV1Certificate.php +++ b/src/V1/Product/Resume/ResumeV1Certificate.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The list of certificates obtained by the candidate. */ -class ResumeV1Certificate +class ResumeV1Certificate implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -32,20 +33,15 @@ class ResumeV1Certificate * @var string|null The year when a certificate was issued or received. */ public ?string $year; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->grade = $rawPrediction["grade"] ?? null; $this->name = $rawPrediction["name"] ?? null; $this->provider = $rawPrediction["provider"] ?? null; diff --git a/src/V1/Product/Resume/ResumeV1Certificates.php b/src/V1/Product/Resume/ResumeV1Certificates.php index ca799c88..c109db53 100644 --- a/src/V1/Product/Resume/ResumeV1Certificates.php +++ b/src/V1/Product/Resume/ResumeV1Certificates.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\Resume; use ArrayObject; +use Stringable; /** * The list of certificates obtained by the candidate. * @extends ArrayObject */ -class ResumeV1Certificates extends ArrayObject +class ResumeV1Certificates extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/Resume/ResumeV1Education.php b/src/V1/Product/Resume/ResumeV1Education.php index 3b87ff07..39e3ecc6 100644 --- a/src/V1/Product/Resume/ResumeV1Education.php +++ b/src/V1/Product/Resume/ResumeV1Education.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The list of the candidate's educational background. */ -class ResumeV1Education +class ResumeV1Education implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -44,20 +45,15 @@ class ResumeV1Education * @var string|null The year when the education program or course began. */ public ?string $startYear; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->degreeDomain = $rawPrediction["degree_domain"] ?? null; $this->degreeType = $rawPrediction["degree_type"] ?? null; $this->endMonth = $rawPrediction["end_month"] ?? null; diff --git a/src/V1/Product/Resume/ResumeV1Educations.php b/src/V1/Product/Resume/ResumeV1Educations.php index b4306901..a2635633 100644 --- a/src/V1/Product/Resume/ResumeV1Educations.php +++ b/src/V1/Product/Resume/ResumeV1Educations.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\Resume; use ArrayObject; +use Stringable; /** * The list of the candidate's educational background. * @extends ArrayObject */ -class ResumeV1Educations extends ArrayObject +class ResumeV1Educations extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/Resume/ResumeV1Language.php b/src/V1/Product/Resume/ResumeV1Language.php index 955085cc..a05a6b72 100644 --- a/src/V1/Product/Resume/ResumeV1Language.php +++ b/src/V1/Product/Resume/ResumeV1Language.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The list of languages that the candidate is proficient in. */ -class ResumeV1Language +class ResumeV1Language implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -24,20 +25,15 @@ class ResumeV1Language * @var string|null The candidate's level for the language. */ public ?string $level; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->language = $rawPrediction["language"] ?? null; $this->level = $rawPrediction["level"] ?? null; } diff --git a/src/V1/Product/Resume/ResumeV1Languages.php b/src/V1/Product/Resume/ResumeV1Languages.php index f8edf407..a1a4e2a7 100644 --- a/src/V1/Product/Resume/ResumeV1Languages.php +++ b/src/V1/Product/Resume/ResumeV1Languages.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\Resume; use ArrayObject; +use Stringable; /** * The list of languages that the candidate is proficient in. * @extends ArrayObject */ -class ResumeV1Languages extends ArrayObject +class ResumeV1Languages extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/Resume/ResumeV1ProfessionalExperience.php b/src/V1/Product/Resume/ResumeV1ProfessionalExperience.php index b4941df7..d9d2d1ee 100644 --- a/src/V1/Product/Resume/ResumeV1ProfessionalExperience.php +++ b/src/V1/Product/Resume/ResumeV1ProfessionalExperience.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The list of the candidate's professional experiences. */ -class ResumeV1ProfessionalExperience +class ResumeV1ProfessionalExperience implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -52,20 +53,15 @@ class ResumeV1ProfessionalExperience * @var string|null The year when the professional experience began. */ public ?string $startYear; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->contractType = $rawPrediction["contract_type"] ?? null; $this->department = $rawPrediction["department"] ?? null; $this->description = $rawPrediction["description"] ?? null; diff --git a/src/V1/Product/Resume/ResumeV1ProfessionalExperiences.php b/src/V1/Product/Resume/ResumeV1ProfessionalExperiences.php index 29c3e1af..8c470bd0 100644 --- a/src/V1/Product/Resume/ResumeV1ProfessionalExperiences.php +++ b/src/V1/Product/Resume/ResumeV1ProfessionalExperiences.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\Resume; use ArrayObject; +use Stringable; /** * The list of the candidate's professional experiences. * @extends ArrayObject */ -class ResumeV1ProfessionalExperiences extends ArrayObject +class ResumeV1ProfessionalExperiences extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/Resume/ResumeV1SocialNetworksUrl.php b/src/V1/Product/Resume/ResumeV1SocialNetworksUrl.php index 1972668c..3fe6add7 100644 --- a/src/V1/Product/Resume/ResumeV1SocialNetworksUrl.php +++ b/src/V1/Product/Resume/ResumeV1SocialNetworksUrl.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The list of social network profiles of the candidate. */ -class ResumeV1SocialNetworksUrl +class ResumeV1SocialNetworksUrl implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -24,20 +25,15 @@ class ResumeV1SocialNetworksUrl * @var string|null The URL of the social network. */ public ?string $url; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->name = $rawPrediction["name"] ?? null; $this->url = $rawPrediction["url"] ?? null; } diff --git a/src/V1/Product/Resume/ResumeV1SocialNetworksUrls.php b/src/V1/Product/Resume/ResumeV1SocialNetworksUrls.php index c1d4cc70..be9ff061 100644 --- a/src/V1/Product/Resume/ResumeV1SocialNetworksUrls.php +++ b/src/V1/Product/Resume/ResumeV1SocialNetworksUrls.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\Resume; use ArrayObject; +use Stringable; /** * The list of social network profiles of the candidate. * @extends ArrayObject */ -class ResumeV1SocialNetworksUrls extends ArrayObject +class ResumeV1SocialNetworksUrls extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/Us/HealthcareCard/HealthcareCardV1Copay.php b/src/V1/Product/Us/HealthcareCard/HealthcareCardV1Copay.php index f1c9d35b..77b066d2 100644 --- a/src/V1/Product/Us/HealthcareCard/HealthcareCardV1Copay.php +++ b/src/V1/Product/Us/HealthcareCard/HealthcareCardV1Copay.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * Copayments for covered services. */ -class HealthcareCardV1Copay +class HealthcareCardV1Copay implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -24,20 +25,15 @@ class HealthcareCardV1Copay * @var string|null The name of the service. */ public ?string $serviceName; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->serviceFees = isset($rawPrediction["service_fees"]) ? (float) ($rawPrediction["service_fees"]) : null; $this->serviceName = $rawPrediction["service_name"] ?? null; diff --git a/src/V1/Product/Us/HealthcareCard/HealthcareCardV1Copays.php b/src/V1/Product/Us/HealthcareCard/HealthcareCardV1Copays.php index ea4d939f..0349c0c6 100644 --- a/src/V1/Product/Us/HealthcareCard/HealthcareCardV1Copays.php +++ b/src/V1/Product/Us/HealthcareCard/HealthcareCardV1Copays.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\Us\HealthcareCard; use ArrayObject; +use Stringable; /** * Copayments for covered services. * @extends ArrayObject */ -class HealthcareCardV1Copays extends ArrayObject +class HealthcareCardV1Copays extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/Us/UsMail/UsMailV3RecipientAddress.php b/src/V1/Product/Us/UsMail/UsMailV3RecipientAddress.php index e938d7f6..872ae58c 100644 --- a/src/V1/Product/Us/UsMail/UsMailV3RecipientAddress.php +++ b/src/V1/Product/Us/UsMail/UsMailV3RecipientAddress.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The addresses of the recipients. */ -class UsMailV3RecipientAddress +class UsMailV3RecipientAddress implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -48,20 +49,15 @@ class UsMailV3RecipientAddress * @var string|null The unit number of the recipient's address. */ public ?string $unit; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->city = $rawPrediction["city"] ?? null; $this->complete = $rawPrediction["complete"] ?? null; $this->isAddressChange = $rawPrediction["is_address_change"] ?? null; diff --git a/src/V1/Product/Us/UsMail/UsMailV3RecipientAddresses.php b/src/V1/Product/Us/UsMail/UsMailV3RecipientAddresses.php index 03b6a97d..652430f4 100644 --- a/src/V1/Product/Us/UsMail/UsMailV3RecipientAddresses.php +++ b/src/V1/Product/Us/UsMail/UsMailV3RecipientAddresses.php @@ -5,12 +5,13 @@ namespace Mindee\V1\Product\Us\UsMail; use ArrayObject; +use Stringable; /** * The addresses of the recipients. * @extends ArrayObject */ -class UsMailV3RecipientAddresses extends ArrayObject +class UsMailV3RecipientAddresses extends ArrayObject implements Stringable { /** * @param array> $rawPrediction Raw prediction array. diff --git a/src/V1/Product/Us/UsMail/UsMailV3SenderAddress.php b/src/V1/Product/Us/UsMail/UsMailV3SenderAddress.php index ecbde5a3..3414229a 100644 --- a/src/V1/Product/Us/UsMail/UsMailV3SenderAddress.php +++ b/src/V1/Product/Us/UsMail/UsMailV3SenderAddress.php @@ -7,11 +7,12 @@ use Mindee\V1\Parsing\Standard\FieldConfidenceMixin; use Mindee\V1\Parsing\Standard\FieldPositionMixin; use Mindee\V1\Parsing\SummaryHelperV1; +use Stringable; /** * The address of the sender. */ -class UsMailV3SenderAddress +class UsMailV3SenderAddress implements Stringable { use FieldConfidenceMixin; use FieldPositionMixin; @@ -36,20 +37,15 @@ class UsMailV3SenderAddress * @var string|null The street of the sender's address. */ public ?string $street; - /** - * @var integer|null Page ID. - */ - public ?int $pageId; /** * @param array> $rawPrediction Array containing the JSON document response. * @param integer|null $pageId Page number for multi pages document. */ - public function __construct(array $rawPrediction, ?int $pageId) + public function __construct(array $rawPrediction, public ?int $pageId) { $this->setConfidence($rawPrediction); $this->setPosition($rawPrediction); - $this->pageId = $pageId; $this->city = $rawPrediction["city"] ?? null; $this->complete = $rawPrediction["complete"] ?? null; $this->postalCode = $rawPrediction["postal_code"] ?? null; diff --git a/src/V2/Client.php b/src/V2/Client.php index 4ad08ef1..649bb553 100644 --- a/src/V2/Client.php +++ b/src/V2/Client.php @@ -9,7 +9,7 @@ use Mindee\Error\MindeeException; use Mindee\Input\InputSource; use Mindee\V2\ClientOptions\BaseParameters; -use Mindee\V2\HTTP\MindeeAPIV2; +use Mindee\V2\Http\MindeeApiV2; use Mindee\V2\Parsing\Inference\BaseResponse; use Mindee\V2\Parsing\JobResponse; use Mindee\V2\Product\Extraction\Params\ExtractionParameters; @@ -22,9 +22,9 @@ class Client use CustomSleepMixin; /** - * @var MindeeAPIV2 Mindee API V2. + * @var MindeeApiV2 Mindee API V2. */ - protected MindeeAPIV2 $mindeeApi; + protected MindeeApiV2 $mindeeApi; /** * Mindee Client V2. @@ -33,7 +33,7 @@ class Client */ public function __construct(?string $apiKey = null) { - $this->mindeeApi = new MindeeAPIV2($apiKey ?: getenv('MINDEE_V2_API_KEY')); + $this->mindeeApi = new MindeeApiV2($apiKey ?: getenv('MINDEE_V2_API_KEY')); } /** diff --git a/src/V2/ClientOptions/BaseParameters.php b/src/V2/ClientOptions/BaseParameters.php index 796a19d1..f146d025 100644 --- a/src/V2/ClientOptions/BaseParameters.php +++ b/src/V2/ClientOptions/BaseParameters.php @@ -4,8 +4,6 @@ namespace Mindee\V2\ClientOptions; -use function count; - /** * Base parameters for running an inference. */ @@ -16,15 +14,10 @@ abstract class BaseParameters */ public ?string $alias; - /** - * @var string Model ID. - */ - public string $modelId; - /** * @var array Optional webhook IDs. */ - public array $webhooksIds; + public array $webhookIds; /** * @var string Slug of the endpoint. @@ -34,19 +27,17 @@ abstract class BaseParameters /** * @param string $modelId ID of the model. * @param string|null $alias Optional file alias. - * @param array|null $webhooksIds List of webhook IDs. + * @param array|null $webhookIds List of webhook IDs. */ - public function __construct(string $modelId, ?string $alias, ?array $webhooksIds) + public function __construct(public string $modelId, ?string $alias, ?array $webhookIds) { - $this->modelId = $modelId; - if (isset($alias)) { $this->alias = $alias; } - if (isset($webhooksIds)) { - $this->webhooksIds = $webhooksIds; + if (isset($webhookIds)) { + $this->webhookIds = $webhookIds; } else { - $this->webhooksIds = []; + $this->webhookIds = []; } } @@ -61,8 +52,8 @@ public function asHash(): array } - if (!empty($this->webhooksIds)) { - $outHash['webhook_ids'] = implode(',', $this->webhooksIds); + if (!empty($this->webhookIds)) { + $outHash['webhook_ids'] = implode(',', $this->webhookIds); } return $outHash; } diff --git a/src/V2/FileOperations/Crop.php b/src/V2/FileOperations/Crop.php index 1be4e189..1240d982 100644 --- a/src/V2/FileOperations/Crop.php +++ b/src/V2/FileOperations/Crop.php @@ -16,18 +16,10 @@ */ class Crop { - /** - * @var LocalInputSource localInputSource object - */ - private readonly LocalInputSource $localInput; - /** * @param LocalInputSource $localInput LocalInputSource object. */ - public function __construct(LocalInputSource $localInput) - { - $this->localInput = $localInput; - } + public function __construct(private readonly LocalInputSource $localInput) {} /** * Extracts a crop zone from a file. diff --git a/src/V2/FileOperations/Split.php b/src/V2/FileOperations/Split.php index 93015574..a8a55689 100644 --- a/src/V2/FileOperations/Split.php +++ b/src/V2/FileOperations/Split.php @@ -5,8 +5,8 @@ namespace Mindee\V2\FileOperations; use Mindee\Error\MindeeInputException; -use Mindee\Extraction\ExtractedPDF; -use Mindee\Extraction\PDFExtractor; +use Mindee\Extraction\ExtractedPdf; +use Mindee\Extraction\PdfExtractor; use Mindee\Input\LocalInputSource; /** @@ -15,17 +15,9 @@ class Split { /** - * @var LocalInputSource localInputSource object + * @param LocalInputSource $localInput LocalInputSource object. */ - private readonly LocalInputSource $localInput; - - /** - * @param LocalInputSource $inputSource LocalInputSource object. - */ - public function __construct(LocalInputSource $inputSource) - { - $this->localInput = $inputSource; - } + public function __construct(private readonly LocalInputSource $localInput) {} /** * Expands a range to a list of integers. @@ -51,9 +43,9 @@ public static function expandRange(int $start, int $end): array * * @param int[] $split Split range to extract. * - * @return ExtractedPDF 2D array of extracted pages + * @return ExtractedPdf 2D array of extracted pages */ - public function extractSingleSplit(array $split): ExtractedPDF + public function extractSingleSplit(array $split): ExtractedPdf { return $this->extractSplits([$split])[0]; } @@ -67,7 +59,7 @@ public function extractSingleSplit(array $split): ExtractedPDF */ public function extractSplits(array $splits): SplitFiles { - $pdfExtractor = new PDFExtractor($this->localInput); + $pdfExtractor = new PdfExtractor($this->localInput); $expandedPageIndexes = array_map(static fn(array $split) => self::expandRange($split[0], $split[1]), $splits); return new SplitFiles(...$pdfExtractor->extractSubDocuments($expandedPageIndexes)); diff --git a/src/V2/FileOperations/SplitFiles.php b/src/V2/FileOperations/SplitFiles.php index 9b9fd0cf..20a8146c 100644 --- a/src/V2/FileOperations/SplitFiles.php +++ b/src/V2/FileOperations/SplitFiles.php @@ -5,7 +5,7 @@ namespace Mindee\V2\FileOperations; use Mindee\Error\MindeeException; -use Mindee\Extraction\ExtractedPDF; +use Mindee\Extraction\ExtractedPdf; use ArrayObject; use Exception; @@ -16,16 +16,16 @@ /** * Split files collection wrapper. * - * @extends ArrayObject + * @extends ArrayObject */ class SplitFiles extends ArrayObject { /** * Builds a new SplitFiles collection. * - * @param ExtractedPDF ...$items Items. + * @param ExtractedPdf ...$items Items. */ - public function __construct(ExtractedPDF ...$items) + public function __construct(ExtractedPdf ...$items) { parent::__construct($items); } diff --git a/src/V2/HTTP/MindeeAPIV2.php b/src/V2/Http/MindeeApiV2.php similarity index 97% rename from src/V2/HTTP/MindeeAPIV2.php rename to src/V2/Http/MindeeApiV2.php index 28eadd49..34e86328 100644 --- a/src/V2/HTTP/MindeeAPIV2.php +++ b/src/V2/Http/MindeeApiV2.php @@ -6,7 +6,7 @@ * Settings and variables linked to endpoint calling & API usage. */ -namespace Mindee\V2\HTTP; +namespace Mindee\V2\Http; use CurlHandle; use Exception; @@ -17,7 +17,7 @@ use Mindee\Error\MindeeV2HttpUnknownException; use Mindee\Input\InputSource; use Mindee\Input\LocalInputSource; -use Mindee\Input\URLInputSource; +use Mindee\Input\UrlInputSource; use Mindee\V2\ClientOptions\BaseParameters; use Mindee\V2\Parsing\ErrorResponse; use Mindee\V2\Parsing\Inference\BaseResponse; @@ -29,7 +29,7 @@ use function call_user_func; use function dirname; -use const Mindee\V1\HTTP\API_KEY_ENV_NAME; +use const Mindee\V1\Http\API_KEY_ENV_NAME; use const Mindee\VERSION; // phpcs:disable @@ -64,7 +64,7 @@ /** * Data class containing settings for endpoints. */ -class MindeeAPIV2 +class MindeeApiV2 { /** * Get the User Agent to send for API calls. @@ -81,7 +81,7 @@ private function getUserAgent(): string /** * @var string|null API key. */ - public ?string $apiKey; + public ?string $apiKey = null; /** * @var integer Timeout for the request, in ms. */ @@ -98,7 +98,7 @@ private function getUserAgent(): string */ public function __construct(?string $apiKey) { - $this->setApiKey($apiKey); + $this->setAPIKey($apiKey); $this->baseUrl = API_V2_BASE_URL_DEFAULT; $this->requestTimeout = API_V2_TIMEOUT_DEFAULT; $this->setFromEnv(); @@ -129,7 +129,7 @@ protected function setBaseUrl(string $value): void private function setFromEnv(): void { $envVars = [ - API_V2_BASE_URL_ENV_NAME => [$this, 'setBaseUrl'], + API_V2_BASE_URL_ENV_NAME => $this->setBaseUrl(...), API_V2_REQUEST_TIMEOUT_ENV_NAME => [$this, 'setTimeout'], ]; foreach ($envVars as $key => $func) { @@ -147,7 +147,7 @@ private function setFromEnv(): void * * @param string|null $apiKey Optional API key. */ - protected function setApiKey(?string $apiKey = null): void + protected function setAPIKey(?string $apiKey = null): void { $envVal = !getenv(API_V2_KEY_ENV_NAME) ? '' : getenv(API_V2_KEY_ENV_NAME); if (!$apiKey) { @@ -346,7 +346,7 @@ private function documentEnqueuePost( $ch = $this->initChannel(); $postFields = $params->asHash(); - if ($inputSource instanceof URLInputSource) { + if ($inputSource instanceof UrlInputSource) { $postFields['url'] = $inputSource->url; } elseif ($inputSource instanceof LocalInputSource) { $inputSource->checkNeedsFix(); diff --git a/src/V2/Parsing/BaseInference.php b/src/V2/Parsing/BaseInference.php index 81b2a855..5d39473a 100644 --- a/src/V2/Parsing/BaseInference.php +++ b/src/V2/Parsing/BaseInference.php @@ -8,11 +8,12 @@ use Mindee\V2\Parsing\Inference\InferenceFile; use Mindee\V2\Parsing\Inference\InferenceJob; use Mindee\V2\Parsing\Inference\InferenceModel; +use Stringable; /** * Base for all inference-based V2 products. */ -abstract class BaseInference +abstract class BaseInference implements Stringable { /** * @var string ID of the inference. diff --git a/src/V2/Parsing/Inference/BaseResponse.php b/src/V2/Parsing/Inference/BaseResponse.php index 341d85ed..94c2cdfc 100644 --- a/src/V2/Parsing/Inference/BaseResponse.php +++ b/src/V2/Parsing/Inference/BaseResponse.php @@ -10,17 +10,9 @@ abstract class BaseResponse { /** - * @var array> Raw HTTP response from the server. + * @param array> $rawHttp Raw server response array. */ - private array $rawHttp; - - /** - * @param array> $rawResponse Raw server response array. - */ - protected function __construct(array $rawResponse) - { - $this->rawHttp = $rawResponse; - } + protected function __construct(private readonly array $rawHttp) {} /** * @return string Raw dump of the JSON response. diff --git a/src/V2/Parsing/Inference/Field/BaseField.php b/src/V2/Parsing/Inference/Field/BaseField.php index 02d64559..f11d30d6 100644 --- a/src/V2/Parsing/Inference/Field/BaseField.php +++ b/src/V2/Parsing/Inference/Field/BaseField.php @@ -5,6 +5,7 @@ namespace Mindee\V2\Parsing\Inference\Field; use Mindee\Error\MindeeApiException; +use Stringable; use function array_key_exists; use function sprintf; @@ -12,12 +13,8 @@ /** * Base class for V2 fields. */ -abstract class BaseField +abstract class BaseField implements Stringable { - /** - * @var integer Level of indentation for rst display. - */ - protected int $indentLevel; /** * @var array List of possible locations for a field. */ @@ -32,9 +29,8 @@ abstract class BaseField * @param array> $rawPrediction Raw prediction array. * @param integer $indentLevel Level of indentation for rst display. */ - public function __construct(array $rawPrediction, int $indentLevel = 0) + public function __construct(array $rawPrediction, protected int $indentLevel = 0) { - $this->indentLevel = $indentLevel; if (array_key_exists("locations", $rawPrediction) && $rawPrediction["locations"]) { $this->locations = []; foreach ($rawPrediction["locations"] as $location) { diff --git a/src/V2/Parsing/Inference/Field/FieldLocation.php b/src/V2/Parsing/Inference/Field/FieldLocation.php index 6699af10..6de9bcb9 100644 --- a/src/V2/Parsing/Inference/Field/FieldLocation.php +++ b/src/V2/Parsing/Inference/Field/FieldLocation.php @@ -5,13 +5,14 @@ namespace Mindee\V2\Parsing\Inference\Field; use Mindee\Geometry\Polygon; +use Stringable; use function is_int; /** * Location of a field. */ -class FieldLocation +class FieldLocation implements Stringable { /** * Free polygon made up of points (can be null when not provided). diff --git a/src/V2/Parsing/Inference/Field/InferenceFields.php b/src/V2/Parsing/Inference/Field/InferenceFields.php index 7a041273..aa2018d9 100644 --- a/src/V2/Parsing/Inference/Field/InferenceFields.php +++ b/src/V2/Parsing/Inference/Field/InferenceFields.php @@ -20,19 +20,12 @@ class InferenceFields extends ArrayObject */ private array $fields = []; - /** - * @var integer Indentation level. - */ - private int $indentLevel; - /** * @param array> $rawResponse Raw server response array. * @param integer $indentLevel Level of indentation. */ - public function __construct(array $rawResponse, int $indentLevel = 0) + public function __construct(array $rawResponse, private readonly int $indentLevel = 0) { - $this->indentLevel = $indentLevel; - foreach ($rawResponse as $key => $value) { $this->fields[$key] = BaseField::createField($value, 1); } diff --git a/src/V2/Parsing/Inference/InferenceActiveOptions.php b/src/V2/Parsing/Inference/InferenceActiveOptions.php index ff0fbd37..7d1e214e 100644 --- a/src/V2/Parsing/Inference/InferenceActiveOptions.php +++ b/src/V2/Parsing/Inference/InferenceActiveOptions.php @@ -6,6 +6,7 @@ use Mindee\Parsing\SummaryHelper; use Mindee\V2\Product\Extraction\Params\DataSchemaActiveOption; +use Stringable; /** * Options which were activated during the inference. @@ -14,7 +15,7 @@ * - By setting their default values on the Platform UI * - By explicitly setting them in the inference request */ -class InferenceActiveOptions +class InferenceActiveOptions implements Stringable { /** * @var boolean Whether the Retrieval-Augmented Generation feature was activated. diff --git a/src/V2/Parsing/Inference/InferenceFile.php b/src/V2/Parsing/Inference/InferenceFile.php index 74251acc..e39bf6b0 100644 --- a/src/V2/Parsing/Inference/InferenceFile.php +++ b/src/V2/Parsing/Inference/InferenceFile.php @@ -4,10 +4,12 @@ namespace Mindee\V2\Parsing\Inference; +use Stringable; + /** * Inference result file class. */ -class InferenceFile +class InferenceFile implements Stringable { /** * @var string Name of the file. diff --git a/src/V2/Parsing/Inference/InferenceJob.php b/src/V2/Parsing/Inference/InferenceJob.php index 5bc7a552..4c288bd2 100644 --- a/src/V2/Parsing/Inference/InferenceJob.php +++ b/src/V2/Parsing/Inference/InferenceJob.php @@ -4,10 +4,12 @@ namespace Mindee\V2\Parsing\Inference; +use Stringable; + /** * Information on the Job associated to a given Inference. */ -class InferenceJob +class InferenceJob implements Stringable { /** * @var string UUID of the job. diff --git a/src/V2/Parsing/Inference/InferenceModel.php b/src/V2/Parsing/Inference/InferenceModel.php index 7dbbdf76..d508b10d 100644 --- a/src/V2/Parsing/Inference/InferenceModel.php +++ b/src/V2/Parsing/Inference/InferenceModel.php @@ -4,10 +4,12 @@ namespace Mindee\V2\Parsing\Inference; +use Stringable; + /** * Inference result model class. */ -class InferenceModel +class InferenceModel implements Stringable { /** * @var string ID of the model. diff --git a/src/V2/Parsing/Inference/RAGMetadata.php b/src/V2/Parsing/Inference/RagMetadata.php similarity index 96% rename from src/V2/Parsing/Inference/RAGMetadata.php rename to src/V2/Parsing/Inference/RagMetadata.php index f63935e3..b1916f3b 100644 --- a/src/V2/Parsing/Inference/RAGMetadata.php +++ b/src/V2/Parsing/Inference/RagMetadata.php @@ -7,7 +7,7 @@ /** * Metadata about the RAG operation. */ -class RAGMetadata +class RagMetadata { /** * @var string|null ID of the matched document, if present. diff --git a/src/V2/Parsing/Inference/RawText.php b/src/V2/Parsing/Inference/RawText.php index 1f6bf181..5b4be8f6 100644 --- a/src/V2/Parsing/Inference/RawText.php +++ b/src/V2/Parsing/Inference/RawText.php @@ -4,12 +4,14 @@ namespace Mindee\V2\Parsing\Inference; +use Stringable; + use function array_key_exists; /** * Raw text as found in the document. */ -class RawText +class RawText implements Stringable { /** * @var RawTextPage[] list of pages found in the document. diff --git a/src/V2/Parsing/Inference/RawTextPage.php b/src/V2/Parsing/Inference/RawTextPage.php index 85d67245..e0008988 100644 --- a/src/V2/Parsing/Inference/RawTextPage.php +++ b/src/V2/Parsing/Inference/RawTextPage.php @@ -4,10 +4,12 @@ namespace Mindee\V2\Parsing\Inference; +use Stringable; + /** * Raw text extracted from the page. */ -class RawTextPage +class RawTextPage implements Stringable { /** * Page content as a single string. diff --git a/src/V2/Parsing/Job.php b/src/V2/Parsing/Job.php index 884ad054..3957e17f 100644 --- a/src/V2/Parsing/Job.php +++ b/src/V2/Parsing/Job.php @@ -116,7 +116,7 @@ private function parseDate(?string $dateString): ?DateTime try { return new DateTime($dateString); - } catch (Exception $e) { + } catch (Exception) { return null; } } diff --git a/src/V2/Parsing/JobWebhook.php b/src/V2/Parsing/JobWebhook.php index c8d856b3..3205c2ce 100644 --- a/src/V2/Parsing/JobWebhook.php +++ b/src/V2/Parsing/JobWebhook.php @@ -60,7 +60,7 @@ private function parseDate(?string $dateString): ?DateTime try { return new DateTime($dateString); - } catch (Exception $e) { + } catch (Exception) { return null; } } diff --git a/src/V2/Product/Classification/ClassificationClassifier.php b/src/V2/Product/Classification/ClassificationClassifier.php index 5bf6ee32..9e53fc91 100644 --- a/src/V2/Product/Classification/ClassificationClassifier.php +++ b/src/V2/Product/Classification/ClassificationClassifier.php @@ -5,11 +5,12 @@ namespace Mindee\V2\Product\Classification; use Mindee\V2\Product\Extraction\ExtractionResponse; +use Stringable; /** * Classification of document type from the source file. */ -class ClassificationClassifier +class ClassificationClassifier implements Stringable { /** * @var string The document type, as identified on given classification values. diff --git a/src/V2/Product/Classification/ClassificationResult.php b/src/V2/Product/Classification/ClassificationResult.php index 5b5e22e3..fda1e00b 100644 --- a/src/V2/Product/Classification/ClassificationResult.php +++ b/src/V2/Product/Classification/ClassificationResult.php @@ -4,10 +4,12 @@ namespace Mindee\V2\Product\Classification; +use Stringable; + /** * Result of the document classifier inference. */ -class ClassificationResult +class ClassificationResult implements Stringable { /** * @var ClassificationClassifier Classification of document type from the source file. diff --git a/src/V2/Product/Classification/Params/ClassificationParameters.php b/src/V2/Product/Classification/Params/ClassificationParameters.php index fade894e..057f9e1c 100644 --- a/src/V2/Product/Classification/Params/ClassificationParameters.php +++ b/src/V2/Product/Classification/Params/ClassificationParameters.php @@ -20,13 +20,13 @@ class ClassificationParameters extends BaseParameters /** * @param string $modelId ID of the model. * @param string|null $alias Optional file alias. - * @param array|null $webhooksIds List of webhook IDs. + * @param array|null $webhookIds List of webhook IDs. */ public function __construct( string $modelId, ?string $alias = null, - ?array $webhooksIds = null + ?array $webhookIds = null ) { - parent::__construct($modelId, $alias, $webhooksIds); + parent::__construct($modelId, $alias, $webhookIds); } } diff --git a/src/V2/Product/Crop/CropItem.php b/src/V2/Product/Crop/CropItem.php index 7b0b8e08..eba0759c 100644 --- a/src/V2/Product/Crop/CropItem.php +++ b/src/V2/Product/Crop/CropItem.php @@ -6,11 +6,12 @@ use Mindee\V2\Parsing\Inference\Field\FieldLocation; use Mindee\V2\Product\Extraction\ExtractionResponse; +use Stringable; /** * Result of a cropped document region. */ -class CropItem +class CropItem implements Stringable { /** * @var FieldLocation Location which includes cropping coordinates for the detected object, @@ -40,7 +41,7 @@ public function __construct(array $rawResponse) /** * @return string String representation. */ - public function __toString() + public function __toString(): string { return "* :Location: $this->location\n :Object Type: $this->objectType"; } diff --git a/src/V2/Product/Crop/CropResult.php b/src/V2/Product/Crop/CropResult.php index 23428a97..0e8bdc18 100644 --- a/src/V2/Product/Crop/CropResult.php +++ b/src/V2/Product/Crop/CropResult.php @@ -4,10 +4,12 @@ namespace Mindee\V2\Product\Crop; +use Stringable; + /** * Result of a crop utility inference. */ -class CropResult +class CropResult implements Stringable { /** * @var CropItem[] Crops extracted from the image. diff --git a/src/V2/Product/Crop/Params/CropParameters.php b/src/V2/Product/Crop/Params/CropParameters.php index 1daacedb..e7cdf652 100644 --- a/src/V2/Product/Crop/Params/CropParameters.php +++ b/src/V2/Product/Crop/Params/CropParameters.php @@ -20,13 +20,13 @@ class CropParameters extends BaseParameters /** * @param string $modelId ID of the model. * @param string|null $alias Optional file alias. - * @param array|null $webhooksIds List of webhook IDs. + * @param array|null $webhookIds List of webhook IDs. */ public function __construct( string $modelId, ?string $alias = null, - ?array $webhooksIds = null + ?array $webhookIds = null ) { - parent::__construct($modelId, $alias, $webhooksIds); + parent::__construct($modelId, $alias, $webhookIds); } } diff --git a/src/V2/Product/Extraction/ExtractionResult.php b/src/V2/Product/Extraction/ExtractionResult.php index f6102026..2a1ae194 100644 --- a/src/V2/Product/Extraction/ExtractionResult.php +++ b/src/V2/Product/Extraction/ExtractionResult.php @@ -5,13 +5,14 @@ namespace Mindee\V2\Product\Extraction; use Mindee\V2\Parsing\Inference\Field\InferenceFields; -use Mindee\V2\Parsing\Inference\RAGMetadata; +use Mindee\V2\Parsing\Inference\RagMetadata; use Mindee\V2\Parsing\Inference\RawText; +use Stringable; /** * Inference result class. */ -class ExtractionResult +class ExtractionResult implements Stringable { /** * @var InferenceFields Fields contained in the inference. @@ -24,9 +25,9 @@ class ExtractionResult public ?RawText $rawText; /** - * @var RAGMetadata|null RAG metadata. + * @var RagMetadata|null RAG metadata. */ - public ?RAGMetadata $rag; + public ?RagMetadata $rag; /** * @param array> $rawResponse Raw server response array. @@ -39,7 +40,7 @@ public function __construct(array $rawResponse) : null; $this->rag = isset( $rawResponse['rag'] - ) ? new RAGMetadata($rawResponse['rag']) : null; + ) ? new RagMetadata($rawResponse['rag']) : null; } /** diff --git a/src/V2/Product/Extraction/Params/DataSchema.php b/src/V2/Product/Extraction/Params/DataSchema.php index faf492ff..98d1a0b3 100644 --- a/src/V2/Product/Extraction/Params/DataSchema.php +++ b/src/V2/Product/Extraction/Params/DataSchema.php @@ -5,6 +5,7 @@ namespace Mindee\V2\Product\Extraction\Params; use InvalidArgumentException; +use Stringable; use function get_class; use function gettype; @@ -12,7 +13,7 @@ /** * Modify the Data Schema. */ -class DataSchema +class DataSchema implements Stringable { /** * @var DataSchemaReplace|null If set, completely replaces the data schema of the model. @@ -30,7 +31,7 @@ public function __construct(self|array|string $dataSchema) } elseif (gettype($dataSchema) === 'array') { $jsonData = $dataSchema; } else { - if (get_class($dataSchema) === self::class) { + if ($dataSchema::class === self::class) { $this->replace = $dataSchema->replace; return; } @@ -76,7 +77,7 @@ private function toJsonStringProperSpacing(): string { $jsonStr = json_encode($this->toJson(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); $lines = explode("\n", $jsonStr); - return implode("\n", array_map(static fn($line) => self::fixLineSpaces($line), $lines)) . "\n"; + return implode("\n", array_map(self::fixLineSpaces(...), $lines)) . "\n"; } /** diff --git a/src/V2/Product/Extraction/Params/DataSchemaActiveOption.php b/src/V2/Product/Extraction/Params/DataSchemaActiveOption.php index e5c62f88..871d592a 100644 --- a/src/V2/Product/Extraction/Params/DataSchemaActiveOption.php +++ b/src/V2/Product/Extraction/Params/DataSchemaActiveOption.php @@ -4,10 +4,12 @@ namespace Mindee\V2\Product\Extraction\Params; +use Stringable; + /** * Data schema options activated during the inference. */ -class DataSchemaActiveOption +class DataSchemaActiveOption implements Stringable { /** * @var boolean Whether the Data Schema has been replaced. diff --git a/src/V2/Product/Extraction/Params/DataSchemaField.php b/src/V2/Product/Extraction/Params/DataSchemaField.php index b7103429..a281ce68 100644 --- a/src/V2/Product/Extraction/Params/DataSchemaField.php +++ b/src/V2/Product/Extraction/Params/DataSchemaField.php @@ -4,10 +4,12 @@ namespace Mindee\V2\Product\Extraction\Params; +use Stringable; + /** * Data Schema Field. */ -class DataSchemaField +class DataSchemaField implements Stringable { /** * @var string Name of the field in the data schema. @@ -103,7 +105,7 @@ public function toJson(): array public function __toString(): string { - return json_encode( + return (string) json_encode( $this->toJson(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ); diff --git a/src/V2/Product/Extraction/Params/DataSchemaReplace.php b/src/V2/Product/Extraction/Params/DataSchemaReplace.php index 77cd9c4a..cc5bfd82 100644 --- a/src/V2/Product/Extraction/Params/DataSchemaReplace.php +++ b/src/V2/Product/Extraction/Params/DataSchemaReplace.php @@ -5,6 +5,7 @@ namespace Mindee\V2\Product\Extraction\Params; use InvalidArgumentException; +use Stringable; use function count; use function is_array; @@ -12,7 +13,7 @@ /** * The structure to completely replace the data schema of the model. */ -class DataSchemaReplace +class DataSchemaReplace implements Stringable { /** * @var DataSchemaField[] Fields to replace in the data schema. @@ -48,7 +49,7 @@ public function toJson(): array */ public function __toString(): string { - return json_encode( + return (string) json_encode( $this->toJson(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ); diff --git a/src/V2/Product/Extraction/Params/ExtractionParameters.php b/src/V2/Product/Extraction/Params/ExtractionParameters.php index dd6a5dc3..5deaf086 100644 --- a/src/V2/Product/Extraction/Params/ExtractionParameters.php +++ b/src/V2/Product/Extraction/Params/ExtractionParameters.php @@ -11,28 +11,6 @@ */ class ExtractionParameters extends BaseParameters { - /** - * @var boolean|null Enhance extraction accuracy with Retrieval-Augmented Generation.. - */ - public ?bool $rag; - - /** - * @var boolean|null Extract the full text content from the document as strings. - */ - public ?bool $rawText; - - /** - * @var boolean|null Calculate bounding box polygons for all fields. - */ - public ?bool $polygon; - - /** - * @var boolean|null Boost the precision and accuracy of all extractions. - * Calculate confidence scores for all fields. - */ - public ?bool $confidence; - - /** * @var string|null Additional text context used by the model during inference. * Not recommended, for specific use only. @@ -58,29 +36,24 @@ class ExtractionParameters extends BaseParameters * fields. * @param boolean|null $confidence Whether to calculate confidence scores for all fields. * @param string|null $alias Optional file alias. - * @param array|null $webhooksIds List of webhook IDs. + * @param array|null $webhookIds List of webhook IDs. * @param string|null $textContext Additional text context used by the model during * inference. * @param DataSchema|string|array|null $dataSchema Additional text context used by the model during * inference. */ public function __construct( - string $modelId, - ?bool $rag = null, - ?bool $rawText = null, - ?bool $polygon = null, - ?bool $confidence = null, - ?string $alias = null, - ?array $webhooksIds = null, - ?string $textContext = null, + string $modelId, + public ?bool $rag = null, + public ?bool $rawText = null, + public ?bool $polygon = null, + public ?bool $confidence = null, + ?string $alias = null, + ?array $webhookIds = null, + ?string $textContext = null, DataSchema|string|array|null $dataSchema = null, ) { - parent::__construct($modelId, $alias, $webhooksIds); - - $this->rag = $rag; - $this->rawText = $rawText; - $this->polygon = $polygon; - $this->confidence = $confidence; + parent::__construct($modelId, $alias, $webhookIds); if (isset($textContext)) { $this->textContext = $textContext; } diff --git a/src/V2/Product/OCR/OCRInference.php b/src/V2/Product/Ocr/OcrInference.php similarity index 66% rename from src/V2/Product/OCR/OCRInference.php rename to src/V2/Product/Ocr/OcrInference.php index d14e841e..cfe2fc9d 100644 --- a/src/V2/Product/OCR/OCRInference.php +++ b/src/V2/Product/Ocr/OcrInference.php @@ -2,19 +2,19 @@ declare(strict_types=1); -namespace Mindee\V2\Product\OCR; +namespace Mindee\V2\Product\Ocr; use Mindee\V2\Parsing\BaseInference; /** - * Response for an OCR utility inference. + * Response for an Ocr utility inference. */ -class OCRInference extends BaseInference +class OcrInference extends BaseInference { /** - * @var OCRResult Result of the inference. + * @var OcrResult Result of the inference. */ - public OCRResult $result; + public OcrResult $result; /** * @param array> $rawResponse Raw server response array. @@ -22,7 +22,7 @@ class OCRInference extends BaseInference public function __construct(array $rawResponse) { parent::__construct($rawResponse); - $this->result = new OCRResult($rawResponse['result']); + $this->result = new OcrResult($rawResponse['result']); } /** diff --git a/src/V2/Product/OCR/OCRPage.php b/src/V2/Product/Ocr/OcrPage.php similarity index 71% rename from src/V2/Product/OCR/OCRPage.php rename to src/V2/Product/Ocr/OcrPage.php index 3d4ba986..29a96e73 100644 --- a/src/V2/Product/OCR/OCRPage.php +++ b/src/V2/Product/Ocr/OcrPage.php @@ -2,15 +2,17 @@ declare(strict_types=1); -namespace Mindee\V2\Product\OCR; +namespace Mindee\V2\Product\Ocr; + +use Stringable; /** - * OCR result for a single page. + * Ocr result for a single page. */ -class OCRPage +class OcrPage implements Stringable { /** - * @var OCRWord[] OCR result for a single page. + * @var OcrWord[] Ocr result for a single page. */ public array $words; @@ -24,7 +26,7 @@ class OCRPage */ public function __construct(array $rawResponse) { - $this->words = array_map(static fn($word) => new OCRWord($word), $rawResponse['words']); + $this->words = array_map(static fn($word) => new OcrWord($word), $rawResponse['words']); $this->content = $rawResponse['content']; } @@ -39,6 +41,6 @@ public function __toString(): string $ocrWords .= implode("\n\n", $this->words); } - return "OCR Words\n---------$ocrWords\n\n:Content: $this->content"; + return "Ocr Words\n---------$ocrWords\n\n:Content: $this->content"; } } diff --git a/src/V2/Product/OCR/OCRResponse.php b/src/V2/Product/Ocr/OcrResponse.php similarity index 63% rename from src/V2/Product/OCR/OCRResponse.php rename to src/V2/Product/Ocr/OcrResponse.php index 9dd334dd..2ca6c8b0 100644 --- a/src/V2/Product/OCR/OCRResponse.php +++ b/src/V2/Product/Ocr/OcrResponse.php @@ -2,19 +2,19 @@ declare(strict_types=1); -namespace Mindee\V2\Product\OCR; +namespace Mindee\V2\Product\Ocr; use Mindee\V2\Parsing\Inference\BaseResponse; /** - * Response for an OCR utility inference. + * Response for an Ocr utility inference. */ -class OCRResponse extends BaseResponse +class OcrResponse extends BaseResponse { /** - * @var OCRInference Result of an OCR inference. + * @var OcrInference Result of an Ocr inference. */ - public OCRInference $inference; + public OcrInference $inference; /** * @var string Slug for the inference. @@ -27,6 +27,6 @@ class OCRResponse extends BaseResponse public function __construct(array $rawResponse) { parent::__construct($rawResponse); - $this->inference = new OCRInference($rawResponse['inference']); + $this->inference = new OcrInference($rawResponse['inference']); } } diff --git a/src/V2/Product/OCR/OCRResult.php b/src/V2/Product/Ocr/OcrResult.php similarity index 73% rename from src/V2/Product/OCR/OCRResult.php rename to src/V2/Product/Ocr/OcrResult.php index 6799ab4c..c0e39c72 100644 --- a/src/V2/Product/OCR/OCRResult.php +++ b/src/V2/Product/Ocr/OcrResult.php @@ -2,17 +2,19 @@ declare(strict_types=1); -namespace Mindee\V2\Product\OCR; +namespace Mindee\V2\Product\Ocr; + +use Stringable; use function strlen; /** - * Result of the OCR utility inference. + * Result of the Ocr utility inference. */ -class OCRResult +class OcrResult implements Stringable { /** - * @var OCRPage[] List of pages. + * @var OcrPage[] List of pages. */ public array $pages; @@ -21,7 +23,7 @@ class OCRResult */ public function __construct(array $rawResponse) { - $this->pages = array_map(static fn($page) => new OCRPage($page), $rawResponse['pages']); + $this->pages = array_map(static fn($page) => new OcrPage($page), $rawResponse['pages']); } /** @@ -29,7 +31,7 @@ public function __construct(array $rawResponse) */ public function __toString(): string { - $str = "OCR Result\n##########\n"; + $str = "Ocr Result\n##########\n"; $i = 1; foreach ($this->pages as $page) { diff --git a/src/V2/Product/OCR/OCRWord.php b/src/V2/Product/Ocr/OcrWord.php similarity index 84% rename from src/V2/Product/OCR/OCRWord.php rename to src/V2/Product/Ocr/OcrWord.php index 189632ea..37d8c6c8 100644 --- a/src/V2/Product/OCR/OCRWord.php +++ b/src/V2/Product/Ocr/OcrWord.php @@ -2,14 +2,15 @@ declare(strict_types=1); -namespace Mindee\V2\Product\OCR; +namespace Mindee\V2\Product\Ocr; use Mindee\Geometry\Polygon; +use Stringable; /** - * OCR result for a single word extracted from the document page. + * Ocr result for a single word extracted from the document page. */ -class OCRWord +class OcrWord implements Stringable { /** * @var string Content of the word. diff --git a/src/V2/Product/OCR/Params/OCRParameters.php b/src/V2/Product/Ocr/Params/OcrParameters.php similarity index 66% rename from src/V2/Product/OCR/Params/OCRParameters.php rename to src/V2/Product/Ocr/Params/OcrParameters.php index bb9a95dc..51423730 100644 --- a/src/V2/Product/OCR/Params/OCRParameters.php +++ b/src/V2/Product/Ocr/Params/OcrParameters.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Mindee\V2\Product\OCR\Params; +namespace Mindee\V2\Product\Ocr\Params; use Mindee\ClientOptions\PollingOptions; use Mindee\V2\ClientOptions\BaseParameters; @@ -10,7 +10,7 @@ /** * Parameters for an ocr utility inference. */ -class OCRParameters extends BaseParameters +class OcrParameters extends BaseParameters { /** * @var string Slug of the endpoint. @@ -20,13 +20,13 @@ class OCRParameters extends BaseParameters /** * @param string $modelId ID of the model. * @param string|null $alias Optional file alias. - * @param array|null $webhooksIds List of webhook IDs. + * @param array|null $webhookIds List of webhook IDs. */ public function __construct( string $modelId, ?string $alias = null, - ?array $webhooksIds = null + ?array $webhookIds = null ) { - parent::__construct($modelId, $alias, $webhooksIds); + parent::__construct($modelId, $alias, $webhookIds); } } diff --git a/src/V2/Product/Split/Params/SplitParameters.php b/src/V2/Product/Split/Params/SplitParameters.php index 8f5e790e..8de1262e 100644 --- a/src/V2/Product/Split/Params/SplitParameters.php +++ b/src/V2/Product/Split/Params/SplitParameters.php @@ -20,13 +20,13 @@ class SplitParameters extends BaseParameters /** * @param string $modelId ID of the model. * @param string|null $alias Optional file alias. - * @param array|null $webhooksIds List of webhook IDs. + * @param array|null $webhookIds List of webhook IDs. */ public function __construct( string $modelId, ?string $alias = null, - ?array $webhooksIds = null + ?array $webhookIds = null ) { - parent::__construct($modelId, $alias, $webhooksIds); + parent::__construct($modelId, $alias, $webhookIds); } } diff --git a/src/V2/Product/Split/SplitRange.php b/src/V2/Product/Split/SplitRange.php index 772b3858..96fca6b0 100644 --- a/src/V2/Product/Split/SplitRange.php +++ b/src/V2/Product/Split/SplitRange.php @@ -5,11 +5,12 @@ namespace Mindee\V2\Product\Split; use Mindee\V2\Product\Extraction\ExtractionResponse; +use Stringable; /** * A single document as identified when splitting a multi-document source file. */ -class SplitRange +class SplitRange implements Stringable { /** * @var integer[] 0-based page indexes, where the first integer indicates the start page and the second integer diff --git a/src/V2/Product/Split/SplitResult.php b/src/V2/Product/Split/SplitResult.php index 86859187..403d7944 100644 --- a/src/V2/Product/Split/SplitResult.php +++ b/src/V2/Product/Split/SplitResult.php @@ -4,10 +4,12 @@ namespace Mindee\V2\Product\Split; +use Stringable; + /** * Result of a split utility inference. */ -class SplitResult +class SplitResult implements Stringable { /** * @var SplitRange[] A single document as identified when splitting a multi-document source file. diff --git a/tests/Dependencies/DependencyCheckerNoExtendedTestPDF.php b/tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php similarity index 68% rename from tests/Dependencies/DependencyCheckerNoExtendedTestPDF.php rename to tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php index 775bb962..89873d95 100644 --- a/tests/Dependencies/DependencyCheckerNoExtendedTestPDF.php +++ b/tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php @@ -6,16 +6,20 @@ use Mindee\Error\MindeeUnhandledException; use Mindee\Extraction\ExtractedImage; -use Mindee\Extraction\ExtractedPDF; +use Mindee\Extraction\ExtractedPdf; use Mindee\V1\Image\ImageExtractor; -use Mindee\Extraction\PDFExtractor; +use Mindee\Extraction\PdfExtractor; use Mindee\Input\PathInput; use PHPUnit\Framework\TestCase; use TestingUtilities; +use Imagick; +use stdClass; require_once(__DIR__ . "/../TestingUtilities.php"); -class DependencyCheckerNoExtendedTestPDF extends TestCase +class DummyImagick {} + +class DependencyCheckerNoExtendedTestPdf extends TestCase { public function testNoImageExtractor(): void { @@ -23,25 +27,29 @@ public function testNoImageExtractor(): void $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf"); new ImageExtractor($inputObj); } - public function testNoPDFExtractor(): void + public function testNoPdfExtractor(): void { $this->expectException(MindeeUnhandledException::class); $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf"); - new PDFExtractor($inputObj); + new PdfExtractor($inputObj); } public function testNoExtractedImage(): void { $this->expectException(MindeeUnhandledException::class); - $inputImage = ""; + if (!class_exists('Imagick')) { + class_alias(DummyImagick::class, 'Imagick'); + } + + $inputImage = new Imagick(); $filename = "dummy"; $saveFormat = "pdf"; new ExtractedImage($inputImage, $filename, $saveFormat, 0, 0); } - public function testNoExtractedPDF(): void + public function testNoExtractedPdf(): void { $this->expectException(MindeeUnhandledException::class); $inputImage = ""; $filename = "dummy"; - new ExtractedPDF($inputImage, $filename); + new ExtractedPdf($inputImage, $filename); } } diff --git a/tests/Dependencies/DependencyCheckerPDFTest.php b/tests/Dependencies/DependencyCheckerPdfTest.php similarity index 92% rename from tests/Dependencies/DependencyCheckerPDFTest.php rename to tests/Dependencies/DependencyCheckerPdfTest.php index 22dd7ede..456f624f 100644 --- a/tests/Dependencies/DependencyCheckerPDFTest.php +++ b/tests/Dependencies/DependencyCheckerPdfTest.php @@ -7,7 +7,7 @@ use Mindee\Dependency\DependencyChecker; use PHPUnit\Framework\TestCase; -class DependencyCheckerPDFTest extends TestCase +class DependencyCheckerPdfTest extends TestCase { public function testGhostScriptDependency(): void { diff --git a/tests/Geometry/PolygonUtilsTest.php b/tests/Geometry/PolygonUtilsTest.php index 45868b52..b338427e 100644 --- a/tests/Geometry/PolygonUtilsTest.php +++ b/tests/Geometry/PolygonUtilsTest.php @@ -12,9 +12,9 @@ class PolygonUtilsTest extends TestCase { - private Polygon $polygonWhichIsNotRectangle; - private Polygon $polygon1; - private Polygon $polygon2; + private readonly Polygon $polygonWhichIsNotRectangle; + private readonly Polygon $polygon1; + private readonly Polygon $polygon2; public function __construct(?string $name = null, array $data = [], $dataName = '') { diff --git a/tests/Input/LocalInputSourceTest.php b/tests/Input/LocalInputSourceTest.php index 13f06f46..51637a4a 100644 --- a/tests/Input/LocalInputSourceTest.php +++ b/tests/Input/LocalInputSourceTest.php @@ -5,7 +5,7 @@ namespace Input; use Mindee\Error\ErrorCode; -use Mindee\Error\MindeePDFException; +use Mindee\Error\MindeePdfException; use Mindee\Error\MindeeSourceException; use Mindee\Image\ImageCompressor; use Mindee\Input\Base64Input; @@ -13,8 +13,8 @@ use Mindee\Input\FileInput; use Mindee\Input\PageOptions; use Mindee\Input\PathInput; -use Mindee\PDF\PDFCompressor; -use Mindee\PDF\PDFUtils; +use Mindee\Pdf\PdfCompressor; +use Mindee\Pdf\PdfUtils; use Mindee\V1\Client; use PHPUnit\Framework\TestCase; use setasign\Fpdi\Fpdi; @@ -24,7 +24,7 @@ use function count; -use const Mindee\V1\HTTP\API_KEY_ENV_NAME; +use const Mindee\V1\Http\API_KEY_ENV_NAME; use const Mindee\Input\KEEP_ONLY; use const Mindee\Input\REMOVE; @@ -69,20 +69,20 @@ protected function tearDown(): void } - public function testPDFCountPages(): void + public function testPdfCountPages(): void { $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); self::assertSame(12, $inputObj->getPageCount()); } - public function testPDFReconstructOK(): void + public function testPdfReconstructOK(): void { $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $inputObj->applyPageOptions(new PageOptions([0, 1, 2, 3, 4], KEEP_ONLY, 2)); self::assertSame(5, $inputObj->getPageCount()); } - public function testPDFReadContents(): void + public function testPdfReadContents(): void { $inputDoc = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $contents = $inputDoc->readContents(); @@ -90,9 +90,9 @@ public function testPDFReadContents(): void } /** - * @dataProvider providePDFCutNPagesCases + * @dataProvider providePdfCutNPagesCases */ - public function testPDFCutNPages(array $indexes): void + public function testPdfCutNPages(array $indexes): void { $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $inputObj->applyPageOptions(new PageOptions($indexes, KEEP_ONLY, 2)); @@ -121,7 +121,7 @@ public function testPDFCutNPages(array $indexes): void $basePdf->Close(); $cutPdf->Close(); } catch (PdfParserException|PdfReaderException $e) { - throw new MindeePDFException( + throw new MindeePdfException( "Failed to read PDF file.", ErrorCode::PDF_CANT_PROCESS, $e @@ -129,26 +129,26 @@ public function testPDFCutNPages(array $indexes): void } } - public static function providePDFCutNPagesCases(): iterable + public static function providePdfCutNPagesCases(): iterable { return [[[0]], [[0, -2]], [[0, -2, -1]]]; } - public function testPDFKeep5FirstPages(): void + public function testPdfKeep5FirstPages(): void { $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $inputObj->applyPageOptions(new PageOptions([0, 1, 2, 3, 4], KEEP_ONLY, 2)); self::assertSame(5, $inputObj->getPageCount()); } - public function testPDFKeepInvalidPages(): void + public function testPdfKeepInvalidPages(): void { $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $inputObj->applyPageOptions(new PageOptions([0, 1, 17], KEEP_ONLY, 2)); self::assertSame(2, $inputObj->getPageCount()); } - public function testPDFRemove5LastPages(): void + public function testPdfRemove5LastPages(): void { $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); @@ -156,36 +156,36 @@ public function testPDFRemove5LastPages(): void self::assertSame(7, $inputObj->getPageCount()); } - public function testPDFRemove5FirstPages(): void + public function testPdfRemove5FirstPages(): void { $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $inputObj->applyPageOptions(new PageOptions([0, 1, 2, 3, 4], REMOVE, 2)); self::assertSame(7, $inputObj->getPageCount()); } - public function testPDFRemoveInvalidPages(): void + public function testPdfRemoveInvalidPages(): void { $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $inputObj->applyPageOptions(new PageOptions([16], REMOVE, 2)); self::assertSame(12, $inputObj->getPageCount()); } - public function testPDFKeepNoPages(): void + public function testPdfKeepNoPages(): void { $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); - $this->expectException(MindeePDFException::class); + $this->expectException(MindeePdfException::class); $inputObj->applyPageOptions(new PageOptions([], KEEP_ONLY, 2)); } - public function testPDFRemoveAllPages(): void + public function testPdfRemoveAllPages(): void { $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); - $this->expectException(MindeePDFException::class); + $this->expectException(MindeePdfException::class); $pageOptions = new PageOptions(range(0, $inputObj->getPageCount() - 1), REMOVE, 2); $inputObj->applyPageOptions(pageOptions: $pageOptions); } - public function testPDFInputFromFile(): void + public function testPdfInputFromFile(): void { $fileContents = file_get_contents(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $fileRef = fopen(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf", "r"); @@ -195,7 +195,7 @@ public function testPDFInputFromFile(): void self::assertSame($fileContents, $contents[1]); } - public function testPDFInputFromBytes(): void + public function testPdfInputFromBytes(): void { $pdfBytes = file_get_contents(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $inputDoc = new BytesInput($pdfBytes, "dummy.pdf"); @@ -213,21 +213,21 @@ public function testInputFromRawb64String(): void self::assertSame(str_replace("\n", "", $pdfBytes), str_replace("\n", "", base64_encode($contents[1]))); } - public function testShouldNotRaiseMimeErrorForBrokenFixablePDF(): void + public function testShouldNotRaiseMimeErrorForBrokenFixablePdf(): void { $this->expectNotToPerformAssertions(); $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . '/pdf/broken_fixable.pdf', true); } - public function testShouldRaiseErrorForBrokenUnfixablePDF(): void + public function testShouldRaiseErrorForBrokenUnfixablePdf(): void { $this->expectException(MindeeSourceException::class); $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . '/pdf/broken_unfixable.pdf', true); } - public function testShouldSendCorrectResultsForBrokenFixableInvoicePDF(): void + public function testShouldSendCorrectResultsForBrokenFixableInvoicePdf(): void { $sourceDocOriginal = $this->dummyClient->sourceFromPath( TestingUtilities::getV1DataDir() . '/products/invoices/invoice.pdf' @@ -285,7 +285,7 @@ public function testDirectImageQualityCompression(): void self::assertGreaterThan($compressSize[1], $compressSize[10]); } - public function testPDFSourceText(): void + public function testPdfSourceText(): void { $imageInput = $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . '/receipt.jpg'); $pdfEmptyInput = $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf'); @@ -295,7 +295,7 @@ public function testPDFSourceText(): void self::assertFalse($imageInput->hasSourceText(), "An image should not have any text."); } - public function testCompressPDFFromInputSource(): void + public function testCompressPdfFromInputSource(): void { $pdfInput = $this->dummyClient->sourceFromPath( TestingUtilities::getFileTypesDir() . "/pdf/not_blank_image_only.pdf" @@ -319,7 +319,7 @@ public function testCompressPDFFromInputSource(): void self::assertLessThan($sizeOriginal, $sizeCompressed); } - public function testCompressPDFFromCompressor(): void + public function testCompressPdfFromCompressor(): void { $pdfInput = $this->dummyClient->sourceFromPath( TestingUtilities::getV1DataDir() . '/products/invoice_splitter/default_sample.pdf' @@ -328,10 +328,10 @@ public function testCompressPDFFromCompressor(): void self::assertFalse($pdfInput->hasSourceText()); $pdfCompresses = [ - 85 => PDFCompressor::compress($pdfInput->fileObject), - 75 => PDFCompressor::compress($pdfInput->fileObject, 75), - 50 => PDFCompressor::compress($pdfInput->fileObject, 50), - 10 => PDFCompressor::compress($pdfInput->fileObject, 10), + 85 => PdfCompressor::compress($pdfInput->fileObject), + 75 => PdfCompressor::compress($pdfInput->fileObject, 75), + 50 => PdfCompressor::compress($pdfInput->fileObject, 50), + 10 => PdfCompressor::compress($pdfInput->fileObject, 10), ]; $outputFiles = [ 85 => TestingUtilities::getRootDataDir() . "/output/compress_direct_85.pdf", @@ -354,7 +354,7 @@ public function testCompressPDFFromCompressor(): void self::assertGreaterThan($compressSize[10], $compressSize[50]); } - public function testSourceTextPDFCompression(): void + public function testSourceTextPdfCompression(): void { $pdfInput = $this->dummyClient->sourceFromPath( @@ -374,7 +374,7 @@ public function testSourceTextPDFCompression(): void self::assertSame( str_repeat('*', 650), - implode('', str_replace(" ", "", PDFUtils::extractPagesTextElements(TestingUtilities::getRootDataDir() . "/output/text_multipage.pdf"))) + implode('', str_replace(" ", "", PdfUtils::extractPagesTextElements(TestingUtilities::getRootDataDir() . "/output/text_multipage.pdf"))) ); } } diff --git a/tests/Input/URLInputSourceTest.php b/tests/Input/UrlInputSourceTest.php similarity index 79% rename from tests/Input/URLInputSourceTest.php rename to tests/Input/UrlInputSourceTest.php index 275991d3..272a9611 100644 --- a/tests/Input/URLInputSourceTest.php +++ b/tests/Input/UrlInputSourceTest.php @@ -5,13 +5,13 @@ namespace Input; use Mindee\Error\MindeeSourceException; -use Mindee\Input\URLInputSource; +use Mindee\Input\UrlInputSource; use Mindee\V1\Client; use PHPUnit\Framework\TestCase; -use const Mindee\V1\HTTP\API_KEY_ENV_NAME; +use const Mindee\V1\Http\API_KEY_ENV_NAME; -class URLInputSourceTest extends TestCase +class UrlInputSourceTest extends TestCase { private string $oldKey; protected Client $dummyClient; @@ -27,16 +27,16 @@ protected function tearDown(): void putenv('MINDEE_API_KEY=' . $this->oldKey); } - public function testInputFromHTTPShouldNotThrow(): void + public function testInputFromHttpShouldNotThrow(): void { $inputDoc = $this->dummyClient->sourceFromUrl("https://example.com/invoice.pdf"); - self::assertInstanceOf(URLInputSource::class, $inputDoc); + self::assertInstanceOf(UrlInputSource::class, $inputDoc); } - public function testInputFromHTTPShouldThrow(): void + public function testInputFromHttpShouldThrow(): void { $this->expectException(MindeeSourceException::class); - new URLInputSource(url: "http://example.com/invoice.pdf"); + new UrlInputSource(url: "http://example.com/invoice.pdf"); } public function testDownloadFileFails(): void diff --git a/tests/V1/CLI/MindeeCLICommandTest.php b/tests/V1/CLI/MindeeCLICommandTest.php index b918fb04..9d9cde6e 100644 --- a/tests/V1/CLI/MindeeCLICommandTest.php +++ b/tests/V1/CLI/MindeeCLICommandTest.php @@ -24,7 +24,7 @@ public function testInvalidFilePath(): void { $cmdOutput = MindeeCLITestingUtilities::executeTest(["financial-document", "invalid-file-path", "-k", $this->apiKey, "-D"]); self::assertSame(1, $cmdOutput["code"]); - self::assertTrue(str_contains($cmdOutput["output"][0], "Invalid path or url provided 'invalid-file-path'.")); + self::assertTrue(str_contains((string) $cmdOutput["output"][0], "Invalid path or url provided 'invalid-file-path'.")); } public function testInvalidKey(): void @@ -38,6 +38,6 @@ public function testInvalidProduct(): void { $cmdOutput = MindeeCLITestingUtilities::executeTest(["invalid-product", $this->filePath, "-k", "invalid-key", "-D"]); self::assertSame(1, $cmdOutput["code"]); - self::assertTrue(str_contains($cmdOutput["output"][0], "Invalid product: invalid-product")); + self::assertTrue(str_contains((string) $cmdOutput["output"][0], "Invalid product: invalid-product")); } } diff --git a/tests/V1/CLI/MindeeCLICommandTestFunctional.php b/tests/V1/CLI/MindeeCLICommandTestFunctional.php index 5dc870ea..ec066319 100644 --- a/tests/V1/CLI/MindeeCLICommandTestFunctional.php +++ b/tests/V1/CLI/MindeeCLICommandTestFunctional.php @@ -62,7 +62,7 @@ public function testProduct($productName, $async, $additionnalArgs = []): void $cmdOutput = $this->runValidCall($productName, $async, $additionnalArgs); self::assertSame(0, $cmdOutput["code"], $productName . ($async ? " async" : " sync") . " test (code)."); self::assertTrue( - str_contains($cmdOutput["output"][1], "Document"), + str_contains((string) $cmdOutput["output"][1], "Document"), $productName . ($async ? " async" : " sync") . " test (string return)." ); } diff --git a/tests/V1/Error/MindeeHttpExceptionTest.php b/tests/V1/Error/MindeeHttpExceptionTest.php index 4b7193bc..16cd1eb7 100644 --- a/tests/V1/Error/MindeeHttpExceptionTest.php +++ b/tests/V1/Error/MindeeHttpExceptionTest.php @@ -27,31 +27,31 @@ protected function setUp(): void ); } - public function testHTTPClientErrorShouldRaise(): void + public function testHttpClientErrorShouldRaise(): void { $this->expectException(MindeeHttpClientException::class); $this->dummyClient->parse(InvoiceV4::class, $this->dummyFile); } - public function testHTTPEnqueueClientException(): void + public function testHttpEnqueueClientException(): void { $this->expectException(MindeeHttpClientException::class); $this->dummyClient->enqueue(InvoiceV4::class, $this->dummyFile); } - public function testHTTPParseClientException(): void + public function testHttpParseClientException(): void { $this->expectException(MindeeHttpClientException::class); $this->dummyClient->enqueue(InvoiceV4::class, $this->dummyFile); } - public function testHTTPEnqueueAndParseClientException(): void + public function testHttpEnqueueAndParseClientException(): void { $this->expectException(MindeeHttpClientException::class); $this->dummyClient->enqueueAndParse(InvoiceV4::class, $this->dummyFile); } - public function testHTTP400Exception(): void + public function testHttp400Exception(): void { $json = file_get_contents($this->errorDir . "error_400_no_details.json"); $errorObj = ["data" => json_decode($json, true), "code" => 400]; @@ -64,7 +64,7 @@ public function testHTTP400Exception(): void throw $error400; } - public function testHTTP401Exception(): void + public function testHttp401Exception(): void { $json = file_get_contents($this->errorDir . "error_401_invalid_token.json"); $errorObj = ["data" => json_decode($json, true), "code" => 401]; @@ -77,7 +77,7 @@ public function testHTTP401Exception(): void throw $error401; } - public function testHTTP429Exception(): void + public function testHttp429Exception(): void { $json = file_get_contents($this->errorDir . "error_429_too_many_requests.json"); $errorObj = ["data" => json_decode($json, true), "code" => 429]; @@ -90,7 +90,7 @@ public function testHTTP429Exception(): void throw $error429; } - public function testHTTP500Exception(): void + public function testHttp500Exception(): void { $json = file_get_contents($this->errorDir . "error_500_inference_fail.json"); $errorObj = ["data" => json_decode($json, true), "code" => 500]; @@ -103,7 +103,7 @@ public function testHTTP500Exception(): void throw $error500; } - public function testHTTP500HTMLError(): void + public function testHttp500HTMLError(): void { $errorRefContents = file_get_contents($this->errorDir . "error_50x.html"); $error500 = MindeeHttpException::handleError("dummy-url", ["data" => $errorRefContents, "code" => 500]); diff --git a/tests/V1/Extraction/ImageExtractorTest.php b/tests/V1/Extraction/ImageExtractorTest.php index 380af8fe..a2a1e3fc 100644 --- a/tests/V1/Extraction/ImageExtractorTest.php +++ b/tests/V1/Extraction/ImageExtractorTest.php @@ -86,7 +86,7 @@ public function testGivenAnImageShouldExtractValueFields(): void } } - public function testGivenAPDFShouldExtractPositionFields(): void + public function testGivenAPdfShouldExtractPositionFields(): void { $imageInput = new PathInput( TestingUtilities::getV1DataDir() . "/products/multi_receipts_detector/multipage_sample.pdf" diff --git a/tests/V1/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php b/tests/V1/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php index 5097b008..5ee29e77 100644 --- a/tests/V1/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php +++ b/tests/V1/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php @@ -4,7 +4,7 @@ namespace V1\Extraction; -use Mindee\Extraction\PDFExtractor; +use Mindee\Extraction\PdfExtractor; use Mindee\Input\PathInput; use Mindee\V1\Client; use Mindee\V1\Parsing\Common\Document; @@ -32,7 +32,7 @@ private function prepareInvoiceReturn(string $rstFilePath, Document $invoicePred * * @group functional */ - public function testPDFShouldExtractInvoicesStrict(): void + public function testPdfShouldExtractInvoicesStrict(): void { $client = new Client(); $invoiceSplitterInput = new PathInput( @@ -40,7 +40,7 @@ public function testPDFShouldExtractInvoicesStrict(): void ); $response = $client->enqueueAndParse(InvoiceSplitterV1::class, $invoiceSplitterInput); $inference = $response->document->inference; - $pdfExtractor = new PDFExtractor($invoiceSplitterInput); + $pdfExtractor = new PdfExtractor($invoiceSplitterInput); self::assertSame(2, $pdfExtractor->getPageCount()); $extractedPdfsStrict = $pdfExtractor->extractInvoices($inference->prediction->invoicePageGroups); diff --git a/tests/V1/Extraction/PDFExtractorTest.php b/tests/V1/Extraction/PdfExtractorTest.php similarity index 58% rename from tests/V1/Extraction/PDFExtractorTest.php rename to tests/V1/Extraction/PdfExtractorTest.php index aa1c516b..9c2d6ef2 100644 --- a/tests/V1/Extraction/PDFExtractorTest.php +++ b/tests/V1/Extraction/PdfExtractorTest.php @@ -4,7 +4,7 @@ namespace V1\Extraction; -use Mindee\Extraction\PDFExtractor; +use Mindee\Extraction\PdfExtractor; use Mindee\Input\LocalResponse; use Mindee\Input\PathInput; use Mindee\V1\Client; @@ -12,7 +12,7 @@ use PHPUnit\Framework\TestCase; use TestingUtilities; -class PDFExtractorTest extends TestCase +class PdfExtractorTest extends TestCase { private Client $dummyClient; @@ -20,56 +20,56 @@ protected function setUp(): void { $this->dummyClient = new Client("dummy-key"); } - public function testGivenAnImageShouldExtractAPDF(): void + public function testGivenAnImageShouldExtractAPdf(): void { $jpg = TestingUtilities::getV1DataDir() . "/products/invoices/default_sample.jpg"; $localInput = new PathInput($jpg); - self::assertFalse($localInput->isPDF()); - $extractor = new PDFExtractor($localInput); + self::assertFalse($localInput->isPdf()); + $extractor = new PdfExtractor($localInput); self::assertSame(1, $extractor->getPageCount()); } /** * */ - public function testGivenAPDFShouldExtractInvoicesNoStrict(): void + public function testGivenAPdfShouldExtractInvoicesNoStrict(): void { $pdf = new PathInput(TestingUtilities::getV1DataDir() . "/products/invoice_splitter/invoice_5p.pdf"); $response = $this->getPrediction(); self::assertNotNull($response); $inference = $response->document->inference; - $extractor = new PDFExtractor($pdf); + $extractor = new PdfExtractor($pdf); self::assertSame(5, $extractor->getPageCount()); - $extractedPDFSNoStrict = $extractor->extractInvoices($inference->prediction->invoicePageGroups); - self::assertCount(3, $extractedPDFSNoStrict); - self::assertSame("invoice_5p_001-001.pdf", $extractedPDFSNoStrict[0]->getFileName()); - self::assertSame(1, $extractedPDFSNoStrict[0]->getPageCount()); - self::assertSame("invoice_5p_002-004.pdf", $extractedPDFSNoStrict[1]->getFileName()); - self::assertSame(3, $extractedPDFSNoStrict[1]->getPageCount()); - self::assertSame("invoice_5p_005-005.pdf", $extractedPDFSNoStrict[2]->getFileName()); - self::assertSame(1, $extractedPDFSNoStrict[2]->getPageCount()); + $extractedPdfSNoStrict = $extractor->extractInvoices($inference->prediction->invoicePageGroups); + self::assertCount(3, $extractedPdfSNoStrict); + self::assertSame("invoice_5p_001-001.pdf", $extractedPdfSNoStrict[0]->getFileName()); + self::assertSame(1, $extractedPdfSNoStrict[0]->getPageCount()); + self::assertSame("invoice_5p_002-004.pdf", $extractedPdfSNoStrict[1]->getFileName()); + self::assertSame(3, $extractedPdfSNoStrict[1]->getPageCount()); + self::assertSame("invoice_5p_005-005.pdf", $extractedPdfSNoStrict[2]->getFileName()); + self::assertSame(1, $extractedPdfSNoStrict[2]->getPageCount()); } /** * */ - public function testGivenAPDFShouldExtractInvoicesStrict(): void + public function testGivenAPdfShouldExtractInvoicesStrict(): void { $pdf = new PathInput(TestingUtilities::getV1DataDir() . "/products/invoice_splitter/invoice_5p.pdf"); $response = $this->getPrediction(); self::assertNotNull($response); $inference = $response->document->inference; - $extractor = new PDFExtractor($pdf); + $extractor = new PdfExtractor($pdf); self::assertSame(5, $extractor->getPageCount()); - $extractedPDFStrict = $extractor->extractInvoices($inference->prediction->invoicePageGroups, true); - self::assertCount(2, $extractedPDFStrict); - self::assertSame("invoice_5p_001-001.pdf", $extractedPDFStrict[0]->getFileName()); - self::assertSame(1, $extractedPDFStrict[0]->getPageCount()); - self::assertSame("invoice_5p_002-005.pdf", $extractedPDFStrict[1]->getFileName()); - self::assertSame(4, $extractedPDFStrict[1]->getPageCount()); + $extractedPdfStrict = $extractor->extractInvoices($inference->prediction->invoicePageGroups, true); + self::assertCount(2, $extractedPdfStrict); + self::assertSame("invoice_5p_001-001.pdf", $extractedPdfStrict[0]->getFileName()); + self::assertSame(1, $extractedPdfStrict[0]->getPageCount()); + self::assertSame("invoice_5p_002-005.pdf", $extractedPdfStrict[1]->getFileName()); + self::assertSame(4, $extractedPdfStrict[1]->getPageCount()); } private function getPrediction() diff --git a/tests/V1/Http/MindeeApiTest.php b/tests/V1/Http/MindeeApiTest.php index 4cb8af19..e958ad3c 100644 --- a/tests/V1/Http/MindeeApiTest.php +++ b/tests/V1/Http/MindeeApiTest.php @@ -5,12 +5,12 @@ namespace V1\Http; use Mindee\Error\MindeeException; -use Mindee\V1\HTTP\MindeeAPI; +use Mindee\V1\Http\MindeeApi; use Mindee\V1\Product\InvoiceSplitter\InvoiceSplitterV1; use PHPUnit\Framework\TestCase; use Mindee\V1\Client; -use const Mindee\V1\HTTP\API_KEY_ENV_NAME; +use const Mindee\V1\Http\API_KEY_ENV_NAME; class MindeeApiTest extends TestCase { @@ -27,7 +27,7 @@ protected function tearDown(): void public function testGivenOTSParametersAProperMindeeApiObjectShouldBeCreated(): void { - $settings = new MindeeAPI("my-api-key", InvoiceSplitterV1::$endpointName); + $settings = new MindeeApi("my-api-key", InvoiceSplitterV1::$endpointName); self::assertSame("my-api-key", $settings->apiKey); self::assertSame(InvoiceSplitterV1::$endpointName, $settings->endpointName); self::assertSame(Client::DEFAULT_OWNER, $settings->accountName); @@ -36,7 +36,7 @@ public function testGivenOTSParametersAProperMindeeApiObjectShouldBeCreated(): v public function testGivenCustomParametersAProperMindeeApiObjectShouldBeCreated(): void { - $settings = new MindeeAPI("my-api-key", "custom-endpoint-name", "custom-owner-name", "1.3"); + $settings = new MindeeApi("my-api-key", "custom-endpoint-name", "custom-owner-name", "1.3"); self::assertSame("my-api-key", $settings->apiKey); self::assertSame("custom-endpoint-name", $settings->endpointName); self::assertSame("custom-owner-name", $settings->accountName); @@ -47,6 +47,6 @@ public function testGivenInvalidApiKeyAnExceptionShouldBeThrown(): void { $this->expectException(MindeeException::class); putenv(API_KEY_ENV_NAME . '='); - new MindeeAPI(null, InvoiceSplitterV1::$endpointName); + new MindeeApi(null, InvoiceSplitterV1::$endpointName); } } diff --git a/tests/V1/Input/URLInputSourceTestFunctional.php b/tests/V1/Input/UrlInputSourceTestFunctional.php similarity index 97% rename from tests/V1/Input/URLInputSourceTestFunctional.php rename to tests/V1/Input/UrlInputSourceTestFunctional.php index b672f42f..d95ec9c9 100644 --- a/tests/V1/Input/URLInputSourceTestFunctional.php +++ b/tests/V1/Input/UrlInputSourceTestFunctional.php @@ -9,7 +9,7 @@ use PHPUnit\Framework\TestCase; use TestingUtilities; -class URLInputSourceTestFunctional extends TestCase +class UrlInputSourceTestFunctional extends TestCase { protected Client $client; protected string $outputFilePath; diff --git a/tests/V1/Parsing/Common/AsyncPredictResponseTest.php b/tests/V1/Parsing/Common/AsyncPredictResponseTest.php index eddb9966..25c3cba1 100644 --- a/tests/V1/Parsing/Common/AsyncPredictResponseTest.php +++ b/tests/V1/Parsing/Common/AsyncPredictResponseTest.php @@ -4,7 +4,7 @@ namespace V1\Parsing\Common; -use Mindee\V1\HTTP\ResponseValidation; +use Mindee\V1\Http\ResponseValidation; use Mindee\V1\Parsing\Common\AsyncPredictResponse; use Mindee\V1\Product\InvoiceSplitter\InvoiceSplitterV1; use PHPUnit\Framework\TestCase; diff --git a/tests/V1/Parsing/Common/Extras/ExtrasIntegrationFunctional.php b/tests/V1/Parsing/Common/Extras/ExtrasIntegrationFunctional.php index 1e96dbee..60654471 100644 --- a/tests/V1/Parsing/Common/Extras/ExtrasIntegrationFunctional.php +++ b/tests/V1/Parsing/Common/Extras/ExtrasIntegrationFunctional.php @@ -40,7 +40,7 @@ public function testShouldSendCropperExtra(): void self::assertGreaterThan(0, count($response->document->inference->pages[0]->extras->cropper->croppings)); } - public function testShouldSendFullTextOCRExtra(): void + public function testShouldSendFullTextOcrExtra(): void { $sample = $this->client->sourceFromPath( TestingUtilities::getV1DataDir() . "/products/international_id/default_sample.jpg" @@ -52,6 +52,6 @@ public function testShouldSendFullTextOCRExtra(): void $response = $this->client->enqueueAndParse(InternationalIdV2::class, $sample, $predictMethodOptions); self::assertNotNull($response->document->extras->fullTextOcr); - self::assertGreaterThan(10, strlen($response->document->extras->fullTextOcr->content)); + self::assertGreaterThan(10, strlen((string) $response->document->extras->fullTextOcr->content)); } } diff --git a/tests/V1/Parsing/Common/Extras/FullTextOCRExtraTest.php b/tests/V1/Parsing/Common/Extras/FullTextOcrExtraTest.php similarity index 91% rename from tests/V1/Parsing/Common/Extras/FullTextOCRExtraTest.php rename to tests/V1/Parsing/Common/Extras/FullTextOcrExtraTest.php index eb90ab63..2594f049 100644 --- a/tests/V1/Parsing/Common/Extras/FullTextOCRExtraTest.php +++ b/tests/V1/Parsing/Common/Extras/FullTextOcrExtraTest.php @@ -10,7 +10,7 @@ use PHPUnit\Framework\TestCase; use TestingUtilities; -class FullTextOCRExtraTest extends TestCase +class FullTextOcrExtraTest extends TestCase { private $extrasDir; @@ -27,7 +27,7 @@ private function loadDocument() return $response->document; } - public function testGetsFullTextOCRResult(): void + public function testGetsFullTextOcrResult(): void { $expectedText = file_get_contents($this->extrasDir . '/full_text_ocr/full_text_ocr.txt'); diff --git a/tests/V1/Parsing/Common/OCR/OCRTest.php b/tests/V1/Parsing/Common/Ocr/OcrTest.php similarity index 88% rename from tests/V1/Parsing/Common/OCR/OCRTest.php rename to tests/V1/Parsing/Common/Ocr/OcrTest.php index 1fa20a6d..74b492d3 100644 --- a/tests/V1/Parsing/Common/OCR/OCRTest.php +++ b/tests/V1/Parsing/Common/Ocr/OcrTest.php @@ -2,22 +2,22 @@ declare(strict_types=1); -namespace V1\Parsing\Common\OCR; +namespace V1\Parsing\Common\Ocr; -use Mindee\V1\Parsing\Common\OCR\OCR; +use Mindee\V1\Parsing\Common\Ocr\Ocr; use PHPUnit\Framework\TestCase; use TestingUtilities; -class OCRTest extends TestCase +class OcrTest extends TestCase { - private OCR $ocrObject; + private Ocr $ocrObject; protected function setup(): void { $json = file_get_contents( TestingUtilities::getV1DataDir() . "/extras/ocr/complete.json" ); $jsonData = json_decode($json, true); - $this->ocrObject = new OCR($jsonData["document"]["ocr"]); + $this->ocrObject = new Ocr($jsonData["document"]["ocr"]); } public function testResponse(): void { diff --git a/tests/V2/ClientV2Test.php b/tests/V2/ClientV2Test.php index 6ff0e62a..83993d69 100644 --- a/tests/V2/ClientV2Test.php +++ b/tests/V2/ClientV2Test.php @@ -9,7 +9,7 @@ use Mindee\Input\LocalResponse; use Mindee\Input\PathInput; use Mindee\V2\Client; -use Mindee\V2\HTTP\MindeeAPIV2; +use Mindee\V2\Http\MindeeApiV2; use Mindee\V2\Parsing\JobResponse; use Mindee\V2\Product\Extraction\ExtractionResponse; use Mindee\V2\Product\Extraction\Params\ExtractionParameters; @@ -20,19 +20,18 @@ class ClientV2Test extends TestCase { - private static function makeClientWithMockedApi(MindeeAPIV2 $mockedApi): Client + private static function makeClientWithMockedApi(MindeeApiV2 $mockedApi): Client { $client = new Client("dummy"); $reflection = new ReflectionClass($client); $property = $reflection->getProperty('mindeeApi'); - $property->setAccessible(true); $property->setValue($client, $mockedApi); return $client; } public function testEnqueuePostAsync(): void { - $predictable = $this->createMock(MindeeAPIV2::class); + $predictable = $this->createMock(MindeeApiV2::class); $syntheticResponse = file_get_contents(TestingUtilities::getV2DataDir() . '/job/ok_processing.json'); $predictable->expects(self::once()) ->method('reqPostEnqueue') @@ -55,8 +54,8 @@ public function testEnqueuePostAsync(): void public function testDocumentGetJobAsync(): void { - /** @var MindeeAPIV2&MockObject $predictable */ - $predictable = $this->createMock(MindeeAPIV2::class); + /** @var MindeeApiV2&MockObject $predictable */ + $predictable = $this->createMock(MindeeApiV2::class); $syntheticResponse = file_get_contents(TestingUtilities::getV2DataDir() . '/job/ok_processing.json'); $processing = new JobResponse(json_decode($syntheticResponse, true)); @@ -76,8 +75,8 @@ public function testDocumentGetJobAsync(): void public function testDocumentGetInferenceAsync(): void { - /** @var MindeeAPIV2&MockObject $predictable */ - $predictable = $this->createMock(MindeeAPIV2::class); + /** @var MindeeApiV2&MockObject $predictable */ + $predictable = $this->createMock(MindeeApiV2::class); $jsonFile = TestingUtilities::getV2DataDir() . '/products/extraction/financial_document/complete.json'; self::assertFileExists($jsonFile, 'Test resource file must exist'); diff --git a/tests/V2/ClientV2TestFunctional.php b/tests/V2/ClientV2TestFunctional.php index c532676b..6c26449e 100644 --- a/tests/V2/ClientV2TestFunctional.php +++ b/tests/V2/ClientV2TestFunctional.php @@ -6,7 +6,7 @@ use Mindee\Error\MindeeV2HttpException; use Mindee\Input\PathInput; -use Mindee\Input\URLInputSource; +use Mindee\Input\UrlInputSource; use Mindee\V2\Client; use Mindee\V2\Product\Extraction\ExtractionResponse; use Mindee\V2\Product\Extraction\Params\ExtractionParameters; @@ -164,7 +164,7 @@ public function testInvalidWebhookIDsMustThrowError(): void public function testUrlInputSourceMustNotRaiseErrors(): void { - $urlSource = new URLInputSource(getenv('MINDEE_V2_SE_TESTS_BLANK_PDF_URL')); + $urlSource = new UrlInputSource(getenv('MINDEE_V2_SE_TESTS_BLANK_PDF_URL')); $inferenceParams = new ExtractionParameters($this->modelId); @@ -227,7 +227,7 @@ public function testMultipleWebhooksMustSucceed(): void $inferenceParams = new ExtractionParameters( $this->modelId, - webhooksIds: [ + webhookIds: [ getenv('MINDEE_V2_FAILURE_WEBHOOK_ID'), getenv('MINDEE_V2_SE_TESTS_FAILURE_WEBHOOK_ID')] ); diff --git a/tests/V2/FileOperations/CropFunctional.php b/tests/V2/FileOperations/CropFunctional.php index 66de7fa7..d0ce95b8 100644 --- a/tests/V2/FileOperations/CropFunctional.php +++ b/tests/V2/FileOperations/CropFunctional.php @@ -93,7 +93,7 @@ public function testExtractCropsFromImageCorrectly(): void self::assertLessThanOrEqual(103000, $file2Info); } - public function testExtractCropsFromEachPDFPageCorrectly(): void + public function testExtractCropsFromEachPdfPageCorrectly(): void { $inputSource = new PathInput(TestingUtilities::getV2ProductDir() . '/crop/multipage_sample.pdf'); $cropParams = new CropParameters($this->cropModelId); diff --git a/tests/V2/FileOperations/SplitFunctional.php b/tests/V2/FileOperations/SplitFunctional.php index 39314f38..16ca313e 100644 --- a/tests/V2/FileOperations/SplitFunctional.php +++ b/tests/V2/FileOperations/SplitFunctional.php @@ -60,7 +60,7 @@ private function checkFindocReturn(ExtractionResponse $findocResponse): void self::assertGreaterThan(0, $totalAmount->value); } - public function testExtractSplitsFromPDFCorrectly(): void + public function testExtractSplitsFromPdfCorrectly(): void { $inputSource = new PathInput(TestingUtilities::getV2ProductDir() . '/split/default_sample.pdf'); $splitParams = new SplitParameters($this->splitModelId); diff --git a/tests/V2/Input/LocalResponseV2Test.php b/tests/V2/Input/LocalResponseV2Test.php index 2d3dc131..1109af1f 100644 --- a/tests/V2/Input/LocalResponseV2Test.php +++ b/tests/V2/Input/LocalResponseV2Test.php @@ -25,7 +25,6 @@ protected function assertLocalResponse(LocalResponse $localResponse): void $signature = "e51bdf80f1a08ed44ee161100fc30a25cb35b4ede671b0a575dc9064a3f5dbf1"; $reflectedLocalResponse = new ReflectionClass($localResponse); $reflectedFile = $reflectedLocalResponse->getProperty('file'); - $reflectedFile->setAccessible(true); self::assertNotNull($reflectedFile); self::assertFalse($localResponse->isValidHMACSignature($fakeHMACSigning, "fake HMAC signature")); self::assertSame($signature, $localResponse->getHmacSignature($fakeHMACSigning)); diff --git a/tests/V2/Parsing/ExtractionResponseTest.php b/tests/V2/Parsing/ExtractionResponseTest.php index d80503a1..b06d6522 100644 --- a/tests/V2/Parsing/ExtractionResponseTest.php +++ b/tests/V2/Parsing/ExtractionResponseTest.php @@ -252,7 +252,7 @@ public function testStandardFieldTypesMustExposeCorrectTypes(): void self::assertInstanceOf(ObjectField::class, $fieldObject); $fieldObjectFields = $fieldObject->fields; self::assertCount(2, $fieldObjectFields); - foreach ($fieldObjectFields as $fieldName => $subField) { + foreach ($fieldObjectFields as $subField) { self::assertInstanceOf(SimpleField::class, $subField); } diff --git a/tests/V2/Product/OCRFunctional.php b/tests/V2/Product/OcrFunctional.php similarity index 75% rename from tests/V2/Product/OCRFunctional.php rename to tests/V2/Product/OcrFunctional.php index 25517311..ed870e60 100644 --- a/tests/V2/Product/OCRFunctional.php +++ b/tests/V2/Product/OcrFunctional.php @@ -6,14 +6,14 @@ use Mindee\Input\PathInput; use Mindee\V2\Client; -use Mindee\V2\Product\OCR\OCRResponse; -use Mindee\V2\Product\OCR\Params\OCRParameters; +use Mindee\V2\Product\Ocr\OcrResponse; +use Mindee\V2\Product\Ocr\Params\OcrParameters; use PHPUnit\Framework\TestCase; use TestingUtilities; require_once(__DIR__ . "/../../TestingUtilities.php"); -class OCRFunctional extends TestCase +class OcrFunctional extends TestCase { private Client $client; private string $ocrModelId; @@ -27,17 +27,17 @@ protected function setUp(): void } /** - * Tests the success of the OCR process using a default sample file. + * Tests the success of the Ocr process using a default sample file. * */ - public function testOCRDefaultSampleMustSucceed(): void + public function testOcrDefaultSampleMustSucceed(): void { $inputSource = new PathInput( TestingUtilities::getV2ProductDir() . '/ocr/default_sample.jpg' ); - $productParams = new OCRParameters($this->ocrModelId); - $response = $this->client->enqueueAndGetResult(OCRResponse::class, $inputSource, $productParams); + $productParams = new OcrParameters($this->ocrModelId); + $response = $this->client->enqueueAndGetResult(OcrResponse::class, $inputSource, $productParams); self::assertNotNull($response); self::assertNotNull($response->inference); diff --git a/tests/V2/Product/OCRTest.php b/tests/V2/Product/OcrTest.php similarity index 88% rename from tests/V2/Product/OCRTest.php rename to tests/V2/Product/OcrTest.php index 3ff0a7ff..66d9a667 100644 --- a/tests/V2/Product/OCRTest.php +++ b/tests/V2/Product/OcrTest.php @@ -6,14 +6,14 @@ use PHPUnit\Framework\TestCase; use TestingUtilities; -use Mindee\V2\Product\OCR\OCRResponse; +use Mindee\V2\Product\Ocr\OcrResponse; require_once(__DIR__ . "/../../TestingUtilities.php"); /** - * OCR unit tests. + * Ocr unit tests. */ -class OCRTest extends TestCase +class OcrTest extends TestCase { /** * Load a JSON sample and return its decoded contents. @@ -41,12 +41,12 @@ private function assertInferenceResponse(mixed $response): void } /** - * Should correctly map properties when reading a single OCR JSON. + * Should correctly map properties when reading a single Ocr JSON. */ - public function testOCRWhenSingleMustHaveValidProperties(): void + public function testOcrWhenSingleMustHaveValidProperties(): void { $jsonSample = self::getInference("ocr/ocr_single.json"); - $response = new OCRResponse($jsonSample); + $response = new OcrResponse($jsonSample); $this->assertInferenceResponse($response); @@ -76,12 +76,12 @@ public function testOCRWhenSingleMustHaveValidProperties(): void } /** - * Should correctly map properties when reading a multiple OCR JSON. + * Should correctly map properties when reading a multiple Ocr JSON. */ - public function testOCRWhenMultipleMustHaveValidProperties(): void + public function testOcrWhenMultipleMustHaveValidProperties(): void { $jsonSample = self::getInference("ocr/ocr_multiple.json"); - $response = new OCRResponse($jsonSample); + $response = new OcrResponse($jsonSample); $this->assertInferenceResponse($response);