Skip to content

Commit 835a737

Browse files
authored
Merge pull request #339 from norkunas/cs-release
Add cs fixer `native_function_invocation` rule from meilisearch-php
2 parents a832398 + 2b72ab6 commit 835a737

19 files changed

+73
-72
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
->setRules([
1515
'@Symfony' => true,
1616
'@PHP80Migration:risky' => true,
17+
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'],
1718
'global_namespace_import' => [
1819
'import_classes' => false,
1920
'import_functions' => false,

src/Collection.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function all(): array
2929

3030
public function get($key, $default = null)
3131
{
32-
if (array_key_exists($key, $this->items)) {
32+
if (\array_key_exists($key, $this->items)) {
3333
return $this->items[$key];
3434
}
3535

@@ -123,7 +123,7 @@ public function each(callable $callback)
123123
*/
124124
public function unique($key = null, bool $strict = false)
125125
{
126-
if (is_null($key) && false === $strict) {
126+
if (\is_null($key) && false === $strict) {
127127
return new self(array_unique($this->items, SORT_REGULAR));
128128
}
129129

@@ -132,7 +132,7 @@ public function unique($key = null, bool $strict = false)
132132
$exists = [];
133133

134134
return $this->reject(function ($item, $key) use ($callback, $strict, &$exists) {
135-
if (in_array($id = $callback($item, $key), $exists, $strict)) {
135+
if (\in_array($id = $callback($item, $key), $exists, $strict)) {
136136
return true;
137137
}
138138

@@ -145,7 +145,7 @@ public function unique($key = null, bool $strict = false)
145145
*/
146146
public function first(?callable $callback = null, $default = null)
147147
{
148-
if (is_null($callback)) {
148+
if (\is_null($callback)) {
149149
if (empty($this->items)) {
150150
return $default instanceof \Closure ? $default() : $default;
151151
}
@@ -171,7 +171,7 @@ public function first(?callable $callback = null, $default = null)
171171
*/
172172
public function firstWhere($key, $operator = null, $value = null)
173173
{
174-
return $this->first($this->operatorForWhere(...func_get_args()));
174+
return $this->first($this->operatorForWhere(...\func_get_args()));
175175
}
176176

177177
public function offsetExists($offset): bool
@@ -190,7 +190,7 @@ public function offsetGet($offset)
190190

191191
public function offsetSet($offset, $value): void
192192
{
193-
if (is_null($offset)) {
193+
if (\is_null($offset)) {
194194
$this->items[] = $value;
195195
} else {
196196
$this->items[$offset] = $value;
@@ -204,7 +204,7 @@ public function offsetUnset($offset): void
204204

205205
public function count(): int
206206
{
207-
return count($this->items);
207+
return \count($this->items);
208208
}
209209

210210
public function getIterator(): \ArrayIterator
@@ -214,7 +214,7 @@ public function getIterator(): \ArrayIterator
214214

215215
private function getArrayableItems($items): array
216216
{
217-
if (is_array($items)) {
217+
if (\is_array($items)) {
218218
return $items;
219219
}
220220

@@ -239,7 +239,7 @@ private function getArrayableItems($items): array
239239

240240
private function useAsCallable($value): bool
241241
{
242-
return !is_string($value) && is_callable($value);
242+
return !\is_string($value) && \is_callable($value);
243243
}
244244

245245
/**
@@ -261,23 +261,23 @@ private function valueRetriever($value)
261261
*/
262262
private static function getDeepData($target, $key, $default = null)
263263
{
264-
if (is_null($key)) {
264+
if (\is_null($key)) {
265265
return $target;
266266
}
267267

268-
$key = is_array($key) ? $key : explode('.', $key);
268+
$key = \is_array($key) ? $key : explode('.', $key);
269269

270270
foreach ($key as $i => $segment) {
271271
unset($key[$i]);
272272

273-
if (is_null($segment)) {
273+
if (\is_null($segment)) {
274274
return $target;
275275
}
276276

277277
if ('*' === $segment) {
278278
if ($target instanceof self) {
279279
$target = $target->all();
280-
} elseif (!is_array($target)) {
280+
} elseif (!\is_array($target)) {
281281
return $default instanceof \Closure ? $default() : $default;
282282
}
283283

@@ -287,12 +287,12 @@ private static function getDeepData($target, $key, $default = null)
287287
$result[] = self::getDeepData($item, $key);
288288
}
289289

290-
return in_array('*', $key, true) ? self::arrayCollapse($result) : $result;
290+
return \in_array('*', $key, true) ? self::arrayCollapse($result) : $result;
291291
}
292292

293293
if (self::accessible($target) && self::existsInArray($target, $segment)) {
294294
$target = $target[$segment];
295-
} elseif (is_object($target) && isset($target->{$segment})) {
295+
} elseif (\is_object($target) && isset($target->{$segment})) {
296296
$target = $target->{$segment};
297297
} else {
298298
return $default instanceof \Closure ? $default() : $default;
@@ -309,7 +309,7 @@ public static function arrayCollapse(iterable $array): array
309309
foreach ($array as $values) {
310310
if ($values instanceof self) {
311311
$values = $values->all();
312-
} elseif (!is_array($values)) {
312+
} elseif (!\is_array($values)) {
313313
continue;
314314
}
315315

@@ -321,7 +321,7 @@ public static function arrayCollapse(iterable $array): array
321321

322322
public static function accessible($value): bool
323323
{
324-
return is_array($value) || $value instanceof \ArrayAccess;
324+
return \is_array($value) || $value instanceof \ArrayAccess;
325325
}
326326

327327
/**
@@ -336,18 +336,18 @@ private static function existsInArray($array, $key): bool
336336
return $array->offsetExists($key);
337337
}
338338

339-
return array_key_exists($key, $array);
339+
return \array_key_exists($key, $array);
340340
}
341341

342342
private function operatorForWhere(string $key, ?string $operator = null, $value = null): \Closure
343343
{
344-
if (1 === func_num_args()) {
344+
if (1 === \func_num_args()) {
345345
$value = true;
346346

347347
$operator = '=';
348348
}
349349

350-
if (2 === func_num_args()) {
350+
if (2 === \func_num_args()) {
351351
$value = $operator;
352352

353353
$operator = '=';
@@ -356,10 +356,10 @@ private function operatorForWhere(string $key, ?string $operator = null, $value
356356
return static function ($item) use ($key, $operator, $value) {
357357
$retrieved = self::getDeepData($item, $key);
358358

359-
$strings = array_filter([$retrieved, $value], fn ($value) => is_string($value) || (is_object($value) && method_exists($value, '__toString')));
359+
$strings = array_filter([$retrieved, $value], fn ($value) => \is_string($value) || (\is_object($value) && method_exists($value, '__toString')));
360360

361-
if (count($strings) < 2 && 1 === count(array_filter([$retrieved, $value], 'is_object'))) {
362-
return in_array($operator, ['!=', '<>', '!==']);
361+
if (\count($strings) < 2 && 1 === \count(array_filter([$retrieved, $value], 'is_object'))) {
362+
return \in_array($operator, ['!=', '<>', '!==']);
363363
}
364364

365365
switch ($operator) {

src/Command/IndexCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $o
4242
$indexNames = new Collection();
4343

4444
if ($indexList = $input->getOption('indices')) {
45-
$list = \explode(',', $indexList);
45+
$list = explode(',', $indexList);
4646
$indexNames = (new Collection($list))->transform(function (string $item): string {
4747
// Check if the given index name already contains the prefix
4848
if (!str_contains($item, $this->prefix)) {
@@ -53,16 +53,16 @@ protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $o
5353
});
5454
}
5555

56-
if (0 === count($indexNames) && 0 === count($indices)) {
56+
if (0 === \count($indexNames) && 0 === \count($indices)) {
5757
$output->writeln(
5858
'<comment>No indices specified. Please either specify indices using the cli option or YAML configuration.</comment>'
5959
);
6060

6161
return new Collection();
6262
}
6363

64-
if (count($indexNames) > 0) {
65-
return $indices->reject(fn (array $item) => !in_array($item['name'], $indexNames->all(), true));
64+
if (\count($indexNames) > 0) {
65+
return $indices->reject(fn (array $item) => !\in_array($item['name'], $indexNames->all(), true));
6666
}
6767

6868
return $indices;

src/Command/MeilisearchClearCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4545
$output->writeln($msg);
4646
}
4747

48-
if (0 === count($indexToClear)) {
48+
if (0 === \count($indexToClear)) {
4949
$output->writeln('Cannot clear index. Not found.');
5050
}
5151

src/Command/MeilisearchDeleteCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4545
$output->writeln('Deleted <info>'.$indexName.'</info>');
4646
}
4747

48-
if (0 === count($indexToDelete)) {
48+
if (0 === \count($indexToDelete)) {
4949
$output->writeln('Cannot delete index. Not found.');
5050
}
5151

src/Command/MeilisearchImportCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
102102
$repository = $manager->getRepository($entityClassName);
103103
$classMetadata = $manager->getClassMetadata($entityClassName);
104104
$entityIdentifiers = $classMetadata->getIdentifierFieldNames();
105-
$sortByAttrs = array_combine($entityIdentifiers, array_fill(0, count($entityIdentifiers), 'ASC'));
105+
$sortByAttrs = array_combine($entityIdentifiers, array_fill(0, \count($entityIdentifiers), 'ASC'));
106106

107107
$output->writeln('<info>Importing for index '.$entityClassName.'</info>');
108108

109109
$page = max(0, (int) $input->getOption('skip-batches'));
110110

111111
if ($page > 0) {
112112
$output->writeln(
113-
sprintf(
113+
\sprintf(
114114
'<info>Skipping first <comment>%d</comment> batches (<comment>%d</comment> records)</info>',
115115
$page,
116116
$page * $batchSize,
@@ -127,13 +127,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
127127
);
128128

129129
$responses = $this->formatIndexingResponse($this->searchService->index($manager, $entities), $responseTimeout);
130-
$totalIndexed += count($entities);
130+
$totalIndexed += \count($entities);
131131
foreach ($responses as $indexName => $numberOfRecords) {
132132
$output->writeln(
133-
sprintf(
133+
\sprintf(
134134
'Indexed a batch of <comment>%d / %d</comment> %s entities into %s index (%d indexed since start)',
135135
$numberOfRecords,
136-
count($entities),
136+
\count($entities),
137137
$entityClassName,
138138
'<info>'.$indexName.'</info>',
139139
$totalIndexed,
@@ -142,7 +142,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
142142
}
143143

144144
++$page;
145-
} while (count($entities) >= $batchSize);
145+
} while (\count($entities) >= $batchSize);
146146

147147
$manager->clear();
148148

@@ -165,7 +165,7 @@ private function formatIndexingResponse(array $batch, int $responseTimeout): arr
165165

166166
foreach ($batch as $chunk) {
167167
foreach ($chunk as $indexName => $apiResponse) {
168-
if (!array_key_exists($indexName, $formattedResponse)) {
168+
if (!\array_key_exists($indexName, $formattedResponse)) {
169169
$formattedResponse[$indexName] = 0;
170170
}
171171

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function getConfigTreeBuilder(): TreeBuilder
6767
$stringSettings = ['distinctAttribute', 'proximityPrecision', 'searchCutoffMs'];
6868

6969
foreach ($stringSettings as $setting) {
70-
if (isset($value[$setting]) && !is_array($value[$setting])) {
70+
if (isset($value[$setting]) && !\is_array($value[$setting])) {
7171
$value[$setting] = (array) $value[$setting];
7272
}
7373
}

src/DependencyInjection/MeilisearchExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function load(array $configs, ContainerBuilder $container): void
6969
private function findReferences(array $settings): array
7070
{
7171
foreach ($settings as $key => $value) {
72-
if (is_array($value)) {
72+
if (\is_array($value)) {
7373
$settings[$key] = $this->findReferences($value);
7474
} elseif ('_service' === substr((string) $key, -8) || str_starts_with((string) $value, '@') || 'service' === $key) {
7575
$settings[$key] = new Reference(ltrim($value, '@'));

src/Engine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function count(string $query, string $indexName, array $searchParams): in
143143

144144
private function normalizeId($id)
145145
{
146-
if (is_object($id) && method_exists($id, '__toString')) {
146+
if (\is_object($id) && method_exists($id, '__toString')) {
147147
return (string) $id;
148148
}
149149

src/Exception/InvalidIndiceException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ final class InvalidIndiceException extends \InvalidArgumentException
88
{
99
public function __construct(string $indice, $code = 0, ?\Throwable $previous = null)
1010
{
11-
parent::__construct(sprintf('Meilisearch index for "%s" was not found.', $indice), $code, $previous);
11+
parent::__construct(\sprintf('Meilisearch index for "%s" was not found.', $indice), $code, $previous);
1212
}
1313
}

src/MeilisearchBundle.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
final class MeilisearchBundle extends Bundle
1010
{
11-
public const VERSION = '0.15.2';
11+
public const VERSION = '0.15.3';
1212

13-
public static function qualifiedVersion()
13+
public static function qualifiedVersion(): string
1414
{
15-
return sprintf('Meilisearch Symfony (v%s)', MeilisearchBundle::VERSION);
15+
return \sprintf('Meilisearch Symfony (v%s)', self::VERSION);
1616
}
1717

1818
public function getPath(): string

src/Model/Aggregator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct($entity, array $entityIdentifierValues)
3232
{
3333
$this->entity = $entity;
3434

35-
if (count($entityIdentifierValues) > 1) {
35+
if (\count($entityIdentifierValues) > 1) {
3636
throw new InvalidEntityForAggregator("Aggregators don't support more than one primary key.");
3737
}
3838

@@ -66,7 +66,7 @@ public static function getEntityClassFromObjectID(string $objectId): string
6666
{
6767
$type = explode('::', $objectId)[0];
6868

69-
if (in_array($type, static::getEntities(), true)) {
69+
if (\in_array($type, static::getEntities(), true)) {
7070
return $type;
7171
}
7272

src/SearchableEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function getSearchableArray(): array
6767
'fieldsMapping' => $this->entityMetadata->fieldMappings,
6868
];
6969

70-
if (count($this->normalizationGroups) > 0) {
70+
if (\count($this->normalizationGroups) > 0) {
7171
$context['groups'] = $this->normalizationGroups;
7272
}
7373

0 commit comments

Comments
 (0)