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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"symfony/translation": "^6.4|^7.0",
"symfony/twig-bundle": "^6.4|^7.0",
"symfony/yaml": "^6.4|^7.0",
"symplify/easy-coding-standard": "^11.3"
"symplify/easy-coding-standard": "^12.5"
},
"replace": {
"yokai/batch": "self.version",
Expand Down
102 changes: 62 additions & 40 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,79 @@
declare(strict_types=1);

use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
use PhpCsFixer\Fixer\Basic\SingleLineEmptyBodyFixer;
use PhpCsFixer\Fixer\CastNotation\CastSpacesFixer;
use PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer;
use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer;
use PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer;
use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer;
use PhpCsFixer\Fixer\LanguageConstruct\NullableTypeDeclarationFixer;
use PhpCsFixer\Fixer\StringNotation\ExplicitStringVariableFixer;
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\StandaloneLineInMultilineArrayFixer;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests/convention',
__DIR__ . '/tests/integration',
__DIR__ . '/tests/symfony/src',
__DIR__ . '/tests/symfony/tests',
]);
$composer = \json_decode(\file_get_contents(__DIR__.'/composer.json'), true);

$ecsConfig->sets([
SetList::ARRAY,
SetList::DOCBLOCK,
SetList::NAMESPACES,
SetList::COMMENTS,
SetList::STRICT,
SetList::PSR_12,
]);

$ecsConfig->skip([
/* Do not force array on multiple lines : ['foo' => $foo, 'bar' => $bar] */
ArrayOpenerAndCloserNewlineFixer::class,
ArrayListItemNewlineFixer::class,
StandaloneLineInMultilineArrayFixer::class,
]);

$ecsConfig->ruleWithConfiguration(YodaStyleFixer::class, [
'equal' => false,
'identical' => false,
'less_and_greater' => false,
]);
$ecsConfig->ruleWithConfiguration(LineLengthFixer::class, [
LineLengthFixer::INLINE_SHORT_LINES => false,
]);
$ecsConfig->ruleWithConfiguration(ForbiddenFunctionsSniff::class, [
return ECSConfig::configure()
->withPaths(\array_map(
fn(string $path) => __DIR__ . '/' . $path,
[
...\array_values($composer['autoload']['psr-4']),
...\array_values($composer['autoload-dev']['psr-4']),
]
))
->withPhpCsFixerSets(
// https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/PER-CS2.0.rst
perCS20: true,
)
->withPreparedSets(
arrays: true,
comments: true,
docblocks: true,
namespaces: true,
phpunit: true,
strict: true,
)
->withConfiguredRule(BlankLineBeforeStatementFixer::class, [
'statements' => ['case', 'continue', 'declare', 'default', 'return', 'throw', 'try'],
])
->withConfiguredRule(CastSpacesFixer::class, [
'space' => 'none',
])
->withConfiguredRule(ForbiddenFunctionsSniff::class, [
'forbiddenFunctions' => ['dump' => null, 'dd' => null, 'var_dump' => null, 'die' => null],
]);
$ecsConfig->ruleWithConfiguration(FunctionDeclarationFixer::class, [
])
->withConfiguredRule(FunctionDeclarationFixer::class, [
'closure_fn_spacing' => 'none',
]);
$ecsConfig->ruleWithConfiguration(NativeFunctionInvocationFixer::class, [
])
->withConfiguredRule(LineLengthFixer::class, [
LineLengthFixer::INLINE_SHORT_LINES => false,
])
->withConfiguredRule(NativeFunctionInvocationFixer::class, [
'scope' => 'namespaced',
'include' => ['@all'],
]);
};
])
->withConfiguredRule(NullableTypeDeclarationFixer::class, [
'syntax' => 'union',
])
->withConfiguredRule(YodaStyleFixer::class, [
'equal' => false,
'identical' => false,
'less_and_greater' => false,
])
->withConfiguredRule(ClassDefinitionFixer::class, [
'inline_constructor_arguments' => false,
'space_before_parenthesis' => false,
])
->withSkip([
SingleLineEmptyBodyFixer::class,
ArrayListItemNewlineFixer::class,
ArrayOpenerAndCloserNewlineFixer::class,
ExplicitStringVariableFixer::class,
StandaloneLineInMultilineArrayFixer::class,
])
;
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,15 @@ public function query(Query $query): iterable
case Query::SORT_BY_START_ASC:
$qb->orderBy('start_time', 'asc');
break;

case Query::SORT_BY_START_DESC:
$qb->orderBy('start_time', 'desc');
break;

case Query::SORT_BY_END_ASC:
$qb->orderBy('end_time', 'asc');
break;

case Query::SORT_BY_END_DESC:
$qb->orderBy('end_time', 'desc');
break;
Expand Down Expand Up @@ -273,7 +276,7 @@ private function fetchRow(string $jobName, string $id): array
$statement = $this->connection->executeQuery(
$qb->getSQL(),
['jobName' => $jobName, 'id' => $id],
['jobName' => Types::STRING, 'id' => Types::STRING]
['jobName' => Types::STRING, 'id' => Types::STRING],
);

/** @var array<string, string>|null $row */
Expand Down
8 changes: 4 additions & 4 deletions src/batch-doctrine-dbal/src/DoctrineDBALQueryCursorReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public function __construct(
) {
if (!\str_contains($sql, '{after}') || !\str_contains($sql, '{limit}')) {
throw new InvalidArgumentException(
\sprintf('%s $sql argument must contains "{after}" and "{limit}" for pagination.', __METHOD__)
\sprintf('%s $sql argument must contains "{after}" and "{limit}" for pagination.', __METHOD__),
);
}
if ($batch <= 0) {
throw new InvalidArgumentException(
\sprintf('%s $batch argument must be a positive integer.', __METHOD__)
\sprintf('%s $batch argument must be a positive integer.', __METHOD__),
);
}

Expand All @@ -64,7 +64,7 @@ public function read(): Generator
do {
/** @var Result $statement */
$statement = $this->connection->executeQuery(
\strtr($this->sql, ['{limit}' => $this->batch, '{after}' => $after])
\strtr($this->sql, ['{limit}' => $this->batch, '{after}' => $after]),
);

/** @var array<array<string, string>> $rows */
Expand All @@ -74,7 +74,7 @@ public function read(): Generator
if ($lastRowIdx !== null) {
if (!isset($rows[$lastRowIdx][$this->column])) {
throw new LogicException(
\sprintf('Query must include "%s" column in results.', $this->column)
\sprintf('Query must include "%s" column in results.', $this->column),
);
}
$after = $rows[$lastRowIdx][$this->column];
Expand Down
6 changes: 3 additions & 3 deletions src/batch-doctrine-dbal/src/DoctrineDBALQueryOffsetReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public function __construct(ConnectionRegistry $doctrine, string $sql, string $c
{
if (\mb_strpos($sql, '{limit}') === false || \mb_strpos($sql, '{offset}') === false) {
throw new InvalidArgumentException(
\sprintf('%s $sql argument must contains "{limit}" and "{offset}" for pagination.', __METHOD__)
\sprintf('%s $sql argument must contains "{limit}" and "{offset}" for pagination.', __METHOD__),
);
}
if ($batch <= 0) {
throw new InvalidArgumentException(
\sprintf('%s $batch argument must be a positive integer.', __METHOD__)
\sprintf('%s $batch argument must be a positive integer.', __METHOD__),
);
}

Expand All @@ -52,7 +52,7 @@ public function read(): Generator
do {
/** @var Result $statement */
$statement = $this->connection->executeQuery(
\strtr($this->sql, ['{limit}' => $this->batch, '{offset}' => $iteration * $this->batch])
\strtr($this->sql, ['{limit}' => $this->batch, '{offset}' => $iteration * $this->batch]),
);

/** @var array<array<string, string>> $rows */
Expand Down
4 changes: 2 additions & 2 deletions src/batch-doctrine-dbal/src/DoctrineDBALUpsertWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public function write(iterable $items): void
new Warning(
'Update affected more than one line.',
[],
['table' => $item->getTable(), 'identity' => $item->getIdentity(), 'count' => $affected]
)
['table' => $item->getTable(), 'identity' => $item->getIdentity(), 'count' => $affected],
),
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/batch-doctrine-dbal/src/JobExecutionRowNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function fromRow(array $data, JobExecution $parent = null): JobExecution
$status,
$parameters,
$summary,
new JobExecutionLogs($data['logs'])
new JobExecutionLogs($data['logs']),
);
}

Expand Down Expand Up @@ -134,7 +134,7 @@ private function jsonFromString(array|string $value): array
return $value;
}

private function dateFromString(?string $date): ?DateTimeImmutable
private function dateFromString(null|string $date): null|DateTimeImmutable
{
if ($date === null) {
return null;
Expand Down Expand Up @@ -167,7 +167,7 @@ private function failureFromArray(array $array): Failure
$array['message'],
$array['code'],
$array['parameters'],
$array['trace']
$array['trace'],
);
}

Expand All @@ -191,7 +191,7 @@ private function warningFromArray(array $array): Warning
return new Warning($array['message'], $array['parameters'], $array['context']);
}

private function toDateString(?DateTimeInterface $date): ?string
private function toDateString(null|DateTimeInterface $date): null|string
{
if ($date === null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testCreateStandardTable(): void
'child_executions',
'logs',
],
\array_keys($columns)
\array_keys($columns),
);
}

Expand All @@ -81,7 +81,7 @@ public function testCreateCustomTable(): void
'child_executions',
'logs',
],
\array_keys($columns)
\array_keys($columns),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public function test(): void
'id',
0,
null,
4 // we will take 4 records at once : 3 queries expected
4, // we will take 4 records at once : 3 queries expected
);

$read = \array_map(
fn(array $row) => \array_map('strval', $row),
\iterator_to_array($reader->read(), false)
\iterator_to_array($reader->read(), false),
);

self::assertSame([
Expand All @@ -61,7 +61,7 @@ public function testQueryMustContainsAfterPlaceholder(): void
$this->doctrine,
'SELECT * FROM some table WHERE id > 0 LIMIT {limit};',
'id',
0
0,
);
}

Expand All @@ -72,7 +72,7 @@ public function testQueryMustContainsLimitPlaceholder(): void
$this->doctrine,
'SELECT * FROM some table WHERE id > {after} LIMIT 1;',
'id',
0
0,
);
}

Expand All @@ -85,7 +85,7 @@ public function testBatchMustBePositiveInteger(): void
'id',
0,
null,
-1 // must be > 0
-1, // must be > 0
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public function test(): void
$this->doctrine,
'SELECT * FROM numbers LIMIT {limit} OFFSET {offset};',
null,
4 // we will take 4 records at once : 3 queries expected
4, // we will take 4 records at once : 3 queries expected
);

$read = \array_map(
fn(array $row) => \array_map('strval', $row),
\iterator_to_array($reader->read(), false)
\iterator_to_array($reader->read(), false),
);

self::assertSame([
Expand Down Expand Up @@ -72,7 +72,7 @@ public function testBatchMustBePositiveInteger(): void
$this->doctrine,
'SELECT * FROM some table LIMIT {limit} OFFSET {offset};',
null,
0 // must be > 0
0, // must be > 0
);
}
}
2 changes: 1 addition & 1 deletion src/batch-doctrine-dbal/tests/DoctrineDBALTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function findAll(string $table): array

return \array_map(
fn(array $row) => \array_map('strval', $row),
$results->fetchAllAssociative()
$results->fetchAllAssociative(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function test(): void
self::assertSame('Update affected more than one line.', $warnings[0]->getMessage());
self::assertSame(
['table' => 'food', 'identity' => ['type' => 'fruit'], 'count' => 2],
$warnings[0]->getContext()
$warnings[0]->getContext(),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/batch-doctrine-orm/src/EntityReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function read(): iterable
throw UnexpectedValueException::type(
EntityManagerInterface::class,
$manager,
'Provided class must be a valid Doctrine entity.'
'Provided class must be a valid Doctrine entity.',
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/batch-doctrine-persistence/src/ObjectRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(
*
* @return T|null
*/
public function findOneBy(string $class, array $criteria): ?object
public function findOneBy(string $class, array $criteria): null|object
{
return $this->findOneUsing(
$class,
Expand All @@ -44,7 +44,7 @@ function ($repository) use ($criteria) {

return $repository->findOneBy($criteria);
},
\serialize($criteria)
\serialize($criteria),
);
}

Expand All @@ -58,7 +58,7 @@ function ($repository) use ($criteria) {
*
* @return T|null
*/
public function findOneUsing(string $class, \Closure $closure, string $key = null): ?object
public function findOneUsing(string $class, \Closure $closure, string $key = null): null|object
{
$manager = $this->doctrine->getManagerForClass($class);
if ($manager === null) {
Expand Down
Loading
Loading