Skip to content

Commit 92d2bcc

Browse files
fix all formatting issue
1 parent 60e747e commit 92d2bcc

40 files changed

Lines changed: 75 additions & 83 deletions

.github/workflows/_static-analysis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ jobs:
3434
- name: Run lint
3535
run: |
3636
composer lint
37-
37+
38+
- name: Run PHPStan
39+
run: |
40+
composer phpstan

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
],
3535
"scripts": {
3636
"lint": "php-cs-fixer fix --dry-run --diff",
37-
"phpstan": "phpstan analyse src --level max",
37+
"phpstan": "phpstan analyse src --level 6",
3838
"format": "php-cs-fixer fix"
3939
}
4040
}

src/Extraction/ExtractedImage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function writeToFile(string $outputPath, ?string $format = null, int $qua
8585
$quality = min(100, max(0, $quality));
8686
if ('png' === $format) {
8787
$finalQuality = round($quality * 0.09);
88-
$this->image->setOption('png:compression-level', (string)$finalQuality);
88+
$this->image->setOption('png:compression-level', (string) $finalQuality);
8989
} elseif (in_array($format, ['jpg', 'jpeg'], true)) {
9090
$this->image->setImageCompression(Imagick::COMPRESSION_JPEG);
9191
}

src/Geometry/BBoxUtils.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,21 @@ public static function generateBBoxFromPolygon(Polygon $polygon): ?BBox
3030
/**
3131
* Generates a BBox from an array of polygons. Returns null if no polygons are provided.
3232
*
33-
* @param array<Polygon> $polygons Series of polygons to get the BBox of.
33+
* @param array<Polygon|null> $polygons Series of polygons to get the BBox of.
3434
*/
3535
public static function generateBBoxFromPolygons(array $polygons): ?BBox
3636
{
37-
if (!$polygons) {
38-
return null;
39-
}
40-
$merged = null;
37+
$bboxes = [];
38+
4139
foreach ($polygons as $polygon) {
42-
if (empty($polygon)) {
40+
if (null === $polygon || !$polygon->getCoordinates()) {
4341
continue;
44-
} else {
45-
if (empty($merged)) {
46-
$merged = $polygon;
47-
}
48-
}
49-
if ($merged !== $polygon) {
50-
$merged = PolygonUtils::merge($merged, $polygon);
5142
}
43+
44+
$bboxes[] = self::generateBBoxFromPolygon($polygon);
5245
}
53-
return new BBox(
54-
$merged->getMinX(),
55-
$merged->getMaxX(),
56-
$merged->getMinY(),
57-
$merged->getMaxY(),
58-
);
46+
47+
return self::mergeBBoxes($bboxes);
5948
}
6049

6150
/**

src/Geometry/PolygonUtils.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ abstract class PolygonUtils
1818
* Gets the centroid (Point) of a set of points.
1919
*
2020
* @param array<Point>|Polygon $vertices Array of points.
21-
* @return Point
2221
*/
2322
public static function getCentroid(mixed $vertices): Point
2423
{
@@ -49,7 +48,7 @@ public static function getCentroid(mixed $vertices): Point
4948
public static function compareOnY(Polygon $polygon1, Polygon $polygon2): int
5049
{
5150
$sort = ($polygon1->getMinY() - $polygon2->getMinY());
52-
if ($sort == 0) {
51+
if ($sort === 0.0) {
5352
return 0;
5453
}
5554
return $sort < 0 ? -1 : 1;

src/PDF/CustomFPDI.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ class CustomFPDI extends Fpdi
3030
*/
3131
public function rotate(float $angle, float $x = -1, float $y = -1): void
3232
{
33-
if ($x == -1) {
33+
if ((int) $x === -1) {
3434
$x = $this->x;
3535
}
36-
if ($y == -1) {
36+
if ((int) $y === -1) {
3737
$y = $this->y;
3838
}
3939

40-
if ((int) $angle != 0) {
40+
if ((int) $angle !== 0) {
4141
$angle = -$angle;
4242
}
4343
$angle *= M_PI / 180;
@@ -72,6 +72,7 @@ protected function _endpage(): void
7272
}
7373
parent::_endpage();
7474
}
75+
7576
/**
7677
* Starts a new transformation.
7778
*
@@ -80,6 +81,7 @@ public function startTransform(): void
8081
{
8182
$this->_out('q');
8283
}
84+
8385
/**
8486
* Stops the current transformation.
8587
*

src/PDF/PDFCompressor.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Imagick;
1919
use SplFileObject;
2020

21-
2221
/**
2322
* PDF compression class.
2423
*/

src/PDF/PDFUtils.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static function hasSourceText(string $pdfPath): bool
8686
*
8787
* @param string $pdfPath Path to the PDF file.
8888
* @return array<integer, string> A page-indexed array of text elements.
89-
* Each text element includes text content, position, font, size, and color.
89+
* 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
*/
9292
public static function extractPagesTextElements(string $pdfPath): array
@@ -153,7 +153,7 @@ public static function downgradePDFVersion(string $inputPath): string
153153
*
154154
* @param Page $page Page object.
155155
* @return array<array<string, string|float|Font|null>> An array of text elements, each containing text content,
156-
* position, font, size, and color.
156+
* position, font, size, and color.
157157
* @throws MindeePDFException Throws if the text elements can't be extracted.
158158
*/
159159
public static function extractTextElements(Page $page): array
@@ -169,11 +169,11 @@ public static function extractTextElements(Page $page): array
169169
if (isset($text[1])) {
170170
$textElements[] = [
171171
'text' => $text[1],
172-
'rotation' => rad2deg((float)($text[0][2])),
173-
'x' => (float)($text[0][4]),
174-
'y' => (float)($text[0][5]),
172+
'rotation' => rad2deg((float) ($text[0][2])),
173+
'x' => (float) ($text[0][4]),
174+
'y' => (float) ($text[0][5]),
175175
'font' => $page->getFont($text[2]),
176-
'size' => (float)($text[3]),
176+
'size' => (float) ($text[3]),
177177
];
178178
}
179179
}

src/Parsing/SummaryHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SummaryHelper
2020
*/
2121
public static function formatFloat(?float $number): string
2222
{
23-
if ($number === null) {
23+
if (null === $number) {
2424
return '';
2525
}
2626
$formatted = number_format($number, 5, '.', '');
@@ -54,7 +54,7 @@ public static function cleanOutString(string $inputString): string
5454
*/
5555
protected static function escapeSpecialChars(?string $string): ?string
5656
{
57-
if ($string == null) {
57+
if (null === $string) {
5858
return null;
5959
}
6060
$find = ["\n", "\t", "\r"];

src/V1/Client.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ public function parse(
407407
?PredictMethodOptions $options = null,
408408
?PageOptions $pageOptions = null
409409
): PredictResponse {
410-
if ($options == null) {
410+
if (null === $options) {
411411
$options = new PredictMethodOptions();
412412
}
413413
if ($pageOptions !== null && $inputDoc instanceof LocalInputSource && $inputDoc->isPDF()) {
@@ -437,10 +437,10 @@ public function enqueueAndParse(
437437
?PollingOptions $asyncOptions = null,
438438
?PageOptions $pageOptions = null
439439
): AsyncPredictResponse {
440-
if ($options == null) {
440+
if (null === $options) {
441441
$options = new PredictMethodOptions();
442442
}
443-
if ($asyncOptions == null) {
443+
if (null === $asyncOptions) {
444444
$asyncOptions = new PollingOptions();
445445
}
446446

@@ -492,7 +492,7 @@ public function enqueue(
492492
?PredictMethodOptions $options = null,
493493
?PageOptions $pageOptions = null
494494
): AsyncPredictResponse {
495-
if ($options == null) {
495+
if (null === $options) {
496496
$options = new PredictMethodOptions();
497497
}
498498
if ($pageOptions !== null && $inputDoc instanceof LocalInputSource && $inputDoc->isPDF()) {
@@ -561,7 +561,7 @@ public function executeWorkflow(
561561
?WorkflowOptions $options = null,
562562
?PageOptions $pageOptions = null
563563
): WorkflowResponse {
564-
if ($options == null) {
564+
if (null === $options) {
565565
$options = new WorkflowOptions();
566566
}
567567
if ($pageOptions !== null && $inputDoc instanceof LocalInputSource && $inputDoc->isPDF()) {

0 commit comments

Comments
 (0)