Skip to content

Commit d4e50d3

Browse files
fix all lvl 6 errors (untested)
1 parent 2f1b074 commit d4e50d3

102 files changed

Lines changed: 156 additions & 760 deletions

File tree

Some content is hidden

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

src/Extraction/ImageExtractor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function getPageCount(): int
131131
/**
132132
* Extract multiple images on a given page from a list of fields having position data.
133133
*
134-
* @param array<BaseField> $fields List of Fields to extract.
134+
* @param array<BaseField<mixed>> $fields List of Fields to extract.
135135
* @param integer $pageIndex The page index to extract, begins at 0.
136136
* @param null|string $outputName The base output filename, must have an image extension.
137137
*
@@ -215,7 +215,7 @@ public function extractPolygonFromPage(
215215
/**
216216
* Extracts a single image from a Position field.
217217
*
218-
* @param BaseField $field The field to extract.
218+
* @param BaseField<mixed> $field The field to extract.
219219
* @param integer $pageIndex The page index to extract, begins at 0.
220220
* @param integer $index The index to use for naming the extracted image.
221221
* @param string $filename The output filename.
@@ -265,7 +265,7 @@ public function getInputSource(): LocalInputSource
265265
/**
266266
* Extracts images from a page.
267267
*
268-
* @param array<BaseField> $fields List of Fields to extract.
268+
* @param array<BaseField<mixed>> $fields List of Fields to extract.
269269
* @param integer $pageIndex The page index to extract, begins at 0.
270270
* @param string $outputName Name of the created file.
271271
* @param string $format The output format.
@@ -316,7 +316,7 @@ protected function extractImageFromBbox(BBox $bbox, int|float $pageIndex): Imagi
316316
* Splits the filename into name and extension.
317317
*
318318
* @param string $filename Name of the file.
319-
* @return array An array containing the name and extension of the file.
319+
* @return array{0: string, 1: string} An array containing the name and extension of the file.
320320
*/
321321
protected static function splitNameStrict(string $filename): array
322322
{

src/Extraction/PDFExtractor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function getPageCount(): int
8686
/**
8787
* Extracts sub-documents from the source document using list of page indexes.
8888
*
89-
* @param array|InvoiceSplitterV1InvoicePageGroups $pageIndexes List of sub-lists of pages to keep.
89+
* @param array<array<integer>>|InvoiceSplitterV1InvoicePageGroups $pageIndexes List of sub-lists of pages to keep.
9090
*
9191
* @return ExtractedPDF[] list of extracted documents
9292
*
@@ -141,7 +141,7 @@ public function extractSubDocuments(mixed $pageIndexes): array
141141
/**
142142
* Extracts invoices as complete PDFs from the document.
143143
*
144-
* @param array|InvoiceSplitterV1InvoicePageGroups $pageIndexes List of sub-lists of pages to keep.
144+
* @param array<array<integer>>|InvoiceSplitterV1InvoicePageGroups $pageIndexes List of sub-lists of pages to keep.
145145
* @param boolean $strict Whether to trust confidence scores or not.
146146
*
147147
* @return ExtractedPDF[] a list of extracted invoices

src/Geometry/BBox.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ public function getMaxY(): float
8383
/**
8484
* Extends the BBox with the provided points.
8585
*
86-
* @param array|Polygon $points Series of points to add to the BBox.
86+
* @param array<Point>|Polygon $points Series of points to add to the BBox.
8787
*/
88-
public function extendWith(Polygon|array $points): void
88+
public function extendWith(mixed $points): void
8989
{
9090
if ($points instanceof Polygon) {
9191
$sequence = $points->getCoordinates();

src/Geometry/MinMaxUtils.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MinMaxUtils
2222
*/
2323
public static function getMinMaxY(mixed $points): MinMax
2424
{
25-
if (is_a(Polygon::class, $points)) {
25+
if ($points instanceof Polygon) {
2626
$points = $points->getCoordinates();
2727
}
2828
if (count($points) < 1) {
@@ -46,7 +46,7 @@ public static function getMinMaxY(mixed $points): MinMax
4646
*/
4747
public static function getMinMaxX(mixed $points): MinMax
4848
{
49-
if (is_a(Polygon::class, $points)) {
49+
if ($points instanceof Polygon) {
5050
$points = $points->getCoordinates();
5151
}
5252
if (count($points) < 1) {

src/Geometry/Polygon.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Polygon
2727
private MinMax $minMaxX;
2828

2929
/**
30-
* @param array<array<float|integer>>|null $coordinates Coordinates of the polygon as a set of Points.
30+
* @param array<array<float|integer>>|array<Point>|null $coordinates Coordinates of the polygon as a set of Points.
3131
*/
3232
public function __construct(?array $coordinates = null)
3333
{

src/Geometry/PolygonUtils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ abstract class PolygonUtils
2222
*/
2323
public static function getCentroid(mixed $vertices): Point
2424
{
25-
if (is_a(Polygon::class, $vertices)) {
25+
if ($vertices instanceof Polygon) {
2626
$vertices = $vertices->getCoordinates();
2727
}
2828
$verticesSum = count($vertices);

src/Input/LocalResponse.php

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,36 @@ class LocalResponse
2323
private $file;
2424

2525
/**
26-
* @param resource|string|array $inputFile A string, path or file-like object to load as a local response.
26+
* @param resource|string|array<string> $inputFile A string, path or file-like object to load as a local response.
2727
* @throws MindeeException Throws if the input file isn't acceptable.
2828
*/
2929
public function __construct(mixed $inputFile)
3030
{
31-
if (is_resource($inputFile) && get_resource_type($inputFile) === 'file') {
32-
$content = fread($inputFile, fstat($inputFile)['size']);
33-
$strStripped = str_replace(["\r", "\n"], '', $content);
34-
$this->file = fopen('php://memory', 'r+');
35-
fwrite($this->file, $strStripped);
36-
rewind($this->file);
37-
} elseif (is_resource($inputFile) && get_resource_type($inputFile) === 'stream') {
38-
$content = stream_get_contents($inputFile);
39-
$strStripped = str_replace(["\r", "\n"], '', $content);
40-
$this->file = fopen('php://memory', 'r+');
41-
fwrite($this->file, $strStripped);
42-
rewind($this->file);
43-
} elseif (is_string($inputFile) && file_exists($inputFile)) {
44-
$content = file_get_contents($inputFile);
45-
$strStripped = str_replace(["\r", "\n"], '', $content);
46-
$this->file = fopen('php://memory', 'r+');
47-
fwrite($this->file, $strStripped);
48-
rewind($this->file);
31+
if (is_resource($inputFile)) {
32+
$resourceType = get_resource_type($inputFile);
33+
if ($resourceType === 'file') {
34+
$content = fread($inputFile, fstat($inputFile)['size']);
35+
} elseif ($resourceType === 'stream') {
36+
$content = stream_get_contents($inputFile);
37+
} else {
38+
throw new MindeeException("Unsupported resource type.", ErrorCode::USER_INPUT_ERROR);
39+
}
4940
} elseif (is_string($inputFile)) {
50-
$strStripped = str_replace(["\r", "\n"], '', $inputFile);
51-
$this->file = fopen('php://memory', 'r+');
52-
fwrite($this->file, $strStripped);
53-
rewind($this->file);
54-
} elseif (is_string($inputFile) || is_array($inputFile)) {
55-
if (is_array($inputFile))
56-
{
57-
$inputFile = implode($inputFile);
41+
if (file_exists($inputFile) && is_file($inputFile)) {
42+
$content = file_get_contents($inputFile);
43+
} else {
44+
$content = $inputFile;
5845
}
59-
$strStripped = str_replace(["\r", "\n"], '', $inputFile);
60-
$this->file = fopen('php://memory', 'r+');
61-
fwrite($this->file, $strStripped);
62-
rewind($this->file);
46+
} elseif (is_array($inputFile)) {
47+
$content = implode('', $inputFile);
6348
} else {
64-
throw new MindeeException(
65-
"Incompatible type for input.",
66-
ErrorCode::USER_INPUT_ERROR
67-
);
49+
throw new MindeeException("Incompatible type for input.", ErrorCode::USER_INPUT_ERROR);
6850
}
51+
52+
$strStripped = str_replace(["\r", "\n"], '', (string) $content);
53+
$this->file = fopen('php://memory', 'r+');
54+
fwrite($this->file, $strStripped);
55+
rewind($this->file);
6956
}
7057

7158
/**

src/PDF/PDFUtils.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static function hasSourceText(string $pdfPath): bool
8585
* Extracts text elements with their properties from all pages in a PDF.
8686
*
8787
* @param string $pdfPath Path to the PDF file.
88-
* @return array<<integer, string>> A page-indexed array of text elements.
88+
* @return array<integer, string> A page-indexed array of text elements.
8989
* Each text element includes text content, position, font, size, and color.
9090
* @throws MindeePDFException Throws if the PDF can't be parsed or text elements can't be extracted.
9191
*/
@@ -192,7 +192,7 @@ public static function extractTextElements(Page $page): array
192192
* @param string $fontName Name of the font/subfont.
193193
* @return array{family: string, style: string} The standard font & possible style.
194194
*/
195-
private static function standardizeFontName(string $fontName): array
195+
protected static function standardizeFontName(string $fontName): array
196196
{
197197
$cleanName = preg_replace('/^.*?\+/', '', $fontName);
198198
$parts = explode('-', $cleanName, 2);

src/Parsing/SummaryHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static function formatForDisplay($inputString = null, ?int $maxColSize =
7777
return 'False';
7878
}
7979
$inputString = self::escapeSpecialChars($inputString);
80-
if (!$inputString || mb_strlen($inputString, "UTF-8") === 0) {
80+
if (!$inputString) {
8181
return "";
8282
}
8383
if (!isset($maxColSize)) {

src/V1/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private function constructEndpoint(
155155
string $endpointOwner,
156156
string $endpointVersion
157157
): Endpoint {
158-
$endpointVersion = $endpointVersion != null && strlen($endpointVersion) > 0 ? $endpointVersion : '1';
158+
$endpointVersion = $endpointVersion !== '' ? $endpointVersion : '1';
159159

160160
$endpointSettings = new MindeeAPI($this->apiKey, $endpointName, $endpointOwner, $endpointVersion);
161161

@@ -225,7 +225,7 @@ public function createEndpoint(string $endpointName, string $accountName, ?strin
225225
);
226226
}
227227
$accountName = $this->cleanAccountName($accountName);
228-
if (!$version || $version == '') {
228+
if (empty($version)) {
229229
error_log("Notice: no version provided for a custom build, will attempt to poll version 1 by default.");
230230
$version = "1";
231231
}

0 commit comments

Comments
 (0)