Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6089bc

Browse files
committed
Leverage arrow function syntax for closure
1 parent e9870a4 commit e6089bc

File tree

411 files changed

+1091
-2328
lines changed

Some content is hidden

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

411 files changed

+1091
-2328
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,12 @@ public function getEntitiesByIds(string $identifier, array $values): array
7474

7575
// Filter out non-integer values (e.g. ""). If we don't, some
7676
// databases such as PostgreSQL fail.
77-
$values = array_values(array_filter($values, function ($v) {
78-
return (string) $v === (string) (int) $v || ctype_digit($v);
79-
}));
77+
$values = array_values(array_filter($values, fn ($v) => (string) $v === (string) (int) $v || ctype_digit($v)));
8078
} elseif (\in_array($type, ['ulid', 'uuid', 'guid'])) {
8179
$parameterType = Connection::PARAM_STR_ARRAY;
8280

8381
// Like above, but we just filter out empty strings.
84-
$values = array_values(array_filter($values, function ($v) {
85-
return '' !== (string) $v;
86-
}));
82+
$values = array_values(array_filter($values, fn ($v) => '' !== (string) $v));
8783

8884
// Convert values into right type
8985
if (Type::hasType($type)) {

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,13 @@ public function configureOptions(OptionsResolver $resolver)
193193

194194
// Set the "id_reader" option via the normalizer. This option is not
195195
// supposed to be set by the user.
196-
$idReaderNormalizer = function (Options $options) {
197-
// The ID reader is a utility that is needed to read the object IDs
198-
// when generating the field values. The callback generating the
199-
// field values has no access to the object manager or the class
200-
// of the field, so we store that information in the reader.
201-
// The reader is cached so that two choice lists for the same class
202-
// (and hence with the same reader) can successfully be cached.
203-
return $this->getCachedIdReader($options['em'], $options['class']);
204-
};
196+
// The ID reader is a utility that is needed to read the object IDs
197+
// when generating the field values. The callback generating the
198+
// field values has no access to the object manager or the class
199+
// of the field, so we store that information in the reader.
200+
// The reader is cached so that two choice lists for the same class
201+
// (and hence with the same reader) can successfully be cached.
202+
$idReaderNormalizer = fn (Options $options) => $this->getCachedIdReader($options['em'], $options['class']);
205203

206204
$resolver->setDefaults([
207205
'em' => null,

src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ public function getProperties(string $class, array $context = []): ?array
4747
$properties = array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());
4848

4949
if ($metadata instanceof ClassMetadataInfo && class_exists(Embedded::class) && $metadata->embeddedClasses) {
50-
$properties = array_filter($properties, function ($property) {
51-
return !str_contains($property, '.');
52-
});
50+
$properties = array_filter($properties, fn ($property) => !str_contains($property, '.'));
5351

5452
$properties = array_merge($properties, array_keys($metadata->embeddedClasses));
5553
}

src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ protected function setUp(): void
4747

4848
$this->extension->expects($this->any())
4949
->method('getObjectManagerElementName')
50-
->willReturnCallback(function ($name) {
51-
return 'doctrine.orm.'.$name;
52-
});
50+
->willReturnCallback(fn ($name) => 'doctrine.orm.'.$name);
5351

5452
$this->extension
5553
->method('getMappingObjectDefaultName')

src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public function testLoadValuesForChoicesDoesNotLoadIfSingleIntIdAndValueGiven()
222222
);
223223

224224
$choices = [$this->obj1, $this->obj2, $this->obj3];
225-
$value = function (\stdClass $object) { return $object->name; };
225+
$value = fn (\stdClass $object) => $object->name;
226226

227227
$this->repository->expects($this->never())
228228
->method('findAll')
@@ -367,7 +367,7 @@ public function testLoadChoicesForValuesLoadsAllIfSingleIntIdAndValueGiven()
367367
);
368368

369369
$choices = [$this->obj1, $this->obj2, $this->obj3];
370-
$value = function (\stdClass $object) { return $object->name; };
370+
$value = fn (\stdClass $object) => $object->name;
371371

372372
$this->repository->expects($this->once())
373373
->method('findAll')

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ public function testConfigureQueryBuilderWithClosureReturningNonQueryBuilder()
236236
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
237237
'em' => 'default',
238238
'class' => self::SINGLE_IDENT_CLASS,
239-
'query_builder' => function () {
240-
return new \stdClass();
241-
},
239+
'query_builder' => fn () => new \stdClass(),
242240
]);
243241

244242
$field->submit('2');
@@ -1078,10 +1076,8 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderAsClosureSingle
10781076
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
10791077
'em' => 'default',
10801078
'class' => self::SINGLE_IDENT_CLASS,
1081-
'query_builder' => function (EntityRepository $repository) {
1082-
return $repository->createQueryBuilder('e')
1083-
->where('e.id IN (1, 2)');
1084-
},
1079+
'query_builder' => fn (EntityRepository $repository) => $repository->createQueryBuilder('e')
1080+
->where('e.id IN (1, 2)'),
10851081
'choice_label' => 'name',
10861082
]);
10871083

@@ -1102,10 +1098,8 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderAsClosureCompos
11021098
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
11031099
'em' => 'default',
11041100
'class' => self::COMPOSITE_IDENT_CLASS,
1105-
'query_builder' => function (EntityRepository $repository) {
1106-
return $repository->createQueryBuilder('e')
1107-
->where('e.id1 IN (10, 50)');
1108-
},
1101+
'query_builder' => fn (EntityRepository $repository) => $repository->createQueryBuilder('e')
1102+
->where('e.id1 IN (10, 50)'),
11091103
'choice_label' => 'name',
11101104
]);
11111105

@@ -1220,17 +1214,13 @@ public function testLoaderCaching()
12201214
$formBuilder->add('property2', static::TESTED_TYPE, [
12211215
'em' => 'default',
12221216
'class' => self::SINGLE_IDENT_CLASS,
1223-
'query_builder' => function (EntityRepository $repo) {
1224-
return $repo->createQueryBuilder('e')->where('e.id IN (1, 2)');
1225-
},
1217+
'query_builder' => fn (EntityRepository $repo) => $repo->createQueryBuilder('e')->where('e.id IN (1, 2)'),
12261218
]);
12271219

12281220
$formBuilder->add('property3', static::TESTED_TYPE, [
12291221
'em' => 'default',
12301222
'class' => self::SINGLE_IDENT_CLASS,
1231-
'query_builder' => function (EntityRepository $repo) {
1232-
return $repo->createQueryBuilder('e')->where('e.id IN (1, 2)');
1233-
},
1223+
'query_builder' => fn (EntityRepository $repo) => $repo->createQueryBuilder('e')->where('e.id IN (1, 2)'),
12341224
]);
12351225

12361226
$form = $formBuilder->getForm();
@@ -1280,17 +1270,13 @@ public function testLoaderCachingWithParameters()
12801270
$formBuilder->add('property2', static::TESTED_TYPE, [
12811271
'em' => 'default',
12821272
'class' => self::SINGLE_IDENT_CLASS,
1283-
'query_builder' => function (EntityRepository $repo) {
1284-
return $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1);
1285-
},
1273+
'query_builder' => fn (EntityRepository $repo) => $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1),
12861274
]);
12871275

12881276
$formBuilder->add('property3', static::TESTED_TYPE, [
12891277
'em' => 'default',
12901278
'class' => self::SINGLE_IDENT_CLASS,
1291-
'query_builder' => function (EntityRepository $repo) {
1292-
return $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1);
1293-
},
1279+
'query_builder' => fn (EntityRepository $repo) => $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1),
12941280
]);
12951281

12961282
$form = $formBuilder->getForm();
@@ -1791,9 +1777,7 @@ public function testWithSameLoaderAndDifferentChoiceValueCallbacks()
17911777
->add('entity_two', self::TESTED_TYPE, [
17921778
'em' => 'default',
17931779
'class' => self::SINGLE_IDENT_CLASS,
1794-
'choice_value' => function ($choice) {
1795-
return $choice ? $choice->name : '';
1796-
},
1780+
'choice_value' => fn ($choice) => $choice ? $choice->name : '',
17971781
])
17981782
->createView()
17991783
;

src/Symfony/Bridge/Monolog/Tests/Handler/MailerHandlerTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ public function testHandle()
3939
$this->mailer
4040
->expects($this->once())
4141
->method('send')
42-
->with($this->callback(function (Email $email) {
43-
return 'Alert: WARNING message' === $email->getSubject() && null === $email->getHtmlBody();
44-
}))
42+
->with($this->callback(fn (Email $email) => 'Alert: WARNING message' === $email->getSubject() && null === $email->getHtmlBody()))
4543
;
4644
$handler->handle($this->getRecord(Logger::WARNING, 'message'));
4745
}
@@ -53,9 +51,7 @@ public function testHandleBatch()
5351
$this->mailer
5452
->expects($this->once())
5553
->method('send')
56-
->with($this->callback(function (Email $email) {
57-
return 'Alert: ERROR error' === $email->getSubject() && null === $email->getHtmlBody();
58-
}))
54+
->with($this->callback(fn (Email $email) => 'Alert: ERROR error' === $email->getSubject() && null === $email->getHtmlBody()))
5955
;
6056
$handler->handleBatch($this->getMultipleRecords());
6157
}
@@ -86,9 +82,7 @@ public function testHtmlContent()
8682
$this->mailer
8783
->expects($this->once())
8884
->method('send')
89-
->with($this->callback(function (Email $email) {
90-
return 'Alert: WARNING message' === $email->getSubject() && null === $email->getTextBody();
91-
}))
85+
->with($this->callback(fn (Email $email) => 'Alert: WARNING message' === $email->getSubject() && null === $email->getTextBody()))
9286
;
9387
$handler->handle($this->getRecord(Logger::WARNING, 'message'));
9488
}

src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Instantiator/RuntimeInstantiatorTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ public function testInstantiateProxy()
4242
$instance = new \stdClass();
4343
$container = $this->createMock(ContainerInterface::class);
4444
$definition = new Definition('stdClass');
45-
$instantiator = function () use ($instance) {
46-
return $instance;
47-
};
45+
$instantiator = fn () => $instance;
4846

4947
/* @var $proxy LazyLoadingInterface|ValueHolderInterface */
5048
$proxy = $this->instantiator->instantiateProxy($container, $definition, 'foo', $instantiator);

src/Symfony/Bridge/Twig/Command/DebugCommand.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ private function displayPathsText(SymfonyStyle $io, string $name)
162162
[$namespace, $shortname] = $this->parseTemplateName($name);
163163
$alternatives = $this->findAlternatives($shortname, $shortnames);
164164
if (FilesystemLoader::MAIN_NAMESPACE !== $namespace) {
165-
$alternatives = array_map(function ($shortname) use ($namespace) {
166-
return '@'.$namespace.'/'.$shortname;
167-
}, $alternatives);
165+
$alternatives = array_map(fn ($shortname) => '@'.$namespace.'/'.$shortname, $alternatives);
168166
}
169167
}
170168

@@ -543,7 +541,7 @@ private function findAlternatives(string $name, array $collection): array
543541
}
544542

545543
$threshold = 1e3;
546-
$alternatives = array_filter($alternatives, function ($lev) use ($threshold) { return $lev < 2 * $threshold; });
544+
$alternatives = array_filter($alternatives, fn ($lev) => $lev < 2 * $threshold);
547545
ksort($alternatives, \SORT_NATURAL | \SORT_FLAG_CASE);
548546

549547
return array_keys($alternatives);

src/Symfony/Bridge/Twig/Extension/CodeExtension.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ public function fileExcerpt(string $file, int $line, int $srcContext = 3): ?stri
120120
// remove main code/span tags
121121
$code = preg_replace('#^<code.*?>\s*<span.*?>(.*)</span>\s*</code>#s', '\\1', $code);
122122
// split multiline spans
123-
$code = preg_replace_callback('#<span ([^>]++)>((?:[^<]*+<br \/>)++[^<]*+)</span>#', function ($m) {
124-
return "<span $m[1]>".str_replace('<br />', "</span><br /><span $m[1]>", $m[2]).'</span>';
125-
}, $code);
123+
$code = preg_replace_callback('#<span ([^>]++)>((?:[^<]*+<br \/>)++[^<]*+)</span>#', fn ($m) => "<span $m[1]>".str_replace('<br />', "</span><br /><span $m[1]>", $m[2]).'</span>', $code);
126124
$content = explode('<br />', $code);
127125

128126
$lines = [];
@@ -188,9 +186,7 @@ public function getFileRelative(string $file): ?string
188186

189187
public function formatFileFromText(string $text): string
190188
{
191-
return preg_replace_callback('/in ("|&quot;)?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', function ($match) {
192-
return 'in '.$this->formatFile($match[2], $match[3]);
193-
}, $text);
189+
return preg_replace_callback('/in ("|&quot;)?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', fn ($match) => 'in '.$this->formatFile($match[2], $match[3]), $text);
194190
}
195191

196192
/**

0 commit comments

Comments
 (0)