Skip to content

Commit 4e0069c

Browse files
ajout phpcsfixer
1 parent fb53766 commit 4e0069c

File tree

182 files changed

+974
-1138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+974
-1138
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
/phpunit.xml
99
.phpunit.result.cache
1010
.phpunit.cache
11+
.php-cs-fixer.cache
1112
coverage-report

.php-cs-fixer.dist.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__)
5+
->ignoreDotFiles(true)
6+
->ignoreVCS(true)
7+
->exclude(['build', 'vendor'])
8+
->files()
9+
->name('*.php')
10+
;
11+
12+
$config = new PhpCsFixer\Config();
13+
14+
return $config
15+
->setUsingCache(true)
16+
->setRiskyAllowed(true)
17+
->setFinder($finder)
18+
->setRules([
19+
'@Symfony' => true,
20+
'@Symfony:risky' => true,
21+
'@PHPUnit48Migration:risky' => true,
22+
'array_syntax' => ['syntax' => 'short'],
23+
'fopen_flags' => false,
24+
'ordered_imports' => true,
25+
'protected_to_private' => false,
26+
// Part of @Symfony:risky in PHP-CS-Fixer 2.13.0. To be removed from the config file once upgrading
27+
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced', 'strict' => true],
28+
// Part of future @Symfony ruleset in PHP-CS-Fixer To be removed from the config file once upgrading
29+
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
30+
'single_line_throw' => false,
31+
// this must be disabled because the output of some tests include NBSP characters
32+
'non_printable_character' => false,
33+
'blank_line_between_import_groups' => false,
34+
'no_trailing_comma_in_singleline' => false,
35+
'nullable_type_declaration_for_default_null_value' => true,
36+
'phpdoc_to_comment' => false,
37+
])
38+
;

Makefile

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
# Include .env.dist for the default values
2-
include .env.dist
3-
4-
# Include .env only if it exists
5-
ifneq ("",$(wildcard $(.env)))
6-
include .env
7-
endif
1+
.ONESHELL:
2+
SHELL := /bin/bash
83

94
test:
105
php -dxdebug.mode=coverage vendor/bin/phpunit --coverage-html coverage-report
116

12-
linter:
13-
vendor/bin/rector process
14-
vendor/bin/ecs check --fix
7+
linter: #[Linter]
8+
vendor/bin/php-cs-fixer fix
9+
10+
phpstan: #[Phpstan]
1511
vendor/bin/phpstan

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,13 @@
8383
"symfony/yaml": "^6.3"
8484
},
8585
"require-dev": {
86-
"roave/security-advisories": "dev-latest",
87-
"phpunit/phpunit": "*",
86+
"friendsofphp/php-cs-fixer": "*",
87+
"phpstan/extension-installer": "*",
8888
"phpstan/phpstan": "*",
8989
"phpstan/phpstan-symfony": "*",
90-
"phpstan/extension-installer": "*",
90+
"phpunit/phpunit": "*",
9191
"rector/rector": "*",
92-
"symplify/easy-coding-standard": "*",
93-
"symplify/phpstan-rules": "*",
92+
"roave/security-advisories": "dev-latest",
9493
"symfony/test-pack": "^1.1"
9594
},
9695
"suggest": {

ecs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
SetList::DOCTRINE_ANNOTATIONS,
1919
]);
2020

21-
$ecsConfig->paths([__DIR__ . '/src']);
21+
$ecsConfig->paths([__DIR__.'/src']);
2222

2323
$ecsConfig->skip([AssignmentInConditionSniff::class]);
2424
};

rector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
$rectorConfig->importNames();
1414
$rectorConfig->importShortClasses();
1515

16-
$rectorConfig->paths([__DIR__ . '/src']);
17-
$rectorConfig->skip([__DIR__ . '/src/Resources/tests']);
16+
$rectorConfig->paths([__DIR__.'/src']);
17+
$rectorConfig->skip([__DIR__.'/src/Resources/tests']);
1818

1919
$rectorConfig->sets([
2020
SetList::TYPE_DECLARATION,

src/CleverAgeProcessBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
class CleverAgeProcessBundle extends Bundle
2424
{
2525
/**
26-
* Adding compiler passes to inject services into registry
26+
* Adding compiler passes to inject services into registry.
2727
*/
2828
public function build(ContainerBuilder $container): void
2929
{

src/Command/ExecuteProcessCommand.php

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use CleverAge\ProcessBundle\Event\ConsoleProcessEvent;
1717
use CleverAge\ProcessBundle\Filesystem\JsonStreamFile;
1818
use CleverAge\ProcessBundle\Manager\ProcessManager;
19-
use InvalidArgumentException;
2019
use Psr\EventDispatcher\EventDispatcherInterface;
2120
use Symfony\Component\Console\Attribute\AsCommand;
2221
use Symfony\Component\Console\Command\Command;
@@ -26,13 +25,11 @@
2625
use Symfony\Component\Console\Output\OutputInterface;
2726
use Symfony\Component\VarDumper\VarDumper;
2827
use Symfony\Component\Yaml\Parser;
29-
use function count;
30-
use function is_array;
3128

3229
/**
33-
* Run a process from the command line interface
30+
* Run a process from the command line interface.
3431
*/
35-
#[AsCommand(name: 'cleverage:process:execute', description: 'Execute a process',)]
32+
#[AsCommand(name: 'cleverage:process:execute', description: 'Execute a process', )]
3633
class ExecuteProcessCommand extends Command
3734
{
3835
final public const OUTPUT_STDOUT = '-';
@@ -79,8 +76,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7976
$inputData = $input->getOption('input');
8077
if ($input->getOption('input-from-stdin')) {
8178
$inputData = '';
82-
while (! feof(STDIN)) {
83-
$inputData .= fread(STDIN, 8192);
79+
while (!feof(\STDIN)) {
80+
$inputData .= fread(\STDIN, 8192);
8481
}
8582
}
8683

@@ -89,15 +86,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8986
$this->eventDispatcher->dispatch(new ConsoleProcessEvent($input, $output, $inputData, $context));
9087

9188
foreach ($input->getArgument('processCodes') as $code) {
92-
if (! $output->isQuiet()) {
89+
if (!$output->isQuiet()) {
9390
$output->writeln("<comment>Starting process '{$code}'...</comment>");
9491
}
9592

9693
// Execute each process
9794
$returnValue = $this->processManager->execute($code, $inputData, $context);
9895
$this->handleOutputData($returnValue, $input, $output);
9996

100-
if (! $output->isQuiet()) {
97+
if (!$output->isQuiet()) {
10198
$output->writeln("<info>Process '{$code}' executed successfully</info>");
10299
}
103100
}
@@ -117,9 +114,9 @@ protected function parseContextValues(InputInterface $input): array
117114
$context = [];
118115
foreach ($contextValues as $contextValue) {
119116
preg_match($pattern, (string) $contextValue, $parts);
120-
if (count($parts) !== 3
117+
if (3 !== \count($parts)
121118
|| $parts[0] !== $contextValue) {
122-
throw new InvalidArgumentException(sprintf('Invalid context %s', $contextValue));
119+
throw new \InvalidArgumentException(sprintf('Invalid context %s', $contextValue));
123120
}
124121
$context[$parts[1]] = $parser->parse($parts[2]);
125122
}
@@ -130,29 +127,29 @@ protected function parseContextValues(InputInterface $input): array
130127
protected function handleOutputData(mixed $data, InputInterface $input, OutputInterface $output): void
131128
{
132129
// Skip all if undefined
133-
if (! $input->getOption('output-format')) {
130+
if (!$input->getOption('output-format')) {
134131
return;
135132
}
136133

137134
// Handle printing the output
138-
if ($input->getOption('output') === self::OUTPUT_STDOUT) {
135+
if (self::OUTPUT_STDOUT === $input->getOption('output')) {
139136
if ($output->isVeryVerbose()) {
140-
if (class_exists(VarDumper::class) && ($input->getOption(
137+
if (class_exists(VarDumper::class) && (self::OUTPUT_FORMAT_DUMP === $input->getOption(
141138
'output-format'
142-
) === self::OUTPUT_FORMAT_DUMP)) {
139+
))) {
143140
VarDumper::dump($data);
144-
} elseif ($input->getOption('output-format') === self::OUTPUT_FORMAT_JSON) {
145-
$output->writeln(json_encode($data, JSON_THROW_ON_ERROR));
141+
} elseif (self::OUTPUT_FORMAT_JSON === $input->getOption('output-format')) {
142+
$output->writeln(json_encode($data, \JSON_THROW_ON_ERROR));
146143
} else {
147-
throw new InvalidArgumentException(
144+
throw new \InvalidArgumentException(
148145
sprintf("Cannot handle data output with format '%s'", $input->getOption('output-format'))
149146
);
150147
}
151148
}
152-
} elseif ($input->getOption('output-format') === self::OUTPUT_FORMAT_JSON) {
149+
} elseif (self::OUTPUT_FORMAT_JSON === $input->getOption('output-format')) {
153150
// JsonStreamFile::writeLine only takes an array...
154151
// TODO how to handle other cases ?
155-
if (is_array($data)) {
152+
if (\is_array($data)) {
156153
$outputFile = new JsonStreamFile($input->getOption('output'), 'wb');
157154
$outputFile->writeLine($data);
158155
}
@@ -161,7 +158,7 @@ protected function handleOutputData(mixed $data, InputInterface $input, OutputIn
161158
$output->writeln(sprintf("Output stored in '%s'", $input->getOption('output')));
162159
}
163160
} else {
164-
throw new InvalidArgumentException(
161+
throw new \InvalidArgumentException(
165162
sprintf("Cannot handle data output with format '%s'", $input->getOption('output-format'))
166163
);
167164
}

src/Command/ListProcessCommand.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@
2020
use Symfony\Component\Console\Input\InputInterface;
2121
use Symfony\Component\Console\Input\InputOption;
2222
use Symfony\Component\Console\Output\OutputInterface;
23-
use function array_reduce;
24-
use function count;
25-
use function max;
26-
use function usort;
2723

2824
/**
29-
* List all configured processes
25+
* List all configured processes.
3026
*/
31-
#[AsCommand(name: 'cleverage:process:list', description: 'List defined processes',)]
27+
#[AsCommand(name: 'cleverage:process:list', description: 'List defined processes', )]
3228
class ListProcessCommand extends Command
3329
{
3430
public function __construct(
@@ -54,7 +50,7 @@ public function processSorter(ProcessConfiguration $a, ProcessConfiguration $b):
5450

5551
public function maxMessageLengthFilter(int $max, array $message): int
5652
{
57-
return max($max, strlen($this->filterOutTags($message['output'])));
53+
return \max($max, \strlen($this->filterOutTags($message['output'])));
5854
}
5955

6056
protected function configure(): void
@@ -65,18 +61,18 @@ protected function configure(): void
6561
protected function execute(InputInterface $input, OutputInterface $output): int
6662
{
6763
$processConfigurations = $this->processConfigRegistry->getProcessConfigurations();
68-
usort($processConfigurations, $this->processSorter(...));
64+
\usort($processConfigurations, $this->processSorter(...));
6965

70-
$publicCount = array_reduce($processConfigurations, $this->publicProcessCounter(...), 0);
71-
$privateCount = array_reduce($processConfigurations, $this->privateProcessCounter(...), 0);
66+
$publicCount = \array_reduce($processConfigurations, $this->publicProcessCounter(...), 0);
67+
$privateCount = \array_reduce($processConfigurations, $this->privateProcessCounter(...), 0);
7268
$output->writeln(
7369
"<info>There are {$publicCount} process configurations defined (and {$privateCount} private) :</info>"
7470
);
7571

7672
$messages = [];
7773
foreach ($processConfigurations as $processConfiguration) {
7874
if ($processConfiguration->isPublic() || $input->getOption('all')) {
79-
$countTasks = count($processConfiguration->getTaskConfigurations());
75+
$countTasks = \count($processConfiguration->getTaskConfigurations());
8076
$message = "<info> - </info>{$processConfiguration->getCode()}<info> with {$countTasks} tasks</info>";
8177

8278
if ($processConfiguration->isPrivate()) {
@@ -91,7 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9187
}
9288

9389
// Add process descriptions at a fixed position
94-
$maxMessageLength = array_reduce($messages, $this->maxMessageLengthFilter(...), 0);
90+
$maxMessageLength = \array_reduce($messages, $this->maxMessageLengthFilter(...), 0);
9591
$outputMessages = [];
9692
foreach ($messages as $message) {
9793
/** @var ProcessConfiguration $processConfiguration */
@@ -116,7 +112,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
116112

117113
protected function padMessage(string $message, int $length = 80): string
118114
{
119-
$currentLen = strlen($this->filterOutTags($message));
115+
$currentLen = \strlen($this->filterOutTags($message));
120116
if ($currentLen < $length) {
121117
$message .= str_repeat(' ', $length - $currentLen);
122118
}

0 commit comments

Comments
 (0)