Skip to content

Commit 84bdc9b

Browse files
🔧 add support for rector (#189)
1 parent 8232cc2 commit 84bdc9b

185 files changed

Lines changed: 803 additions & 1169 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.

.github/workflows/_static-analysis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ jobs:
3838
- name: Run PHPStan
3939
run: |
4040
composer phpstan
41+
42+
- name: Run Rector
43+
run: |
44+
composer rector:check

bin/MindeeCLICommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Mindee\Input\InputSource;
99
use Mindee\Input\PageOptions;
1010
use Mindee\Input\PathInput;
11-
use Mindee\Input\URLInputSource;
11+
use Mindee\Input\UrlInputSource;
1212
use Mindee\V1\Client;
1313
use Mindee\V1\ClientOptions\PredictMethodOptions;
1414
use Mindee\V1\ClientOptions\PredictOptions;
@@ -359,7 +359,7 @@ private function areMutuallyExclusivePagesOptions(InputInterface $input, OutputI
359359
* @param string $filePathOrUrl Path of the file, or URL if it's remote.
360360
* @param Client $client Mindee Client.
361361
* @param OutputInterface $output Output interface of the CLI.
362-
* @return PathInput|URLInputSource|null A valid InputSource.
362+
* @return PathInput|UrlInputSource|null A valid InputSource.
363363
*/
364364
private function getFileSource(string $filePathOrUrl, Client $client, OutputInterface $output)
365365
{

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"friendsofphp/php-cs-fixer": "^3.38",
1818
"phpunit/phpunit": "^9.6",
1919
"madewithlove/license-checker": "^v1.0",
20-
"phpstan/phpstan": "^2.1"
20+
"phpstan/phpstan": "^2.1",
21+
"phpstan/phpstan-deprecation-rules": "^2.0",
22+
"rector/rector": "^2.4"
2123
},
2224
"suggest": {
2325
"ext-imagick": "Required for PDF rasterization and image processing features",
@@ -35,6 +37,8 @@
3537
"scripts": {
3638
"lint": "php-cs-fixer fix --dry-run --diff",
3739
"phpstan": "phpstan analyse src --level 6",
38-
"format": "php-cs-fixer fix"
40+
"format": "php-cs-fixer fix",
41+
"rector": "rector process src tests",
42+
"rector:check": "rector process src tests --dry-run"
3943
}
4044
}

docs/code_samples/v2_extraction_webhook.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $mindeeClient = new Client($apiKey);
1616
$inferenceParams = new ExtractionParameters(
1717
// ID of the model, required.
1818
$modelId,
19-
webhooksIds: ["MY_WEBHOOK_ID"],
19+
webhookIds: ["MY_WEBHOOK_ID"],
2020

2121
// Options: set to `true` or `false` to override defaults
2222

docs/code_samples/v2_ocr.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

33
use Mindee\V2\Client;
4-
use Mindee\V2\Product\OCR\Params\OCRParameters;
5-
use Mindee\V2\Product\OCR\OCRResponse;
4+
use Mindee\V2\Product\Ocr\Params\OcrParameters;
5+
use Mindee\V2\Product\Ocr\OcrResponse;
66
use Mindee\Input\PathInput;
77

88
$apiKey = "MY_API_KEY";
@@ -14,7 +14,7 @@ $mindeeClient = new Client($apiKey);
1414

1515
// Set ocr parameters
1616
// Note: modelId is mandatory.
17-
$ocrParams = new OCRParameters(
17+
$ocrParams = new OcrParameters(
1818
// ID of the model, required.
1919
$modelId,
2020
);

rector.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
7+
return RectorConfig::configure()
8+
->withPaths([
9+
__DIR__ . '/src',
10+
__DIR__ . '/tests',
11+
])
12+
->withPhpSets()
13+
->withTypeCoverageLevel(0)
14+
->withDeadCodeLevel(0)
15+
->withCodeQualityLevel(0);

src/Dependency/DependencyChecker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static function isGhostscriptAvailable(): void
4848
} else {
4949
$commandWasExecuted = (bool) shell_exec('which gs');
5050
}
51-
} catch (Exception $e) {
51+
} catch (Exception) {
5252
throw new MindeeUnhandledException(
5353
"To enable full support of PDF features, you need "
5454
. "to enable Ghostscript on your PHP installation.",
@@ -96,7 +96,7 @@ public static function isImageMagickPolicyAllowed(): void
9696
/** @phpstan-ignore-next-line */
9797
TestingUtilities::getV1DataDir() . "/products/expense_receipts/default_sample.jpg"
9898
);
99-
} catch (Exception $e) {
99+
} catch (Exception) {
100100
throw new MindeeUnhandledException(
101101
"To enable full support of PDF features, you need "
102102
. "to enable ImageMagick on your PHP installation. Also, you "

src/Error/MindeeHttpException.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
*/
2121
class MindeeHttpException extends MindeeException
2222
{
23-
/**
24-
* @var integer Status code as sent by the server.
25-
*/
26-
public int $statusCode;
2723
/**
2824
* @var string|null API code as sent by the server.
2925
*/
@@ -40,11 +36,10 @@ class MindeeHttpException extends MindeeException
4036
/**
4137
* @param array<string, int|float|string|bool|null|array<array-key, mixed>> $httpError Array containing the error data.
4238
* @param string $url Remote URL the error was found on.
43-
* @param integer $code Error code.
39+
* @param integer $statusCode Error code.
4440
*/
45-
public function __construct(array $httpError, string $url, int $code)
41+
public function __construct(array $httpError, string $url, public int $statusCode)
4642
{
47-
$this->statusCode = $code;
4843
if (array_key_exists('code', $httpError)) {
4944
$this->apiCode = $httpError['code'];
5045
} else {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
/**
1313
* Exceptions relating to the handling of PDF documents.
1414
*/
15-
class MindeePDFException extends MindeeException {}
15+
class MindeePdfException extends MindeeException {}

src/Extraction/ExtractedImage.php

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,21 @@
1919
*/
2020
class ExtractedImage
2121
{
22-
/**
23-
* @var Imagick Wrapper for the image.
24-
*/
25-
public Imagick $image;
26-
27-
/**
28-
* @var string Name of the file.
29-
*/
30-
public string $filename;
31-
32-
/**
33-
* @var integer Page ID of the image.
34-
*/
35-
public int $pageId;
36-
37-
/**
38-
* @var integer Element ID of the image.
39-
*/
40-
public int $elementId;
41-
42-
/**
43-
* @var string String representation of the save format.
44-
*/
45-
protected string $saveFormat;
46-
4722
/**
4823
* Initializes a new instance of the ExtractedImage class.
4924
*
5025
* @param Imagick $image The extracted image.
5126
* @param string $filename The filename for the image.
5227
* @param string $saveFormat The format to save the image.
53-
* @param integer $pageIndex The page index of the image.
54-
* @param integer $index The element index of the image.
28+
* @param integer $pageId The page index of the image.
29+
* @param integer $elementId The element index of the image.
5530
*
5631
* @throws MindeeUnhandledException Throws if PDF operations aren't supported.
5732
*/
58-
public function __construct(Imagick $image, string $filename, string $saveFormat, int $pageIndex, int $index)
33+
public function __construct(public Imagick $image, public string $filename, protected string $saveFormat, public int $pageId, public int $elementId)
5934
{
6035
DependencyChecker::isImageMagickAvailable();
6136
DependencyChecker::isGhostscriptAvailable();
62-
$this->image = $image;
63-
$this->filename = $filename;
64-
$this->saveFormat = $saveFormat;
65-
$this->pageId = $pageIndex;
66-
$this->elementId = $index;
6737
}
6838

6939
/**

0 commit comments

Comments
 (0)