Skip to content

Commit dbdc368

Browse files
♻️ drop phpcs/phpcbf in favor of php-cs-fixer with stricter rules (#187)
1 parent d980a46 commit dbdc368

374 files changed

Lines changed: 4353 additions & 3915 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: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,7 @@ jobs:
3131
run: |
3232
composer install
3333
34-
- name: Run CS Fixer
34+
- name: Run lint
3535
run: |
36-
./vendor/bin/php-cs-fixer check ./src
37-
38-
- name: Setup Code Sniffer
39-
run: |
40-
./vendor/bin/phpcs --config-set default_standard PSR12
41-
42-
- name: Run Code Sniffer
43-
run: |
44-
./vendor/bin/phpcs -n ./src/
36+
composer lint
37+

.php-cs-fixer.dist.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpCsFixer\Config;
6+
use PhpCsFixer\Finder;
7+
8+
$finder = (new Finder())
9+
->in([
10+
__DIR__ . '/src',
11+
__DIR__ . '/tests',
12+
__DIR__ . '/bin',
13+
])
14+
->append([
15+
__DIR__ . '/mindee',
16+
]);
17+
18+
return (new Config())
19+
->setRiskyAllowed(true)
20+
->setRules([
21+
'@auto' => true,
22+
'@auto:risky' => true,
23+
'@PhpCsFixer:risky' => true,
24+
25+
'fully_qualified_strict_types' => [
26+
'import_symbols' => true,
27+
'leading_backslash_in_global_namespace' => false,
28+
],
29+
'global_namespace_import' => [
30+
'import_classes' => true,
31+
'import_constants' => true,
32+
'import_functions' => true,
33+
],
34+
'no_superfluous_phpdoc_tags' => [
35+
'allow_mixed' => true,
36+
'allow_unused_params' => false,
37+
],
38+
'phpdoc_align' => [
39+
'align' => 'left',
40+
],
41+
'concat_space' => [
42+
'spacing' => 'one',
43+
],
44+
'yoda_style' => false,
45+
'php_unit_strict' => false,
46+
])
47+
->setFinder($finder);

bin/DocumentCommandConfig.php

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

3+
declare(strict_types=1);
4+
35
namespace Mindee\CLI;
46

57
/**
@@ -12,7 +14,7 @@ class DocumentCommandConfig
1214
*/
1315
public string $help;
1416
/**
15-
* @var string Document class, as defined in the Mindee\Product namespace.
17+
* @var string Document class, as defined in the Mindee\V1\Product namespace.
1618
*/
1719
public string $docClass;
1820
/**
@@ -25,10 +27,10 @@ class DocumentCommandConfig
2527
public bool $isAsync;
2628

2729
/**
28-
* @param string $help Custom help message (currently not in use).
29-
* @param string $docClass Document class, as defined in the Mindee\Product namespace.
30-
* @param boolean $isSync Whether the document supports synchronous usage.
31-
* @param boolean $isAsync Whether the document supports asynchronous usage.
30+
* @param string $help Custom help message (currently not in use).
31+
* @param string $docClass Document class, as defined in the Mindee\V1\Product namespace.
32+
* @param boolean $isSync Whether the document supports synchronous usage.
33+
* @param boolean $isAsync Whether the document supports asynchronous usage.
3234
*/
3335
public function __construct(string $help, string $docClass, bool $isSync, bool $isAsync = false)
3436
{

bin/MindeeCLICommand.php

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Mindee\CLI;
46

57
use Mindee\Error\MindeeHttpException;
@@ -17,6 +19,11 @@
1719
use Symfony\Component\Console\Input\InputInterface;
1820
use Symfony\Component\Console\Input\InputOption;
1921
use Symfony\Component\Console\Output\OutputInterface;
22+
use Exception;
23+
24+
use function count;
25+
use function in_array;
26+
2027
use const Mindee\Input\KEEP_ONLY;
2128
use const Mindee\Input\REMOVE;
2229
use const Mindee\VERSION;
@@ -54,7 +61,6 @@ public function __construct(array $documentList)
5461

5562
/**
5663
* @param string|null $product Selected product, for customisation of the help section.
57-
* @return string
5864
*/
5965
protected function formatHelp(string $product = null): string
6066
{
@@ -83,7 +89,7 @@ protected function formatHelp(string $product = null): string
8389
/**
8490
* @return void sets the main CLI properties.
8591
*/
86-
protected function configure()
92+
protected function configure(): void
8793
{
8894
$this
8995
->setName('mindee')
@@ -106,7 +112,7 @@ protected function configure()
106112
/**
107113
* @return void Sets main properties regarding polling/parsing.
108114
*/
109-
private function configureMainOptions()
115+
private function configureMainOptions(): void
110116
{
111117
$this->addOption(
112118
'async',
@@ -171,7 +177,7 @@ private function configureMainOptions()
171177
/**
172178
* @return void Sets custom options.
173179
*/
174-
private function configureCustomOptions()
180+
private function configureCustomOptions(): void
175181
{
176182
$this
177183
->addOption(
@@ -197,11 +203,10 @@ private function configureCustomOptions()
197203
/**
198204
* Initializes the CLI runner, writes the help section if no argument nor option is given.
199205
*
200-
* @param InputInterface $input Input interface given to the CLI.
206+
* @param InputInterface $input Input interface given to the CLI.
201207
* @param OutputInterface $output Output interface.
202-
* @return void
203208
*/
204-
protected function initialize(InputInterface $input, OutputInterface $output)
209+
protected function initialize(InputInterface $input, OutputInterface $output): void
205210
{
206211
$args = $input->getArguments();
207212
$opts = $input->getOptions();
@@ -215,7 +220,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
215220
/**
216221
* Runs a command (overload).
217222
*
218-
* @param InputInterface $input Input interface given to the CLI.
223+
* @param InputInterface $input Input interface given to the CLI.
219224
* @param OutputInterface $output Output interface.
220225
* @return integer Command execution code return.
221226
*/
@@ -276,7 +281,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
276281
/**
277282
* Checks whether the version was requested.
278283
*
279-
* @param InputInterface $input Input interface of the CLI.
284+
* @param InputInterface $input Input interface of the CLI.
280285
* @param OutputInterface $output Output interface of the CLI.
281286
* @return boolean True if options are valid.
282287
*/
@@ -292,16 +297,16 @@ private function handleVersionOption(InputInterface $input, OutputInterface $out
292297
/**
293298
* Checks whether a given product is valid for CLI use.
294299
*
295-
* @param string $product Product class used.
296-
* @param OutputInterface $output Output interface of the CLI.
300+
* @param string $product Product class used.
301+
* @param OutputInterface $output Output interface of the CLI.
297302
* @return boolean True if a product is valid.
298303
*/
299304
private function isValidProduct(string $product, OutputInterface $output): bool
300305
{
301-
if (!in_array($product, $this->acceptableDocuments)) {
306+
if (!in_array($product, $this->acceptableDocuments, true)) {
302307
$output->writeln("<error>Invalid product: $product</error>");
303-
$output->writeln('<error>Available products are: ' .
304-
implode(', ', $this->acceptableDocuments) . '</error>');
308+
$output->writeln('<error>Available products are: '
309+
. implode(', ', $this->acceptableDocuments) . '</error>');
305310
return false;
306311
}
307312
return true;
@@ -310,9 +315,9 @@ private function isValidProduct(string $product, OutputInterface $output): bool
310315
/**
311316
* Checks whether a polling method is valid for the current poll.
312317
*
313-
* @param string $product Product class used.
314-
* @param boolean $isAsync Whether the polling will be asynchronous.
315-
* @param OutputInterface $output Output interface of the CLI.
318+
* @param string $product Product class used.
319+
* @param boolean $isAsync Whether the polling will be asynchronous.
320+
* @param OutputInterface $output Output interface of the CLI.
316321
* @return boolean True if the polling method exists for a given product.
317322
*/
318323
private function isValidPollingMethod(string $product, bool $isAsync, OutputInterface $output): bool
@@ -333,7 +338,7 @@ private function isValidPollingMethod(string $product, bool $isAsync, OutputInte
333338
/**
334339
* Checks whether PageOptions for the current polling are possible.
335340
*
336-
* @param InputInterface $input Input interface of the CLI.
341+
* @param InputInterface $input Input interface of the CLI.
337342
* @param OutputInterface $output Output interface of the CLI.
338343
* @return boolean True if the operations are possible.
339344
*/
@@ -351,9 +356,9 @@ private function areMutuallyExclusivePagesOptions(InputInterface $input, OutputI
351356
/**
352357
* Retrieves a source file from a URL or a path.
353358
*
354-
* @param string $filePathOrUrl Path of the file, or URL if it's remote.
355-
* @param Client $client Mindee Client.
356-
* @param OutputInterface $output Output interface of the CLI.
359+
* @param string $filePathOrUrl Path of the file, or URL if it's remote.
360+
* @param Client $client Mindee Client.
361+
* @param OutputInterface $output Output interface of the CLI.
357362
* @return PathInput|URLInputSource|null A valid InputSource.
358363
*/
359364
private function getFileSource(string $filePathOrUrl, Client $client, OutputInterface $output)
@@ -410,7 +415,7 @@ private function getPredictOptions(InputInterface $input): PredictOptions
410415
* Generates a valid PredictMethodOptions object for parsing.
411416
*
412417
* @param PredictOptions $predictOptions Valid PredictOptions.
413-
* @param PageOptions $pageOptions Valid PageOptions.
418+
* @param PageOptions $pageOptions Valid PageOptions.
414419
* @return PredictMethodOptions Valid PredictMethod Options.
415420
*/
416421
private function getPredictMethodOptions(
@@ -426,11 +431,11 @@ private function getPredictMethodOptions(
426431
/**
427432
* Handles options specific to Custom & Generated Products.
428433
*
429-
* @param InputInterface $input Input interface of the CLI.
430-
* @param OutputInterface $output Output interface of the CLI.
431-
* @param Client $client Mindee Client.
434+
* @param InputInterface $input Input interface of the CLI.
435+
* @param OutputInterface $output Output interface of the CLI.
436+
* @param Client $client Mindee Client.
432437
* @param PredictMethodOptions $predictMethodOptions Valid PredictMethodOptions.
433-
* @param string $product Product class used.
438+
* @param string $product Product class used.
434439
* @return boolean Whether the setting of options for custom/generated are valid.
435440
*/
436441
private function handleCustomOrGeneratedProduct(
@@ -440,7 +445,7 @@ private function handleCustomOrGeneratedProduct(
440445
PredictMethodOptions $predictMethodOptions,
441446
string $product
442447
): bool {
443-
if ($product == "generated") {
448+
if ($product === "generated") {
444449
$accountName = $input->getOption('account_name');
445450
$endpointName = $input->getOption('endpoint_name');
446451
$endpointVersion = $input->getOption('endpoint_version') ?? '1';
@@ -465,14 +470,14 @@ private function handleCustomOrGeneratedProduct(
465470
}
466471

467472
/**
468-
* @param Client $client Mindee Client.
469-
* @param string $product Product class used.
470-
* @param InputSource $file Input File.
473+
* @param Client $client Mindee Client.
474+
* @param string $product Product class used.
475+
* @param InputSource $file Input File.
471476
* @param PredictMethodOptions $predictMethodOptions Options for the polling.
472-
* @param boolean $isAsync Whether the polling will be asynchronous.
473-
* @param InputInterface $input Input interface of the CLI.
474-
* @param OutputInterface $output Output interface of the CLI.
475-
* @param string|null $outputType Type of output (raw, parsed or summary).
477+
* @param boolean $isAsync Whether the polling will be asynchronous.
478+
* @param InputInterface $input Input interface of the CLI.
479+
* @param OutputInterface $output Output interface of the CLI.
480+
* @param string|null $outputType Type of output (raw, parsed or summary).
476481
* @return integer Return code for the CLI
477482
*/
478483
private function executePrediction(
@@ -491,7 +496,7 @@ private function executePrediction(
491496
} catch (MindeeHttpException $e) {
492497
$output->writeln($e->getMessage());
493498
return Command::FAILURE;
494-
} catch (\Exception $e) {
499+
} catch (Exception $e) {
495500
$output->writeln("Something went wrong, '" . $e->getMessage() . "' was raised.");
496501
return Command::FAILURE;
497502
}
@@ -502,15 +507,15 @@ private function executePrediction(
502507
/**
503508
* Runs the prediction call.
504509
*
505-
* @param Client $client Mindee client.
506-
* @param string $product Product class used.
507-
* @param InputSource $file Input File.
510+
* @param Client $client Mindee client.
511+
* @param string $product Product class used.
512+
* @param InputSource $file Input File.
508513
* @param PredictMethodOptions $predictMethodOptions Prediction method options.
509-
* @param boolean $isAsync Whether the polling is asynchronous.
510-
* @param boolean $debug Whether the command is running in debug mode.
514+
* @param boolean $isAsync Whether the polling is asynchronous.
515+
* @param boolean $debug Whether the command is running in debug mode.
511516
*
512517
* @return AsyncPredictResponse|PredictResponse|string Either a valid prediction response, or a message if the
513-
* command is in debug mode.
518+
* command is in debug mode.
514519
*/
515520
private function runClientPrediction(
516521
Client $client,
@@ -532,10 +537,10 @@ private function runClientPrediction(
532537
}
533538

534539
/**
535-
* @param PredictResponse|AsyncPredictResponse|string $result Result of the parsing (or message if in debug
536-
* mode).
537-
* @param string|null $outputType Type of output (raw, parsed or summary).
538-
* @param OutputInterface $output Output interface for the CLI.
540+
* @param PredictResponse|AsyncPredictResponse|string $result Result of the parsing (or message if in debug
541+
* mode).
542+
* @param string|null $outputType Type of output (raw, parsed or summary).
543+
* @param OutputInterface $output Output interface for the CLI.
539544
* @return integer Command execution code return.
540545
*/
541546
private function outputResult(

0 commit comments

Comments
 (0)