Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/workflows/_static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,3 @@ jobs:
- name: Run lint
run: |
composer lint

- name: Run PHPStan
run: |
composer phpstan

- name: Run Rector
run: |
composer rector:check
2 changes: 1 addition & 1 deletion bin/MindeeCLICommand.php → bin/MindeeCliCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Configuration Class for CLI.
*/
class MindeeCLICommand extends Command
class MindeeCliCommand extends Command
{
/**
* @var array $documentList Array of document configurations.
Expand Down
2 changes: 1 addition & 1 deletion bin/MindeeCLIDocuments.php → bin/MindeeCliDocuments.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/**
* Document specifications for CLI usage.
*/
class MindeeCLIDocuments
class MindeeCliDocuments
{
/**
* @return array Specifications for each Mindee Document, for CLI usage.
Expand Down
6 changes: 3 additions & 3 deletions bin/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
namespace Mindee\Cli;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/MindeeCLIDocuments.php';
require __DIR__ . '/MindeeCLICommand.php';
require __DIR__ . '/MindeeCliDocuments.php';
require __DIR__ . '/MindeeCliCommand.php';

use Symfony\Component\Console\Application;
use Exception;

$cli = new Application();
$mindeeCommand = new MindeeCLICommand(MindeeCLIDocuments::getSpecs());
$mindeeCommand = new MindeeCliCommand(MindeeCliDocuments::getSpecs());
$cli->add($mindeeCommand);
try {
$cli->add($mindeeCommand);
Expand Down
26 changes: 20 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"madewithlove/license-checker": "^v1.0",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-deprecation-rules": "^2.0",
"rector/rector": "^2.4"
"rector/rector": "^2.4",
"projektgopher/whisky": "^0.7.4"
},
"suggest": {
"ext-imagick": "Required for PDF rasterization and image processing features",
Expand All @@ -35,10 +36,23 @@
"bin/cli.php"
],
"scripts": {
"lint": "php-cs-fixer fix --dry-run --diff",
"phpstan": "phpstan analyse src --level 6",
"format": "php-cs-fixer fix",
"rector": "rector process src tests",
"rector:check": "rector process src tests --dry-run"
"lint:cs-fixer": "php-cs-fixer fix --dry-run --diff",
"lint:rector": "rector process src tests --dry-run",
"lint:phpstan": "phpstan analyse",
"lint": [
"@lint:phpstan",
"@lint:cs-fixer",
"@lint:rector"
],
"format:cs-fixer": "php-cs-fixer fix",
"format:rector": "rector process src tests",
"format": [
"@format:cs-fixer",
"@format:rector"
],
"test:unit": "phpunit -c tests/phpunit.xml",
"test:functional": "phpunit -c tests/functional.xml",
"test:smoke:v1": "./tests/test_v1_code_samples.sh",
"test:smoke:v2": "./tests/test_v2_code_samples.sh"
}
}
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 6
paths:
- src
2 changes: 1 addition & 1 deletion src/V1/Http/BaseApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Default URL prefix for API calls.
*/
const BASE_URL_DEFAULT = 'https://api.mindee.net/v1';
const BASE_URL_DEFAULT = 'https://api.mindee.net';

/**
* Default key name for CURL request timeout in environment variables.
Expand Down
2 changes: 1 addition & 1 deletion src/V1/Http/BaseEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function setFinalCurlOpts(
?string $workflowId = null
): array {
if (isset($workflowId)) {
$url = $this->settings->baseUrl . "/workflows/" . $workflowId . $suffix;
$url = $this->settings->baseUrl . "/v1/workflows/" . $workflowId . $suffix;
} else {
$url = $this->settings->urlRoot . $suffix;
}
Expand Down
2 changes: 1 addition & 1 deletion src/V1/Http/MindeeApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public function __construct(
$this->urlRoot = rtrim(
$this->baseUrl,
"/"
) . "/products/$this->accountName/$this->endpointName/v$this->version";
) . "/v1/products/$this->accountName/$this->endpointName/v$this->version";
}
}
2 changes: 1 addition & 1 deletion src/V1/Http/MindeeWorkflowApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public function __construct(
$this->urlRoot = rtrim(
$this->baseUrl,
"/"
) . "/workflows/$this->workflowId/executions";
) . "/v1/workflows/$this->workflowId/executions";
}
}
8 changes: 4 additions & 4 deletions src/V2/Http/MindeeApiV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
/**
* Default URL prefix for API calls.
*/
const API_V2_BASE_URL_DEFAULT = 'https://api-v2.mindee.net/v2';
const API_V2_BASE_URL_DEFAULT = 'https://api-v2.mindee.net';

/**
* Default key name for CURL request timeout in environment variables.
Expand Down Expand Up @@ -241,7 +241,7 @@ private function processJobResponse(array $result): JobResponse
*/
public function reqGetJob(string $jobId): JobResponse
{
$response = $this->sendGetRequest($this->baseUrl . "/jobs/$jobId");
$response = $this->sendGetRequest($this->baseUrl . "/v2/jobs/$jobId");
return $this->processJobResponse($response);
}

Expand All @@ -268,7 +268,7 @@ public function reqGetResult(
$e
);
}
$url = $this->baseUrl . "/products/{$slugProperty->getValue()}/results/$resultId";
$url = $this->baseUrl . "/v2/products/{$slugProperty->getValue()}/results/$resultId";
$response = $this->sendGetRequest($url);
return $this->processResponse($responseClass, $response);
}
Expand Down Expand Up @@ -352,7 +352,7 @@ private function documentEnqueuePost(
$inputSource->checkNeedsFix();
$postFields['file'] = $inputSource->fileObject;
}
$url = $this->baseUrl . "/products/{$params::$slug}/enqueue";
$url = $this->baseUrl . "/v2/products/{$params::$slug}/enqueue";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
$resp = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

declare(strict_types=1);

namespace V1\CLI;
namespace V1\Cli;

use PHPUnit\Framework\TestCase;
use TestingUtilities;

require_once(__DIR__ . "/MindeeCLITestingUtilities.php");
require_once(__DIR__ . "/MindeeCliTestingUtilities.php");

class MindeeCLICommandTest extends TestCase
class MindeeCliCommandTest extends TestCase
{
private string $apiKey;
private string $filePath;
Expand All @@ -22,21 +22,21 @@ protected function setUp(): void

public function testInvalidFilePath(): void
{
$cmdOutput = MindeeCLITestingUtilities::executeTest(["financial-document", "invalid-file-path", "-k", $this->apiKey, "-D"]);
$cmdOutput = MindeeCliTestingUtilities::executeTest(["financial-document", "invalid-file-path", "-k", $this->apiKey, "-D"]);
self::assertSame(1, $cmdOutput["code"]);
self::assertTrue(str_contains((string) $cmdOutput["output"][0], "Invalid path or url provided 'invalid-file-path'."));
}

public function testInvalidKey(): void
{
$cmdOutput = MindeeCLITestingUtilities::executeTest(["financial-document", $this->filePath, "-k", "invalid-key"]);
$cmdOutput = MindeeCliTestingUtilities::executeTest(["financial-document", $this->filePath, "-k", "invalid-key"]);
self::assertSame(1, $cmdOutput["code"]);
self::assertTrue(str_contains(implode(" ", $cmdOutput["output"]), "Invalid token provided"));
}

public function testInvalidProduct(): void
{
$cmdOutput = MindeeCLITestingUtilities::executeTest(["invalid-product", $this->filePath, "-k", "invalid-key", "-D"]);
$cmdOutput = MindeeCliTestingUtilities::executeTest(["invalid-product", $this->filePath, "-k", "invalid-key", "-D"]);
self::assertSame(1, $cmdOutput["code"]);
self::assertTrue(str_contains((string) $cmdOutput["output"][0], "Invalid product: invalid-product"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

declare(strict_types=1);

namespace V1\CLI;
namespace V1\Cli;

require_once(__DIR__ . "/../../../vendor/autoload.php");
require_once(__DIR__ . "/../../../bin/MindeeCLIDocuments.php");
require_once(__DIR__ . "/../../../bin/MindeeCliDocuments.php");
require_once(__DIR__ . "/../../TestingUtilities.php");
require_once(__DIR__ . "/MindeeCLITestingUtilities.php");
require_once(__DIR__ . "/MindeeCliTestingUtilities.php");

use Mindee\Cli\MindeeCLIDocuments;
use Mindee\Cli\MindeeCliDocuments;
use PHPUnit\Framework\TestCase;
use TestingUtilities;

class MindeeCLICommandTestFunctional extends TestCase
class MindeeCliCommandTestFunctional extends TestCase
{
private string $apiKey;

Expand All @@ -32,7 +32,7 @@ private function runValidCall($productName, $async = false, $initialArgs = []):
if ($async) {
$args[] = "-A";
}
return MindeeCLITestingUtilities::executeTest($args);
return MindeeCliTestingUtilities::executeTest($args);
}


Expand All @@ -41,7 +41,7 @@ public static function provideProductCases(): iterable
$data = [];
$data[] = ["generated", true, ["-a", "mindee", "-e", "invoice_splitter", "-d", "1"]];
/** @phpstan-ignore-next-line */
foreach (MindeeCLIDocuments::getSpecs() as $productName => $productSpecs) {
foreach (MindeeCliDocuments::getSpecs() as $productName => $productSpecs) {
if ($productName !== "custom" && $productName !== "generated") {
if ($productSpecs->isSync) {
$data[] = [$productName, false];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace V1\CLI;
namespace V1\Cli;

class MindeeCLITestingUtilities
class MindeeCliTestingUtilities
{
public static function executeTest($args, $mute = false)
{
Expand Down
11 changes: 11 additions & 0 deletions whisky.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"disabled": [],
"hooks": {
"pre-commit": [
"composer lint"
],
"pre-push": [
"composer test:unit"
]
}
}
Loading