Skip to content

Commit 9932489

Browse files
authored
Add new CS rules (#1705)
* Alpha sort rules * Add native_function_invocation rule * Adapt code * Add no_alias_functions rule * Add is_null rule * Adapt code * Add native_constant_invocation rule * Adapt code * Allow risky rules
1 parent b29ece7 commit 9932489

File tree

59 files changed

+235
-231
lines changed

Some content is hidden

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

59 files changed

+235
-231
lines changed

.github/workflows/continuous-integration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
php-cs-fixer --version
2323
2424
- name: 'Check PHP code'
25-
run: 'php-cs-fixer fix --diff --dry-run --using-cache=false'
25+
run: 'php-cs-fixer fix --diff --dry-run --allow-risky=yes --using-cache=false'
2626

2727
- name: 'Check composer.json'
2828
run: 'composer-normalize --diff --dry-run --no-update-lock'

.php_cs.dist

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ return PhpCsFixer\Config::create()
1616
'combine_consecutive_issets' => true,
1717
'combine_consecutive_unsets' => true,
1818
'header_comment' => ['header' => $header],
19+
'is_null' => true,
1920
'linebreak_after_opening_tag' => true,
21+
'native_constant_invocation' => true,
22+
'native_function_invocation' => true,
23+
'no_alias_functions' => true,
2024
'no_useless_else' => true,
25+
'nullable_type_declaration_for_default_null_value' => true,
2126
'ordered_class_elements' => true,
2227
'ordered_imports' => true,
2328
'phpdoc_no_empty_return' => false,
2429
'ternary_to_null_coalescing' => true,
25-
'nullable_type_declaration_for_default_null_value' => true,
2630
'visibility_required' => ['property', 'method', 'const'],
2731
])
2832
->setUsingCache(true)

src/Command/CreateCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ protected function configure()
5757

5858
protected function execute(InputInterface $input, OutputInterface $output)
5959
{
60-
$indexes = (null !== $index = $input->getOption('index')) ? [$index] : array_keys($this->indexManager->getAllIndexes());
60+
$indexes = (null !== $index = $input->getOption('index')) ? [$index] : \array_keys($this->indexManager->getAllIndexes());
6161

6262
foreach ($indexes as $indexName) {
63-
$output->writeln(sprintf('<info>Creating</info> <comment>%s</comment>', $indexName));
63+
$output->writeln(\sprintf('<info>Creating</info> <comment>%s</comment>', $indexName));
6464

6565
$indexConfig = $this->configManager->getIndexConfiguration($indexName);
6666
$index = $this->indexManager->getIndex($indexName);

src/Command/DeleteCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ protected function configure()
5151
protected function execute(InputInterface $input, OutputInterface $output)
5252
{
5353
$indexName = $input->getOption('index');
54-
$indexes = null === $indexName ? array_keys($this->indexManager->getAllIndexes()) : [$indexName];
54+
$indexes = null === $indexName ? \array_keys($this->indexManager->getAllIndexes()) : [$indexName];
5555

5656
foreach ($indexes as $indexName) {
5757
$output->writeln(
58-
sprintf('<info>Deleting</info> <comment>%s</comment> ', $indexName)
58+
\sprintf('<info>Deleting</info> <comment>%s</comment> ', $indexName)
5959
);
6060
$index = $this->indexManager->getIndex($indexName);
6161
if (!$index->exists()) {
6262
$output->writeln(
63-
sprintf('<error>%s does not exist and can\'t be deleted</error>', $indexName)
63+
\sprintf('<error>%s does not exist and can\'t be deleted</error>', $indexName)
6464
);
6565

6666
continue;
@@ -78,7 +78,7 @@ private function deleteIndex(string $indexName): void
7878
$path = $indexName;
7979
$this->client->request($path, Request::DELETE);
8080
} catch (ExceptionInterface $deleteOldIndexException) {
81-
throw new \RuntimeException(sprintf('Failed to delete index "%s" with message: "%s"', $indexName, $deleteOldIndexException->getMessage()), 0, $deleteOldIndexException);
81+
throw new \RuntimeException(\sprintf('Failed to delete index "%s" with message: "%s"', $indexName, $deleteOldIndexException->getMessage()), 0, $deleteOldIndexException);
8282
}
8383
}
8484
}

src/Command/PopulateCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
119119

120120
protected function execute(InputInterface $input, OutputInterface $output)
121121
{
122-
$indexes = (null !== $index = $input->getOption('index')) ? [$index] : array_keys($this->indexManager->getAllIndexes());
122+
$indexes = (null !== $index = $input->getOption('index')) ? [$index] : \array_keys($this->indexManager->getAllIndexes());
123123
$reset = !$input->getOption('no-reset');
124124
$delete = !$input->getOption('no-delete');
125125

@@ -159,7 +159,7 @@ private function populateIndex(OutputInterface $output, string $index, bool $res
159159
$this->dispatcher->dispatch($event = new PreIndexPopulateEvent($index, $reset, $options));
160160

161161
if ($reset = $event->isReset()) {
162-
$output->writeln(sprintf('<info>Resetting</info> <comment>%s</comment>', $index));
162+
$output->writeln(\sprintf('<info>Resetting</info> <comment>%s</comment>', $index));
163163
$this->resetter->resetIndex($index, true);
164164
}
165165

@@ -170,17 +170,17 @@ private function populateIndex(OutputInterface $output, string $index, bool $res
170170
OnExceptionEvent::class,
171171
function (OnExceptionEvent $event) use ($loggerClosure) {
172172
$loggerClosure(
173-
count($event->getObjects()),
173+
\count($event->getObjects()),
174174
$event->getPager()->getNbResults(),
175-
sprintf('<error>%s</error>', $event->getException()->getMessage())
175+
\sprintf('<error>%s</error>', $event->getException()->getMessage())
176176
);
177177
}
178178
);
179179

180180
$this->dispatcher->addListener(
181181
PostInsertObjectsEvent::class,
182182
function (PostInsertObjectsEvent $event) use ($loggerClosure) {
183-
$loggerClosure(count($event->getObjects()), $event->getPager()->getNbResults());
183+
$loggerClosure(\count($event->getObjects()), $event->getPager()->getNbResults());
184184
}
185185
);
186186

@@ -205,7 +205,7 @@ function (OnExceptionEvent $event) {
205205
$provider = $this->pagerProviderRegistry->getProvider($index);
206206
$pager = $provider->provide($options);
207207

208-
$this->pagerPersister->insert($pager, array_merge($options, ['indexName' => $index]));
208+
$this->pagerPersister->insert($pager, \array_merge($options, ['indexName' => $index]));
209209

210210
$this->dispatcher->dispatch(new PostIndexPopulateEvent($index, $reset, $options));
211211

@@ -217,7 +217,7 @@ function (OnExceptionEvent $event) {
217217
*/
218218
private function refreshIndex(OutputInterface $output, string $index): void
219219
{
220-
$output->writeln(sprintf('<info>Refreshing</info> <comment>%s</comment>', $index));
220+
$output->writeln(\sprintf('<info>Refreshing</info> <comment>%s</comment>', $index));
221221
$this->indexManager->getIndex($index)->refresh();
222222
$output->writeln('');
223223
}

src/Command/ProgressClosureBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public static function build(OutputInterface $output, string $action, string $in
3636

3737
if (null !== $message) {
3838
$progress->clear();
39-
$output->writeln(sprintf('<info>%s</info> <error>%s</error>', $action, $message));
39+
$output->writeln(\sprintf('<info>%s</info> <error>%s</error>', $action, $message));
4040
$progress->display();
4141
}
4242

43-
$progress->setMessage(sprintf('<info>%s</info> <comment>%s</comment>', $action, $index));
43+
$progress->setMessage(\sprintf('<info>%s</info> <comment>%s</comment>', $action, $index));
4444
$progress->advance($increment);
4545
};
4646
}

src/Command/ResetCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ protected function configure()
5050

5151
protected function execute(InputInterface $input, OutputInterface $output)
5252
{
53-
$indexes = (null !== $index = $input->getOption('index')) ? [$index] : array_keys($this->indexManager->getAllIndexes());
53+
$indexes = (null !== $index = $input->getOption('index')) ? [$index] : \array_keys($this->indexManager->getAllIndexes());
5454
$force = (bool) $input->getOption('force');
5555

5656
foreach ($indexes as $index) {
57-
$output->writeln(sprintf('<info>Resetting</info> <comment>%s</comment>', $index));
57+
$output->writeln(\sprintf('<info>Resetting</info> <comment>%s</comment>', $index));
5858
$this->resetter->resetIndex($index, false, $force);
5959
}
6060

src/Command/ResetTemplatesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7878
}
7979

8080
if (null !== $indexTemplate) {
81-
$output->writeln(sprintf('<info>Resetting template</info> <comment>%s</comment>', $indexTemplate));
81+
$output->writeln(\sprintf('<info>Resetting template</info> <comment>%s</comment>', $indexTemplate));
8282
$this->resetter->resetIndex($indexTemplate, $deleteByPattern);
8383
} else {
8484
$output->writeln('<info>Resetting all templates</info>');

src/Command/SearchCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6363

6464
$resultSet = $index->search($query);
6565

66-
$output->writeLn(sprintf('Found %d results', $index->count($query)));
66+
$output->writeLn(\sprintf('Found %d results', $index->count($query)));
6767
foreach ($resultSet->getResults() as $result) {
6868
$output->writeLn($this->formatResult($result, $input->getOption('show-field'), $input->getOption('show-source'), $input->getOption('show-id'), $input->getOption('explain')));
6969
}
@@ -85,17 +85,17 @@ protected function formatResult(Result $result, $showField, $showSource, $showId
8585
if ($showField) {
8686
$toString = $source[$showField] ?? '-';
8787
} else {
88-
$toString = reset($source);
88+
$toString = \reset($source);
8989
}
90-
$string = sprintf('[%0.2f] %s', $result->getScore(), var_export($toString, true));
90+
$string = \sprintf('[%0.2f] %s', $result->getScore(), \var_export($toString, true));
9191
if ($showSource) {
92-
$string = sprintf('%s %s', $string, json_encode($source));
92+
$string = \sprintf('%s %s', $string, \json_encode($source));
9393
}
9494
if ($showId) {
95-
$string = sprintf('{%s} %s', $result->getId(), $string);
95+
$string = \sprintf('{%s} %s', $result->getId(), $string);
9696
}
9797
if ($explain) {
98-
$string = sprintf('%s %s', $string, json_encode($result->getExplanation()));
98+
$string = \sprintf('%s %s', $string, \json_encode($result->getExplanation()));
9999
}
100100

101101
return $string;

src/Configuration/ConfigManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ class ConfigManager implements ManagerInterface
2727
public function __construct(array $sources)
2828
{
2929
foreach ($sources as $source) {
30-
$this->indexes = array_merge($source->getConfiguration(), $this->indexes);
30+
$this->indexes = \array_merge($source->getConfiguration(), $this->indexes);
3131
}
3232
}
3333

3434
public function getIndexConfiguration(string $indexName): IndexConfigInterface
3535
{
3636
if (!$this->hasIndexConfiguration($indexName)) {
37-
throw new \InvalidArgumentException(sprintf('Index "%s" is not configured.', $indexName));
37+
throw new \InvalidArgumentException(\sprintf('Index "%s" is not configured.', $indexName));
3838
}
3939

4040
return $this->indexes[$indexName];
4141
}
4242

4343
public function getIndexNames(): array
4444
{
45-
return array_keys($this->indexes);
45+
return \array_keys($this->indexes);
4646
}
4747

4848
public function hasIndexConfiguration(string $indexName): bool

0 commit comments

Comments
 (0)