Skip to content

Commit 9a10410

Browse files
change phpcsfixer to symfony version
1 parent 4e0069c commit 9a10410

26 files changed

+97
-144
lines changed

.php-cs-fixer.dist.php

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
11
<?php
22

3-
$finder = PhpCsFixer\Finder::create()
4-
->in(__DIR__)
5-
->ignoreDotFiles(true)
6-
->ignoreVCS(true)
7-
->exclude(['build', 'vendor'])
8-
->files()
9-
->name('*.php')
10-
;
3+
/*
4+
* This file is part of the CleverAge/ProcessBundle package.
5+
*
6+
* Copyright (c) 2017-2023 Clever-Age
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
1111

12-
$config = new PhpCsFixer\Config();
12+
if (!file_exists(__DIR__.'/src')) {
13+
exit(0);
14+
}
1315

14-
return $config
15-
->setUsingCache(true)
16-
->setRiskyAllowed(true)
17-
->setFinder($finder)
16+
$fileHeaderComment = <<<'EOF'
17+
This file is part of the CleverAge/ProcessBundle package.
18+
19+
Copyright (c) 2017-2023 Clever-Age
20+
21+
For the full copyright and license information, please view the LICENSE
22+
file that was distributed with this source code.
23+
EOF;
24+
25+
return (new PhpCsFixer\Config())
1826
->setRules([
27+
'@PHP71Migration' => true,
28+
'@PHPUnit75Migration:risky' => true,
1929
'@Symfony' => true,
2030
'@Symfony:risky' => true,
21-
'@PHPUnit48Migration:risky' => true,
22-
'array_syntax' => ['syntax' => 'short'],
23-
'fopen_flags' => false,
24-
'ordered_imports' => true,
2531
'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,
32+
'native_constant_invocation' => ['strict' => false],
33+
'header_comment' => ['header' => $fileHeaderComment],
34+
'modernize_strpos' => true,
35+
'get_class_to_class_keyword' => true,
3736
])
37+
->setRiskyAllowed(true)
38+
->setFinder(
39+
(new PhpCsFixer\Finder())
40+
->in(__DIR__.'/src')
41+
->append([__FILE__])
42+
)
43+
->setCacheFile('.php-cs-fixer.cache')
3844
;

src/Command/ExecuteProcessCommand.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ protected function handleOutputData(mixed $data, InputInterface $input, OutputIn
141141
} elseif (self::OUTPUT_FORMAT_JSON === $input->getOption('output-format')) {
142142
$output->writeln(json_encode($data, \JSON_THROW_ON_ERROR));
143143
} else {
144-
throw new \InvalidArgumentException(
145-
sprintf("Cannot handle data output with format '%s'", $input->getOption('output-format'))
146-
);
144+
throw new \InvalidArgumentException(sprintf("Cannot handle data output with format '%s'", $input->getOption('output-format')));
147145
}
148146
}
149147
} elseif (self::OUTPUT_FORMAT_JSON === $input->getOption('output-format')) {
@@ -158,9 +156,7 @@ protected function handleOutputData(mixed $data, InputInterface $input, OutputIn
158156
$output->writeln(sprintf("Output stored in '%s'", $input->getOption('output')));
159157
}
160158
} else {
161-
throw new \InvalidArgumentException(
162-
sprintf("Cannot handle data output with format '%s'", $input->getOption('output-format'))
163-
);
159+
throw new \InvalidArgumentException(sprintf("Cannot handle data output with format '%s'", $input->getOption('output-format')));
164160
}
165161
}
166162
}

src/Command/ListProcessCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function processSorter(ProcessConfiguration $a, ProcessConfiguration $b):
5050

5151
public function maxMessageLengthFilter(int $max, array $message): int
5252
{
53-
return \max($max, \strlen($this->filterOutTags($message['output'])));
53+
return max($max, \strlen($this->filterOutTags($message['output'])));
5454
}
5555

5656
protected function configure(): void
@@ -61,10 +61,10 @@ protected function configure(): void
6161
protected function execute(InputInterface $input, OutputInterface $output): int
6262
{
6363
$processConfigurations = $this->processConfigRegistry->getProcessConfigurations();
64-
\usort($processConfigurations, $this->processSorter(...));
64+
usort($processConfigurations, $this->processSorter(...));
6565

66-
$publicCount = \array_reduce($processConfigurations, $this->publicProcessCounter(...), 0);
67-
$privateCount = \array_reduce($processConfigurations, $this->privateProcessCounter(...), 0);
66+
$publicCount = array_reduce($processConfigurations, $this->publicProcessCounter(...), 0);
67+
$privateCount = array_reduce($processConfigurations, $this->privateProcessCounter(...), 0);
6868
$output->writeln(
6969
"<info>There are {$publicCount} process configurations defined (and {$privateCount} private) :</info>"
7070
);
@@ -87,7 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8787
}
8888

8989
// Add process descriptions at a fixed position
90-
$maxMessageLength = \array_reduce($messages, $this->maxMessageLengthFilter(...), 0);
90+
$maxMessageLength = array_reduce($messages, $this->maxMessageLengthFilter(...), 0);
9191
$outputMessages = [];
9292
foreach ($messages as $message) {
9393
/** @var ProcessConfiguration $processConfiguration */

src/Command/ProcessHelpCommand.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ static function ($taskCode, $i) use ($gapBranches, $origin, $final, $branches):
376376
foreach ($nextTasks as $nextTask) {
377377
$index = array_search(null, $branches, true);
378378
if (false !== $index && $index >= $origin) {
379-
/** @var int $index */
379+
/* @var int $index */
380380
$branches[$index] = $taskCode;
381381
$expandBranches[] = $index;
382382
} else {
@@ -446,8 +446,8 @@ protected function writeBranches(
446446
OutputInterface $output,
447447
array $branches,
448448
string|iterable $comment = '',
449-
?callable $match = null,
450-
string|callable|null $char = null
449+
callable $match = null,
450+
string|callable $char = null
451451
): void {
452452
$output->write(str_repeat(' ', self::INDENT_SIZE));
453453

@@ -525,14 +525,10 @@ protected function getTaskService(TaskConfiguration $taskConfiguration): TaskInt
525525
} elseif ($this->container->has($serviceReference)) {
526526
$task = $this->container->get($serviceReference);
527527
} else {
528-
throw new \UnexpectedValueException(
529-
"Unable to resolve service reference for Task '{$taskConfiguration->getCode()}'"
530-
);
528+
throw new \UnexpectedValueException("Unable to resolve service reference for Task '{$taskConfiguration->getCode()}'");
531529
}
532530
if (!$task instanceof TaskInterface) {
533-
throw new \UnexpectedValueException(
534-
"Service defined in Task '{$taskConfiguration->getCode()}' is not a TaskInterface"
535-
);
531+
throw new \UnexpectedValueException("Service defined in Task '{$taskConfiguration->getCode()}' is not a TaskInterface");
536532
}
537533

538534
return $task;

src/Exception/TransformerException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TransformerException extends \RuntimeException implements ProcessException
2323
public function __construct(
2424
protected string $transformerCode,
2525
int $code = 0,
26-
?\Throwable $previous = null
26+
\Throwable $previous = null
2727
) {
2828
parent::__construct('', $code, $previous);
2929
$this->updateMessage();

src/Filesystem/CsvFile.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(
2929
string $delimiter = ',',
3030
string $enclosure = '"',
3131
string $escape = '\\',
32-
?array $headers = null,
32+
array $headers = null,
3333
string $mode = 'rb'
3434
) {
3535
if (!\in_array($filePath, ['php://stdin', 'php://stdout', 'php://stderr'], true)) {
@@ -47,9 +47,7 @@ public function __construct(
4747
$readAllowedModes = ['r', 'r+', 'w+', 'a+', 'x+', 'c+'];
4848
if (null === $headers && !\in_array(str_replace('b', '', $mode), $readAllowedModes, true)) {
4949
// Cannot read headers if the file was just created
50-
throw new \UnexpectedValueException(
51-
"Invalid headers for {$this->getResourceName()}, you need to pass the headers manually"
52-
);
50+
throw new \UnexpectedValueException("Invalid headers for {$this->getResourceName()}, you need to pass the headers manually");
5351
}
5452

5553
parent::__construct($resource, $delimiter, $enclosure, $escape, $headers);

src/Filesystem/CsvResource.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(
4444
protected string $delimiter = ',',
4545
protected string $enclosure = '"',
4646
protected string $escape = '\\',
47-
?array $headers = null
47+
array $headers = null
4848
) {
4949
if (!\is_resource($resource)) {
5050
$type = \gettype($resource);
@@ -149,15 +149,15 @@ public function isEndOfFile(): bool
149149
/**
150150
* Warning, this function will return exactly the same value as the fgetcsv() function.
151151
*/
152-
public function readRaw(?int $length = null): array|false
152+
public function readRaw(int $length = null): array|false
153153
{
154154
$this->assertOpened();
155155
++$this->lineNumber;
156156

157157
return fgetcsv($this->handler, $length, $this->delimiter, $this->enclosure, $this->escape);
158158
}
159159

160-
public function readLine(?int $length = null): ?array
160+
public function readLine(int $length = null): ?array
161161
{
162162
if ($this->seekCalled) {
163163
$filePosition = "at position {$this->tell()}";
@@ -290,7 +290,7 @@ protected function assertOpened(): void
290290
}
291291
}
292292

293-
protected function parseHeaders(?array $headers = null): array
293+
protected function parseHeaders(array $headers = null): array
294294
{
295295
// If headers are not passed in the constructor but file is readable, try to read headers from file
296296
if (null === $headers) {
@@ -308,15 +308,11 @@ protected function parseHeaders(?array $headers = null): array
308308
$this->manualHeaders = true;
309309

310310
if (!\is_array($headers)) {
311-
throw new \UnexpectedValueException(
312-
"Invalid headers for {$this->getResourceName()}, you need to pass the headers manually"
313-
);
311+
throw new \UnexpectedValueException("Invalid headers for {$this->getResourceName()}, you need to pass the headers manually");
314312
}
315313

316314
if (0 === \count($headers)) {
317-
throw new \UnexpectedValueException(
318-
"Empty headers for {$this->getResourceName()}, you need to pass the headers manually"
319-
);
315+
throw new \UnexpectedValueException("Empty headers for {$this->getResourceName()}, you need to pass the headers manually");
320316
}
321317

322318
return $headers;

src/Filesystem/FileStreamInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function getLineNumber(): int;
2727

2828
public function isEndOfFile(): bool;
2929

30-
public function readLine(?int $length = null): ?array;
30+
public function readLine(int $length = null): ?array;
3131

3232
/**
3333
* This methods rewinds the file to the first line of data, skipping the headers.

src/Filesystem/JsonStreamFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function isEndOfFile(): bool
6565
/**
6666
* Return an array containing current data and moving the file pointer.
6767
*/
68-
public function readLine(?int $length = null): ?array
68+
public function readLine(int $length = null): ?array
6969
{
7070
if ($this->isEndOfFile()) {
7171
return null;

src/Manager/ProcessManager.php

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,10 @@ protected function initialize(TaskConfiguration $taskConfiguration): void
238238
} elseif ($this->container->has($serviceReference)) {
239239
$task = $this->container->get($serviceReference);
240240
} else {
241-
throw new \UnexpectedValueException(
242-
"Unable to resolve service reference for Task '{$taskConfiguration->getCode()}'"
243-
);
241+
throw new \UnexpectedValueException("Unable to resolve service reference for Task '{$taskConfiguration->getCode()}'");
244242
}
245243
if (!$task instanceof TaskInterface) {
246-
throw new \UnexpectedValueException(
247-
"Service defined in Task '{$taskConfiguration->getCode()}' is not a TaskInterface"
248-
);
244+
throw new \UnexpectedValueException("Service defined in Task '{$taskConfiguration->getCode()}' is not a TaskInterface");
249245
}
250246
$taskConfiguration->setTask($task);
251247

@@ -299,16 +295,7 @@ protected function process(TaskConfiguration $taskConfiguration, int $executionF
299295
$m .= " during process {$state->getTaskConfiguration()
300296
->getCode()}";
301297
$m .= " with message: '{$exception->getMessage()}'.\n";
302-
throw new FatalError(
303-
$m,
304-
-1,
305-
[
306-
'file' => $exception->getFile(),
307-
'line' => $exception->getLine(),
308-
'type' => 500,
309-
'message' => $exception->getMessage(),
310-
]
311-
);
298+
throw new FatalError($m, -1, ['file' => $exception->getFile(), 'line' => $exception->getLine(), 'type' => 500, 'message' => $exception->getMessage()]);
312299
}
313300

314301
return;
@@ -421,9 +408,7 @@ protected function processExecution(TaskConfiguration $taskConfiguration, int $e
421408
} elseif (TaskConfiguration::STRATEGY_STOP === $taskConfiguration->getErrorStrategy()) {
422409
$state->stop($exception);
423410
} else {
424-
throw new \UnexpectedValueException(
425-
"Unknown error strategy '{$taskConfiguration->getErrorStrategy()}'"
426-
);
411+
throw new \UnexpectedValueException("Unknown error strategy '{$taskConfiguration->getErrorStrategy()}'");
427412
}
428413
}
429414
}
@@ -566,18 +551,10 @@ protected function checkProcess(ProcessConfiguration $processConfiguration): voi
566551
// Check coherence for entry/end points
567552
$processConfiguration->getEndPoint();
568553
if ($entryPoint && !\in_array($entryPoint->getCode(), $mainTaskList, true)) {
569-
throw InvalidProcessConfigurationException::createNotInMain(
570-
$processConfiguration,
571-
$entryPoint,
572-
$mainTaskList
573-
);
554+
throw InvalidProcessConfigurationException::createNotInMain($processConfiguration, $entryPoint, $mainTaskList);
574555
}
575556
if ($endPoint && !\in_array($endPoint->getCode(), $mainTaskList, true)) {
576-
throw InvalidProcessConfigurationException::createNotInMain(
577-
$processConfiguration,
578-
$endPoint,
579-
$mainTaskList
580-
);
557+
throw InvalidProcessConfigurationException::createNotInMain($processConfiguration, $endPoint, $mainTaskList);
581558
}
582559
}
583560

0 commit comments

Comments
 (0)