Skip to content
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 3 additions & 10 deletions .github/workflows/_static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ jobs:
run: |
composer install

- name: Run CS Fixer
- name: Run lint
run: |
./vendor/bin/php-cs-fixer check ./src

- name: Setup Code Sniffer
run: |
./vendor/bin/phpcs --config-set default_standard PSR12

- name: Run Code Sniffer
run: |
./vendor/bin/phpcs -n ./src/
composer lint

47 changes: 47 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = (new Finder())
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__ . '/bin',
])
->append([
__DIR__ . '/mindee',
]);

return (new Config())
->setRiskyAllowed(true)
->setRules([
'@auto' => true,
'@auto:risky' => true,
'@PhpCsFixer:risky' => true,

'fully_qualified_strict_types' => [
'import_symbols' => true,
'leading_backslash_in_global_namespace' => false,
],
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
],
'no_superfluous_phpdoc_tags' => [
'allow_mixed' => true,
'allow_unused_params' => false,
],
'phpdoc_align' => [
'align' => 'left',
],
'concat_space' => [
'spacing' => 'one',
],
'yoda_style' => false,
'php_unit_strict' => false,
])
->setFinder($finder);
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Mindee PHP API Library Changelog

## v3.0.0-alpha1 - 2026-05-11
### ¡Breaking Changes!
*
### Changes
* :sparkles: add support for extraction in crop, split, and classification
### Fixes
*


## v2.9.0 - 2026-05-07
### Changes
* :sparkles: add support for extraction in crop, split, and classification
Expand Down
12 changes: 7 additions & 5 deletions bin/DocumentCommandConfig.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Mindee\CLI;

/**
Expand All @@ -12,7 +14,7 @@ class DocumentCommandConfig
*/
public string $help;
/**
* @var string Document class, as defined in the Mindee\Product namespace.
* @var string Document class, as defined in the Mindee\V1\Product namespace.
*/
public string $docClass;
/**
Expand All @@ -25,10 +27,10 @@ class DocumentCommandConfig
public bool $isAsync;

/**
* @param string $help Custom help message (currently not in use).
* @param string $docClass Document class, as defined in the Mindee\Product namespace.
* @param boolean $isSync Whether the document supports synchronous usage.
* @param boolean $isAsync Whether the document supports asynchronous usage.
* @param string $help Custom help message (currently not in use).
* @param string $docClass Document class, as defined in the Mindee\V1\Product namespace.
* @param boolean $isSync Whether the document supports synchronous usage.
* @param boolean $isAsync Whether the document supports asynchronous usage.
*/
public function __construct(string $help, string $docClass, bool $isSync, bool $isAsync = false)
{
Expand Down
104 changes: 54 additions & 50 deletions bin/MindeeCLICommand.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
<?php

declare(strict_types=1);

namespace Mindee\CLI;

use Mindee\Client;
use Mindee\Error\MindeeHttpException;
use Mindee\Input\InputSource;
use Mindee\Input\PageOptions;
use Mindee\Input\PathInput;
use Mindee\Input\PredictMethodOptions;
use Mindee\Input\PredictOptions;
use Mindee\Input\URLInputSource;
use Mindee\Parsing\Common\AsyncPredictResponse;
use Mindee\Parsing\Common\PredictResponse;
use Mindee\V1\Client;
use Mindee\V1\ClientOptions\PredictMethodOptions;
use Mindee\V1\ClientOptions\PredictOptions;
use Mindee\V1\Parsing\Common\AsyncPredictResponse;
use Mindee\V1\Parsing\Common\PredictResponse;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Exception;

use function count;
use function in_array;

use const Mindee\Input\KEEP_ONLY;
use const Mindee\Input\REMOVE;
Expand Down Expand Up @@ -55,7 +61,6 @@ public function __construct(array $documentList)

/**
* @param string|null $product Selected product, for customisation of the help section.
* @return string
*/
protected function formatHelp(string $product = null): string
{
Expand Down Expand Up @@ -84,7 +89,7 @@ protected function formatHelp(string $product = null): string
/**
* @return void sets the main CLI properties.
*/
protected function configure()
protected function configure(): void
{
$this
->setName('mindee')
Expand All @@ -107,7 +112,7 @@ protected function configure()
/**
* @return void Sets main properties regarding polling/parsing.
*/
private function configureMainOptions()
private function configureMainOptions(): void
{
$this->addOption(
'async',
Expand Down Expand Up @@ -172,7 +177,7 @@ private function configureMainOptions()
/**
* @return void Sets custom options.
*/
private function configureCustomOptions()
private function configureCustomOptions(): void
{
$this
->addOption(
Expand All @@ -198,11 +203,10 @@ private function configureCustomOptions()
/**
* Initializes the CLI runner, writes the help section if no argument nor option is given.
*
* @param InputInterface $input Input interface given to the CLI.
* @param InputInterface $input Input interface given to the CLI.
* @param OutputInterface $output Output interface.
* @return void
*/
protected function initialize(InputInterface $input, OutputInterface $output)
protected function initialize(InputInterface $input, OutputInterface $output): void
{
$args = $input->getArguments();
$opts = $input->getOptions();
Expand All @@ -216,7 +220,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
/**
* Runs a command (overload).
*
* @param InputInterface $input Input interface given to the CLI.
* @param InputInterface $input Input interface given to the CLI.
* @param OutputInterface $output Output interface.
* @return integer Command execution code return.
*/
Expand Down Expand Up @@ -277,7 +281,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/**
* Checks whether the version was requested.
*
* @param InputInterface $input Input interface of the CLI.
* @param InputInterface $input Input interface of the CLI.
* @param OutputInterface $output Output interface of the CLI.
* @return boolean True if options are valid.
*/
Expand All @@ -293,16 +297,16 @@ private function handleVersionOption(InputInterface $input, OutputInterface $out
/**
* Checks whether a given product is valid for CLI use.
*
* @param string $product Product class used.
* @param OutputInterface $output Output interface of the CLI.
* @param string $product Product class used.
* @param OutputInterface $output Output interface of the CLI.
* @return boolean True if a product is valid.
*/
private function isValidProduct(string $product, OutputInterface $output): bool
{
if (!in_array($product, $this->acceptableDocuments)) {
if (!in_array($product, $this->acceptableDocuments, true)) {
$output->writeln("<error>Invalid product: $product</error>");
$output->writeln('<error>Available products are: ' .
implode(', ', $this->acceptableDocuments) . '</error>');
$output->writeln('<error>Available products are: '
. implode(', ', $this->acceptableDocuments) . '</error>');
return false;
}
return true;
Expand All @@ -311,9 +315,9 @@ private function isValidProduct(string $product, OutputInterface $output): bool
/**
* Checks whether a polling method is valid for the current poll.
*
* @param string $product Product class used.
* @param boolean $isAsync Whether the polling will be asynchronous.
* @param OutputInterface $output Output interface of the CLI.
* @param string $product Product class used.
* @param boolean $isAsync Whether the polling will be asynchronous.
* @param OutputInterface $output Output interface of the CLI.
* @return boolean True if the polling method exists for a given product.
*/
private function isValidPollingMethod(string $product, bool $isAsync, OutputInterface $output): bool
Expand All @@ -334,7 +338,7 @@ private function isValidPollingMethod(string $product, bool $isAsync, OutputInte
/**
* Checks whether PageOptions for the current polling are possible.
*
* @param InputInterface $input Input interface of the CLI.
* @param InputInterface $input Input interface of the CLI.
* @param OutputInterface $output Output interface of the CLI.
* @return boolean True if the operations are possible.
*/
Expand All @@ -352,9 +356,9 @@ private function areMutuallyExclusivePagesOptions(InputInterface $input, OutputI
/**
* Retrieves a source file from a URL or a path.
*
* @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.
* @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.
*/
private function getFileSource(string $filePathOrUrl, Client $client, OutputInterface $output)
Expand Down Expand Up @@ -411,7 +415,7 @@ private function getPredictOptions(InputInterface $input): PredictOptions
* Generates a valid PredictMethodOptions object for parsing.
*
* @param PredictOptions $predictOptions Valid PredictOptions.
* @param PageOptions $pageOptions Valid PageOptions.
* @param PageOptions $pageOptions Valid PageOptions.
* @return PredictMethodOptions Valid PredictMethod Options.
*/
private function getPredictMethodOptions(
Expand All @@ -427,11 +431,11 @@ private function getPredictMethodOptions(
/**
* Handles options specific to Custom & Generated Products.
*
* @param InputInterface $input Input interface of the CLI.
* @param OutputInterface $output Output interface of the CLI.
* @param Client $client Mindee Client.
* @param InputInterface $input Input interface of the CLI.
* @param OutputInterface $output Output interface of the CLI.
* @param Client $client Mindee Client.
* @param PredictMethodOptions $predictMethodOptions Valid PredictMethodOptions.
* @param string $product Product class used.
* @param string $product Product class used.
* @return boolean Whether the setting of options for custom/generated are valid.
*/
private function handleCustomOrGeneratedProduct(
Expand All @@ -441,7 +445,7 @@ private function handleCustomOrGeneratedProduct(
PredictMethodOptions $predictMethodOptions,
string $product
): bool {
if ($product == "generated") {
if ($product === "generated") {
$accountName = $input->getOption('account_name');
$endpointName = $input->getOption('endpoint_name');
$endpointVersion = $input->getOption('endpoint_version') ?? '1';
Expand All @@ -466,14 +470,14 @@ private function handleCustomOrGeneratedProduct(
}

/**
* @param Client $client Mindee Client.
* @param string $product Product class used.
* @param InputSource $file Input File.
* @param Client $client Mindee Client.
* @param string $product Product class used.
* @param InputSource $file Input File.
* @param PredictMethodOptions $predictMethodOptions Options for the polling.
* @param boolean $isAsync Whether the polling will be asynchronous.
* @param InputInterface $input Input interface of the CLI.
* @param OutputInterface $output Output interface of the CLI.
* @param string|null $outputType Type of output (raw, parsed or summary).
* @param boolean $isAsync Whether the polling will be asynchronous.
* @param InputInterface $input Input interface of the CLI.
* @param OutputInterface $output Output interface of the CLI.
* @param string|null $outputType Type of output (raw, parsed or summary).
* @return integer Return code for the CLI
*/
private function executePrediction(
Expand All @@ -492,7 +496,7 @@ private function executePrediction(
} catch (MindeeHttpException $e) {
$output->writeln($e->getMessage());
return Command::FAILURE;
} catch (\Exception $e) {
} catch (Exception $e) {
$output->writeln("Something went wrong, '" . $e->getMessage() . "' was raised.");
return Command::FAILURE;
}
Expand All @@ -503,15 +507,15 @@ private function executePrediction(
/**
* Runs the prediction call.
*
* @param Client $client Mindee client.
* @param string $product Product class used.
* @param InputSource $file Input File.
* @param Client $client Mindee client.
* @param string $product Product class used.
* @param InputSource $file Input File.
* @param PredictMethodOptions $predictMethodOptions Prediction method options.
* @param boolean $isAsync Whether the polling is asynchronous.
* @param boolean $debug Whether the command is running in debug mode.
* @param boolean $isAsync Whether the polling is asynchronous.
* @param boolean $debug Whether the command is running in debug mode.
*
* @return AsyncPredictResponse|PredictResponse|string Either a valid prediction response, or a message if the
* command is in debug mode.
* command is in debug mode.
*/
private function runClientPrediction(
Client $client,
Expand All @@ -533,10 +537,10 @@ private function runClientPrediction(
}

/**
* @param PredictResponse|AsyncPredictResponse|string $result Result of the parsing (or message if in debug
* mode).
* @param string|null $outputType Type of output (raw, parsed or summary).
* @param OutputInterface $output Output interface for the CLI.
* @param PredictResponse|AsyncPredictResponse|string $result Result of the parsing (or message if in debug
* mode).
* @param string|null $outputType Type of output (raw, parsed or summary).
* @param OutputInterface $output Output interface for the CLI.
* @return integer Command execution code return.
*/
private function outputResult(
Expand Down
Loading
Loading