Skip to content

Commit 686d8ac

Browse files
committed
Fix CS: Use static anonymous functions
1 parent 4994519 commit 686d8ac

36 files changed

Lines changed: 87 additions & 87 deletions

_docs_build/build.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
(new Application('Symfony Docs Builder', '1.0'))
2424
->register('build-docs')
2525
->addOption('generate-fjson-files', null, InputOption::VALUE_NONE, 'Use this option to generate docs both in HTML and JSON formats')
26-
->setCode(function (InputInterface $input, OutputInterface $output) {
26+
->setCode(static function (InputInterface $input, OutputInterface $output) {
2727
$io = new SymfonyStyle($input, $output);
2828
$io->text('Building all Symfony Docs...');
2929

src/Doctrine/EntityRelation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(
3434
private string $inverseClass,
3535
) {
3636
if (!\in_array($type, self::getValidRelationTypes())) {
37-
throw new \Exception(\sprintf('Invalid relation type "%s"', $type));
37+
throw new \Exception(\sprintf('Invalid relation type "%s".', $type));
3838
}
3939

4040
if (self::ONE_TO_MANY === $type) {

src/Maker/MakeEntity.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
301301
}
302302
$currentFields[] = $newFieldName;
303303
} else {
304-
throw new \Exception('Invalid value');
304+
throw new \Exception('Invalid value.');
305305
}
306306

307307
foreach ($fileManagerOperations as $path => $manipulatorOrMessage) {
@@ -825,9 +825,9 @@ private function askRelationType(ConsoleStyle $io, string $entityClass, string $
825825
implode(', ', EntityRelation::getValidRelationTypes())
826826
));
827827
$question->setAutocompleterValues(EntityRelation::getValidRelationTypes());
828-
$question->setValidator(function ($type) {
828+
$question->setValidator(static function ($type) {
829829
if (!\in_array($type, EntityRelation::getValidRelationTypes())) {
830-
throw new \InvalidArgumentException(\sprintf('Invalid type: use one of: %s', implode(', ', EntityRelation::getValidRelationTypes())));
830+
throw new \InvalidArgumentException(\sprintf('Invalid type, use one of: "%s"', implode('", "', EntityRelation::getValidRelationTypes())));
831831
}
832832

833833
return $type;

src/Maker/MakeForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
6767
$entities = $this->entityHelper->getEntitiesForAutocomplete();
6868

6969
$question = new Question($argument->getDescription());
70-
$question->setValidator(fn ($answer) => Validator::existsOrNull($answer, $entities));
70+
$question->setValidator(static fn ($answer) => Validator::existsOrNull($answer, $entities));
7171
$question->setAutocompleterValues($entities);
7272
$question->setMaxAttempts(3);
7373

src/Maker/MakeListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
107107
$event = $input->getArgument('event');
108108
if (null === $this->getEventConstant($event) && null === $this->eventRegistry->getEventClassName($event)) {
109109
$eventList = $this->eventRegistry->getAllActiveEvents();
110-
$eventFQCNList = array_filter(array_map($this->eventRegistry->getEventClassName(...), $eventList), fn ($eventFQCN) => \is_string($eventFQCN));
110+
$eventFQCNList = array_filter(array_map($this->eventRegistry->getEventClassName(...), $eventList), static fn ($eventFQCN) => \is_string($eventFQCN));
111111
$eventIdAndFQCNList = array_unique(array_merge($eventList, $eventFQCNList));
112112
$suggestionList = [];
113113

src/Maker/MakeStimulusController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
159159
\sprintf('- Open <info>%s</info> and add the code you need', $filePath),
160160
'- Use the controller in your templates:',
161161
...array_map(
162-
fn (string $line): string => " $line",
162+
static fn (string $line): string => " $line",
163163
explode("\n", $this->generateUsageExample($controllerName, $targetArgs, $valuesArg, $classesArgs)),
164164
),
165165
'Find the documentation at <fg=yellow>https://symfony.com/bundles/StimulusBundle</>',
@@ -175,7 +175,7 @@ private function askForNextTarget(ConsoleStyle $io, array $targets, bool $isFirs
175175
$questionText = 'Add another target? Enter the target name (or press <return> to stop adding targets)';
176176
}
177177

178-
$targetName = $io->ask($questionText, validator: function (?string $name) use ($targets) {
178+
$targetName = $io->ask($questionText, validator: static function (?string $name) use ($targets) {
179179
if (\in_array($name, $targets)) {
180180
throw new \InvalidArgumentException(\sprintf('The "%s" target already exists.', $name));
181181
}
@@ -199,7 +199,7 @@ private function askForNextValue(ConsoleStyle $io, array $values, bool $isFirstV
199199
$questionText = 'Add another value? Enter the value name (or press <return> to stop adding values)';
200200
}
201201

202-
$valueName = $io->ask($questionText, null, function ($name) use ($values) {
202+
$valueName = $io->ask($questionText, null, static function ($name) use ($values) {
203203
if (\array_key_exists($name, $values)) {
204204
throw new \InvalidArgumentException(\sprintf('The "%s" value already exists.', $name));
205205
}
@@ -258,7 +258,7 @@ private function askForNextClass(ConsoleStyle $io, array $classes, bool $isFirst
258258
$questionText = 'Add another class? Enter the class name (or press <return> to stop adding classes)';
259259
}
260260

261-
$className = $io->ask($questionText, validator: function (?string $name) use ($classes) {
261+
$className = $io->ask($questionText, validator: static function (?string $name) use ($classes) {
262262
if (str_contains($name, ' ')) {
263263
throw new \InvalidArgumentException('Class name cannot contain spaces.');
264264
}
@@ -298,7 +298,7 @@ private function getValuesTypes(): array
298298
*/
299299
private function generateUsageExample(string $name, array $targets, array $values, array $classes): string
300300
{
301-
$slugify = fn (string $name) => str_replace('_', '-', Str::asSnakeCase($name));
301+
$slugify = static fn (string $name) => str_replace('_', '-', Str::asSnakeCase($name));
302302
$controller = $slugify($name);
303303

304304
$htmlTargets = [];

src/Renderer/FormTypeRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function render(ClassNameDetails $formClassDetails, array $formFields, ?C
4343
$extraUseClasses = array_merge($extraUseClasses, $fieldTypeOptions['extra_use_classes'] ?? []);
4444
$fieldTypeOptions['options_code'] = str_replace(
4545
$fieldTypeOptions['extra_use_classes'],
46-
array_map(fn ($class) => Str::getShortClassName($class), $fieldTypeOptions['extra_use_classes']),
46+
array_map(static fn ($class) => Str::getShortClassName($class), $fieldTypeOptions['extra_use_classes']),
4747
$fieldTypeOptions['options_code']
4848
);
4949
}

src/Test/MakerTestEnvironment.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function prepareDirectory(): void
168168
;
169169

170170
if (!$composerProcess->isSuccessful()) {
171-
throw new \Exception(\sprintf('Error running command: composer require %s -v. Output: "%s". Error: "%s"', implode(' ', $dependencies), $composerProcess->getOutput(), $composerProcess->getErrorOutput()));
171+
throw new \Exception(\sprintf('Error running command: composer require "%s" -v. Output: "%s". Error: "%s"', implode(' ', $dependencies), $composerProcess->getOutput(), $composerProcess->getErrorOutput()));
172172
}
173173
}
174174

@@ -345,7 +345,7 @@ public function createInteractiveCommandProcess(string $commandName, array $user
345345
// start the command with some input
346346
$inputStream->write(current($userInputs)."\n");
347347

348-
$inputStream->onEmpty(function () use ($inputStream, &$userInputs) {
348+
$inputStream->onEmpty(static function () use ($inputStream, &$userInputs) {
349349
$nextInput = next($userInputs);
350350
if (false === $nextInput) {
351351
$inputStream->close();

src/Test/MakerTestRunner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function modifyYamlFile(string $filename, \Closure $callback)
114114

115115
$newData = $callback($manipulator->getData());
116116
if (!\is_array($newData)) {
117-
throw new \Exception('The modifyYamlFile() callback must return the final array of data');
117+
throw new \Exception('The modifyYamlFile() callback must return the final array of data.');
118118
}
119119
$manipulator->setData($newData);
120120

@@ -172,7 +172,7 @@ public function configureDatabase(bool $createSchema = true): void
172172

173173
// Flex includes a recipe to suffix the dbname w/ "_test" - lets keep
174174
// things simple for these tests and not do that.
175-
$this->modifyYamlFile('config/packages/doctrine.yaml', function (array $config) {
175+
$this->modifyYamlFile('config/packages/doctrine.yaml', static function (array $config) {
176176
if (isset($config['when@test']['doctrine']['dbal']['dbname_suffix'])) {
177177
unset($config['when@test']['doctrine']['dbal']['dbname_suffix']);
178178
}

src/Util/ClassSourceManipulator.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public function addTrait(string $trait): void
240240
$importedClassName = $this->addUseStatementIfNecessary($trait);
241241

242242
/** @var Node\Stmt\TraitUse[] $traitNodes */
243-
$traitNodes = $this->findAllNodes(fn ($node) => $node instanceof Node\Stmt\TraitUse);
243+
$traitNodes = $this->findAllNodes(static fn ($node) => $node instanceof Node\Stmt\TraitUse);
244244

245245
foreach ($traitNodes as $node) {
246246
if ($node->traits[0]->toString() === $importedClassName) {
@@ -433,7 +433,7 @@ private function addCustomGetter(string $propertyName, string $methodName, $retu
433433
break;
434434
default:
435435
// implement other cases if/when the library needs them
436-
throw new \Exception('Not implemented');
436+
throw new \Exception('Not implemented.');
437437
}
438438
}
439439

@@ -964,21 +964,21 @@ private function setSourceCode(string $sourceCode): void
964964

965965
private function getClassNode(): Node\Stmt\Class_
966966
{
967-
$node = $this->findFirstNode(fn ($node) => $node instanceof Node\Stmt\Class_);
967+
$node = $this->findFirstNode(static fn ($node) => $node instanceof Node\Stmt\Class_);
968968

969969
if (!$node) {
970-
throw new \Exception('Could not find class node');
970+
throw new \Exception('Could not find class node.');
971971
}
972972

973973
return $node;
974974
}
975975

976976
private function getNamespaceNode(): Node\Stmt\Namespace_
977977
{
978-
$node = $this->findFirstNode(fn ($node) => $node instanceof Node\Stmt\Namespace_);
978+
$node = $this->findFirstNode(static fn ($node) => $node instanceof Node\Stmt\Namespace_);
979979

980980
if (!$node) {
981-
throw new \Exception('Could not find namespace node');
981+
throw new \Exception('Could not find namespace node.');
982982
}
983983

984984
return $node;
@@ -1044,10 +1044,10 @@ private function createSingleLineCommentNode(string $comment, string $context):
10441044
switch ($context) {
10451045
case self::CONTEXT_OUTSIDE_CLASS:
10461046
// just not needed yet
1047-
throw new \Exception('not supported');
1047+
throw new \Exception('Not supported.');
10481048
case self::CONTEXT_CLASS:
10491049
// just not needed yet
1050-
throw new \Exception('not supported');
1050+
throw new \Exception('Not supported.');
10511051
case self::CONTEXT_CLASS_METHOD:
10521052
return BuilderHelpers::normalizeStmt(new Node\Expr\Variable(\sprintf('__COMMENT__VAR_%d', \count($this->pendingComments) - 1)));
10531053
default:
@@ -1146,16 +1146,16 @@ private function addNodeAfterProperties(Node $newNode): void
11461146
$classNode = $this->getClassNode();
11471147

11481148
// try to add after last property
1149-
$targetNode = $this->findLastNode(fn ($node) => $node instanceof Node\Stmt\Property, [$classNode]);
1149+
$targetNode = $this->findLastNode(static fn ($node) => $node instanceof Node\Stmt\Property, [$classNode]);
11501150

11511151
// otherwise, try to add after the last constant
11521152
if (!$targetNode) {
1153-
$targetNode = $this->findLastNode(fn ($node) => $node instanceof Node\Stmt\ClassConst, [$classNode]);
1153+
$targetNode = $this->findLastNode(static fn ($node) => $node instanceof Node\Stmt\ClassConst, [$classNode]);
11541154
}
11551155

11561156
// otherwise, try to add after the last trait
11571157
if (!$targetNode) {
1158-
$targetNode = $this->findLastNode(fn ($node) => $node instanceof Node\Stmt\TraitUse, [$classNode]);
1158+
$targetNode = $this->findLastNode(static fn ($node) => $node instanceof Node\Stmt\TraitUse, [$classNode]);
11591159
}
11601160

11611161
// add the new property after this node

0 commit comments

Comments
 (0)