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 _docs_build/build.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
(new Application('Symfony Docs Builder', '1.0'))
->register('build-docs')
->addOption('generate-fjson-files', null, InputOption::VALUE_NONE, 'Use this option to generate docs both in HTML and JSON formats')
->setCode(function (InputInterface $input, OutputInterface $output) {
->setCode(static function (InputInterface $input, OutputInterface $output) {
$io = new SymfonyStyle($input, $output);
$io->text('Building all Symfony Docs...');

Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/EntityRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
private string $inverseClass,
) {
if (!\in_array($type, self::getValidRelationTypes())) {
throw new \Exception(\sprintf('Invalid relation type "%s"', $type));
throw new \Exception(\sprintf('Invalid relation type "%s".', $type));
}

if (self::ONE_TO_MANY === $type) {
Expand Down
6 changes: 3 additions & 3 deletions src/Maker/MakeEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
}
$currentFields[] = $newFieldName;
} else {
throw new \Exception('Invalid value');
throw new \Exception('Invalid value.');
}

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

return $type;
Expand Down
2 changes: 1 addition & 1 deletion src/Maker/MakeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
$entities = $this->entityHelper->getEntitiesForAutocomplete();

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

Expand Down
2 changes: 1 addition & 1 deletion src/Maker/MakeListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
$event = $input->getArgument('event');
if (null === $this->getEventConstant($event) && null === $this->eventRegistry->getEventClassName($event)) {
$eventList = $this->eventRegistry->getAllActiveEvents();
$eventFQCNList = array_filter(array_map($this->eventRegistry->getEventClassName(...), $eventList), fn ($eventFQCN) => \is_string($eventFQCN));
$eventFQCNList = array_filter(array_map($this->eventRegistry->getEventClassName(...), $eventList), static fn ($eventFQCN) => \is_string($eventFQCN));
$eventIdAndFQCNList = array_unique(array_merge($eventList, $eventFQCNList));
$suggestionList = [];

Expand Down
10 changes: 5 additions & 5 deletions src/Maker/MakeStimulusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
\sprintf('- Open <info>%s</info> and add the code you need', $filePath),
'- Use the controller in your templates:',
...array_map(
fn (string $line): string => " $line",
static fn (string $line): string => " $line",
explode("\n", $this->generateUsageExample($controllerName, $targetArgs, $valuesArg, $classesArgs)),
),
'Find the documentation at <fg=yellow>https://symfony.com/bundles/StimulusBundle</>',
Expand All @@ -175,7 +175,7 @@ private function askForNextTarget(ConsoleStyle $io, array $targets, bool $isFirs
$questionText = 'Add another target? Enter the target name (or press <return> to stop adding targets)';
}

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

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

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

$htmlTargets = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/FormTypeRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function render(ClassNameDetails $formClassDetails, array $formFields, ?C
$extraUseClasses = array_merge($extraUseClasses, $fieldTypeOptions['extra_use_classes'] ?? []);
$fieldTypeOptions['options_code'] = str_replace(
$fieldTypeOptions['extra_use_classes'],
array_map(fn ($class) => Str::getShortClassName($class), $fieldTypeOptions['extra_use_classes']),
array_map(static fn ($class) => Str::getShortClassName($class), $fieldTypeOptions['extra_use_classes']),
$fieldTypeOptions['options_code']
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Test/MakerTestEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function prepareDirectory(): void
;

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

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

$inputStream->onEmpty(function () use ($inputStream, &$userInputs) {
$inputStream->onEmpty(static function () use ($inputStream, &$userInputs) {
$nextInput = next($userInputs);
if (false === $nextInput) {
$inputStream->close();
Expand Down
4 changes: 2 additions & 2 deletions src/Test/MakerTestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function modifyYamlFile(string $filename, \Closure $callback)

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

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

// Flex includes a recipe to suffix the dbname w/ "_test" - lets keep
// things simple for these tests and not do that.
$this->modifyYamlFile('config/packages/doctrine.yaml', function (array $config) {
$this->modifyYamlFile('config/packages/doctrine.yaml', static function (array $config) {
if (isset($config['when@test']['doctrine']['dbal']['dbname_suffix'])) {
unset($config['when@test']['doctrine']['dbal']['dbname_suffix']);
}
Expand Down
22 changes: 11 additions & 11 deletions src/Util/ClassSourceManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public function addTrait(string $trait): void
$importedClassName = $this->addUseStatementIfNecessary($trait);

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

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

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

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

if (!$node) {
throw new \Exception('Could not find class node');
throw new \Exception('Could not find class node.');
}

return $node;
}

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

if (!$node) {
throw new \Exception('Could not find namespace node');
throw new \Exception('Could not find namespace node.');
}

return $node;
Expand Down Expand Up @@ -1044,10 +1044,10 @@ private function createSingleLineCommentNode(string $comment, string $context):
switch ($context) {
case self::CONTEXT_OUTSIDE_CLASS:
// just not needed yet
throw new \Exception('not supported');
throw new \Exception('Not supported.');
case self::CONTEXT_CLASS:
// just not needed yet
throw new \Exception('not supported');
throw new \Exception('Not supported.');
case self::CONTEXT_CLASS_METHOD:
return BuilderHelpers::normalizeStmt(new Node\Expr\Variable(\sprintf('__COMMENT__VAR_%d', \count($this->pendingComments) - 1)));
default:
Expand Down Expand Up @@ -1146,16 +1146,16 @@ private function addNodeAfterProperties(Node $newNode): void
$classNode = $this->getClassNode();

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

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

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

// add the new property after this node
Expand Down
6 changes: 3 additions & 3 deletions src/Util/YamlSourceManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ private function guessNextArrayTypeAndAdvance(): string
{
while (true) {
if ($this->isEOF()) {
throw new \LogicException('Could not determine array type');
throw new \LogicException('Could not determine array type.');
}

// get the next char & advance immediately
Expand Down Expand Up @@ -1029,7 +1029,7 @@ private function findPositionOfNextCharacter(array $chars)
$currentPosition = $this->currentPosition;
while (true) {
if ($this->isEOF($currentPosition)) {
throw new \LogicException(\sprintf('Could not find any characters: %s', implode(', ', $chars)));
throw new \LogicException(\sprintf('Could not find any characters: "%s"', implode('", "', $chars)));
}

// get the next char & advance immediately
Expand Down Expand Up @@ -1093,7 +1093,7 @@ private function isHash($value): bool
private function normalizeSequences(array $data): array
{
// https://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential/4254008#4254008
$hasStringKeys = fn (array $array): bool => \count(array_filter(array_keys($array), 'is_string')) > 0;
$hasStringKeys = static fn (array $array): bool => \count(array_filter(array_keys($array), 'is_string')) > 0;

foreach ($data as $key => $val) {
if (!\is_array($val)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/EntityRegeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private function doTestRegeneration(string $sourceDir, Kernel $kernel, string $n
$autoloaderUtil = $this->createMock(AutoloaderUtil::class);
$autoloaderUtil->expects($this->any())
->method('getPathForFutureClass')
->willReturnCallback(function ($className) use ($tmpDir, $targetDirName) {
->willReturnCallback(static function ($className) use ($tmpDir, $targetDirName) {
$shortClassName = str_replace('Symfony\Bundle\MakerBundle\Tests\tmp\\'.$targetDirName.'\src\\', '', $className);

// strip the App\, change \ to / and add .php
Expand Down
2 changes: 1 addition & 1 deletion tests/FileManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function testWithMakerFileLinkFormatter()

$fileLinkFormatter
->method('format')
->willReturnCallback(function ($path, $line) {
->willReturnCallback(static function ($path, $line) {
return \sprintf('subl://open?url=file://%s&line=%d', $path, $line);
});

Expand Down
8 changes: 4 additions & 4 deletions tests/Maker/MakeAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getTestDetails(): \Generator

yield 'auth_empty_multiple_firewalls' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
$runner->modifyYamlFile('config/packages/security.yaml', function (array $config) {
$runner->modifyYamlFile('config/packages/security.yaml', static function (array $config) {
$config['security']['firewalls']['second']['lazy'] = true;

return $config;
Expand Down Expand Up @@ -80,7 +80,7 @@ public function getTestDetails(): \Generator
'src/Security/BlankAuthenticator.php'
);

$runner->modifyYamlFile('config/packages/security.yaml', function (array $config) {
$runner->modifyYamlFile('config/packages/security.yaml', static function (array $config) {
$config['security']['firewalls']['main']['custom_authenticator'] = 'App\Security\BlankAuthenticator';

return $config;
Expand Down Expand Up @@ -112,7 +112,7 @@ public function getTestDetails(): \Generator
'src/Security/BlankAuthenticator.php'
);

$runner->modifyYamlFile('config/packages/security.yaml', function (array $config) {
$runner->modifyYamlFile('config/packages/security.yaml', static function (array $config) {
$config['security']['firewalls']['second'] = ['lazy' => true, 'custom_authenticator' => 'App\Security\BlankAuthenticator'];

return $config;
Expand Down Expand Up @@ -358,7 +358,7 @@ private function runLoginTest(MakerTestRunner $runner, string $userIdentifier, b
);

// plaintext password: needed for entities, simplifies overall
$runner->modifyYamlFile('config/packages/security.yaml', function (array $config) {
$runner->modifyYamlFile('config/packages/security.yaml', static function (array $config) {
if (isset($config['when@test']['security']['password_hashers'])) {
$config['when@test']['security']['password_hashers'] = [PasswordAuthenticatedUserInterface::class => 'plaintext'];

Expand Down
2 changes: 1 addition & 1 deletion tests/Maker/MakeCrudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function getTestDetails(): \Generator
);

// Symfony 6.2 sets the path and namespace for router resources
$runner->modifyYamlFile('config/routes.yaml', function (array $config) {
$runner->modifyYamlFile('config/routes.yaml', static function (array $config) {
if (!isset($config['controllers']['resource']['namespace'])) {
return $config;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Maker/MakeEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function getMakerClass(): string
private function createMakeEntityTest(bool $withDatabase = true): MakerTestDetails
{
return $this->createMakerTest()
->preRun(function (MakerTestRunner $runner) use ($withDatabase) {
->preRun(static function (MakerTestRunner $runner) use ($withDatabase) {
if ($withDatabase) {
$runner->configureDatabase();
}
Expand All @@ -45,7 +45,7 @@ private function createMakeEntityTestForMercure(): MakerTestDetails
}

return $this->createMakeEntityTest()
->preRun(function (MakerTestRunner $runner) {
->preRun(static function (MakerTestRunner $runner) {
// installed manually later so that the compatibility check can run first
$runner->runProcess('composer require symfony/ux-turbo');
})
Expand Down Expand Up @@ -679,7 +679,7 @@ public function getTestDetails(): \Generator
];

yield 'it_generates_entity_with_turbo_without_mercure' => [$this->createMakeEntityTest()
->preRun(function (MakerTestRunner $runner) {
->preRun(static function (MakerTestRunner $runner) {
$runner->runProcess('composer require symfony/ux-turbo');
})
->addExtraDependencies('twig')
Expand Down
2 changes: 1 addition & 1 deletion tests/Maker/MakeFunctionalTestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getTestDetails(): \Generator
{
yield 'it_generates_test_with_panther' => [$this->getPantherTest()
->addExtraDependencies('panther')
->run(function (MakerTestRunner $runner) {
->run(static function (MakerTestRunner $runner) {
$runner->copy(
'make-functional/MainController.php',
'src/Controller/MainController.php'
Expand Down
Loading
Loading