diff --git a/src/Command/MakerCommand.php b/src/Command/MakerCommand.php index 320bfde7f..4188d2188 100644 --- a/src/Command/MakerCommand.php +++ b/src/Command/MakerCommand.php @@ -86,7 +86,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi continue; } - $value = $this->io->ask($argument->getDescription(), $argument->getDefault(), [Validator::class, 'notBlank']); + $value = $this->io->ask($argument->getDescription(), $argument->getDefault(), Validator::notBlank(...)); $input->setArgument($argument->getName(), $value); } diff --git a/src/Docker/DockerDatabaseServices.php b/src/Docker/DockerDatabaseServices.php index e0548de31..16e78139e 100644 --- a/src/Docker/DockerDatabaseServices.php +++ b/src/Docker/DockerDatabaseServices.php @@ -99,7 +99,7 @@ public static function getMissingExtensionName(string $name): ?string /** * @throws RuntimeCommandException */ - private static function throwInvalidDatabase(string $name): void + private static function throwInvalidDatabase(string $name): never { throw new RuntimeCommandException(sprintf('%s is not a valid / supported docker database type.', $name)); } diff --git a/src/Doctrine/EntityRegenerator.php b/src/Doctrine/EntityRegenerator.php index df0473a59..9a3051fd7 100644 --- a/src/Doctrine/EntityRegenerator.php +++ b/src/Doctrine/EntityRegenerator.php @@ -116,26 +116,13 @@ public function regenerateEntities(string $classOrNamespace): void continue; } - switch ($mapping['type']) { - case ClassMetadata::MANY_TO_ONE: - $manipulator->addManyToOneRelation(RelationManyToOne::createFromObject($mapping)); - - break; - case ClassMetadata::ONE_TO_MANY: - $manipulator->addOneToManyRelation(RelationOneToMany::createFromObject($mapping)); - - break; - case ClassMetadata::MANY_TO_MANY: - $manipulator->addManyToManyRelation(RelationManyToMany::createFromObject($mapping)); - - break; - case ClassMetadata::ONE_TO_ONE: - $manipulator->addOneToOneRelation(RelationOneToOne::createFromObject($mapping)); - - break; - default: - throw new \Exception('Unknown association type.'); - } + match ($mapping['type']) { + ClassMetadata::MANY_TO_ONE => $manipulator->addManyToOneRelation(RelationManyToOne::createFromObject($mapping)), + ClassMetadata::ONE_TO_MANY => $manipulator->addOneToManyRelation(RelationOneToMany::createFromObject($mapping)), + ClassMetadata::MANY_TO_MANY => $manipulator->addManyToManyRelation(RelationManyToMany::createFromObject($mapping)), + ClassMetadata::ONE_TO_ONE => $manipulator->addOneToOneRelation(RelationOneToOne::createFromObject($mapping)), + default => throw new \Exception('Unknown association type.'), + }; } } diff --git a/src/Generator.php b/src/Generator.php index 9a909bfcd..f65726da6 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -25,14 +25,13 @@ class Generator { private GeneratorTwigHelper $twigHelper; private array $pendingOperations = []; - private ?TemplateComponentGenerator $templateComponentGenerator; private array $generatedFiles = []; public function __construct( private FileManager $fileManager, private string $namespacePrefix, ?PhpCompatUtil $phpCompatUtil = null, - ?TemplateComponentGenerator $templateComponentGenerator = null, + private ?TemplateComponentGenerator $templateComponentGenerator = null, ) { $this->twigHelper = new GeneratorTwigHelper($fileManager); $this->namespacePrefix = trim($namespacePrefix, '\\'); @@ -40,8 +39,6 @@ public function __construct( if (null !== $phpCompatUtil) { trigger_deprecation('symfony/maker-bundle', 'v1.44.0', 'Initializing Generator while providing an instance of PhpCompatUtil is deprecated.'); } - - $this->templateComponentGenerator = $templateComponentGenerator; } /** @@ -152,7 +149,7 @@ public function createClassNameDetails(string $name, string $namespacePrefix, st try { Validator::classDoesNotExist($className); $className = rtrim($fullNamespacePrefix, '\\').'\\'.$className; - } catch (RuntimeCommandException $e) { + } catch (RuntimeCommandException) { } } diff --git a/src/GeneratorTwigHelper.php b/src/GeneratorTwigHelper.php index c1c42af6d..60957b2e2 100644 --- a/src/GeneratorTwigHelper.php +++ b/src/GeneratorTwigHelper.php @@ -23,41 +23,20 @@ public function __construct( public function getEntityFieldPrintCode($entity, $field): string { - $twigField = preg_replace_callback('/(?!^)_([a-z0-9])/', static function ($s) { - return strtoupper($s[1]); - }, $field['fieldName']); + $twigField = preg_replace_callback('/(?!^)_([a-z0-9])/', static fn ($s) => strtoupper($s[1]), $field['fieldName']); $printCode = $entity.'.'.str_replace('_', '', $twigField); - switch ($field['type']) { - case 'datetimetz_immutable': - case 'datetimetz': - $printCode .= ' ? '.$printCode.'|date(\'Y-m-d H:i:s T\') : \'\''; - break; - case 'datetime_immutable': - case 'datetime': - $printCode .= ' ? '.$printCode.'|date(\'Y-m-d H:i:s\') : \'\''; - break; - case 'dateinterval': - $printCode .= ' ? '.$printCode.'.format(\'%y year(s), %m month(s), %d day(s)\') : \'\''; - break; - case 'date_immutable': - case 'date': - $printCode .= ' ? '.$printCode.'|date(\'Y-m-d\') : \'\''; - break; - case 'time_immutable': - case 'time': - $printCode .= ' ? '.$printCode.'|date(\'H:i:s\') : \'\''; - break; - case 'json': - $printCode .= ' ? '.$printCode.'|json_encode : \'\''; - break; - case 'array': - $printCode .= ' ? '.$printCode.'|join(\', \') : \'\''; - break; - case 'boolean': - $printCode .= ' ? \'Yes\' : \'No\''; - break; - } + match ($field['type']) { + 'datetimetz_immutable', 'datetimetz' => $printCode .= ' ? '.$printCode.'|date(\'Y-m-d H:i:s T\') : \'\'', + 'datetime_immutable', 'datetime' => $printCode .= ' ? '.$printCode.'|date(\'Y-m-d H:i:s\') : \'\'', + 'dateinterval' => $printCode .= ' ? '.$printCode.'.format(\'%y year(s), %m month(s), %d day(s)\') : \'\'', + 'date_immutable', 'date' => $printCode .= ' ? '.$printCode.'|date(\'Y-m-d\') : \'\'', + 'time_immutable', 'time' => $printCode .= ' ? '.$printCode.'|date(\'H:i:s\') : \'\'', + 'json' => $printCode .= ' ? '.$printCode.'|json_encode : \'\'', + 'array' => $printCode .= ' ? '.$printCode.'|join(\', \') : \'\'', + 'boolean' => $printCode .= ' ? \'Yes\' : \'No\'', + default => $printCode, + }; return $printCode; } diff --git a/src/Maker/MakeAuthenticator.php b/src/Maker/MakeAuthenticator.php index 8a8708149..8d567c1db 100644 --- a/src/Maker/MakeAuthenticator.php +++ b/src/Maker/MakeAuthenticator.php @@ -157,7 +157,7 @@ function ($answer) { $io->ask( 'Choose a name for the controller class (e.g. SecurityController)', 'SecurityController', - [Validator::class, 'validateClassName'] + Validator::validateClassName(...) ) ); diff --git a/src/Maker/MakeDockerDatabase.php b/src/Maker/MakeDockerDatabase.php index 91d44c562..7dab9ef20 100644 --- a/src/Maker/MakeDockerDatabase.php +++ b/src/Maker/MakeDockerDatabase.php @@ -102,7 +102,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $io->text($serviceNameMsg); - $this->serviceName = $io->ask(sprintf('What name should we call the new %s service? (e.g. database)', $this->serviceName), null, [Validator::class, 'notBlank']); + $this->serviceName = $io->ask(sprintf('What name should we call the new %s service? (e.g. database)', $this->serviceName), null, Validator::notBlank(...)); } $this->checkForPDOSupport($this->databaseChoice, $io); diff --git a/src/Maker/MakeEntity.php b/src/Maker/MakeEntity.php index e7b1293f1..a4a620d2c 100644 --- a/src/Maker/MakeEntity.php +++ b/src/Maker/MakeEntity.php @@ -111,7 +111,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma 'This command will generate any missing methods (e.g. getters & setters) for a class or all classes in a namespace.', 'To overwrite any existing methods, re-run this command with the --overwrite flag', ], null, 'fg=yellow'); - $classOrNamespace = $io->ask('Enter a class or namespace to regenerate', $this->getEntityNamespace(), [Validator::class, 'notBlank']); + $classOrNamespace = $io->ask('Enter a class or namespace to regenerate', $this->getEntityNamespace(), Validator::notBlank(...)); $input->setArgument('name', $classOrNamespace); @@ -407,13 +407,13 @@ private function askForNextField(ConsoleStyle $io, array $fields, string $entity if ('string' === $type) { // default to 255, avoid the question - $classProperty->length = $io->ask('Field length', 255, [Validator::class, 'validateLength']); + $classProperty->length = $io->ask('Field length', 255, Validator::validateLength(...)); } elseif ('decimal' === $type) { // 10 is the default value given in \Doctrine\DBAL\Schema\Column::$_precision - $classProperty->precision = $io->ask('Precision (total number of digits stored: 100.00 would be 5)', 10, [Validator::class, 'validatePrecision']); + $classProperty->precision = $io->ask('Precision (total number of digits stored: 100.00 would be 5)', 10, Validator::validatePrecision(...)); // 0 is the default value given in \Doctrine\DBAL\Schema\Column::$_scale - $classProperty->scale = $io->ask('Scale (number of decimals to store: 100.00 would be 2)', 0, [Validator::class, 'validateScale']); + $classProperty->scale = $io->ask('Scale (number of decimals to store: 100.00 would be 2)', 0, Validator::validateScale(...)); } if ($io->confirm('Can this field be null in the database (nullable)', false)) { @@ -525,7 +525,7 @@ private function printAvailableTypes(ConsoleStyle $io): void private function createEntityClassQuestion(string $questionText): Question { $question = new Question($questionText); - $question->setValidator([Validator::class, 'notBlank']); + $question->setValidator(Validator::notBlank(...)); $question->setAutocompleterValues($this->doctrineHelper->getEntitiesForAutocomplete()); return $question; diff --git a/src/Maker/MakeListener.php b/src/Maker/MakeListener.php index d961426f8..cd625eb24 100644 --- a/src/Maker/MakeListener.php +++ b/src/Maker/MakeListener.php @@ -98,7 +98,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $io->listing($this->eventRegistry->listActiveEvents($events)); $question = new Question(sprintf(' %s', $command->getDefinition()->getArgument('event')->getDescription())); $question->setAutocompleterValues($events); - $question->setValidator([Validator::class, 'notBlank']); + $question->setValidator(Validator::notBlank(...)); $event = $io->askQuestion($question); $input->setArgument('event', $event); } diff --git a/src/Maker/MakeRegistrationForm.php b/src/Maker/MakeRegistrationForm.php index a9ace9a68..c5ba0d1ef 100644 --- a/src/Maker/MakeRegistrationForm.php +++ b/src/Maker/MakeRegistrationForm.php @@ -158,13 +158,13 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $this->fromEmailAddress = $io->ask( 'What email address will be used to send registration confirmations? (e.g. mailer@your-domain.com)', null, - [Validator::class, 'validateEmailAddress'] + Validator::validateEmailAddress(...) ); $this->fromEmailName = $io->ask( 'What "name" should be associated with that email address? (e.g. Acme Mail Bot)', null, - [Validator::class, 'notBlank'] + Validator::notBlank(...) ); } diff --git a/src/Maker/MakeResetPassword.php b/src/Maker/MakeResetPassword.php index 2748f581d..5409d9adc 100644 --- a/src/Maker/MakeResetPassword.php +++ b/src/Maker/MakeResetPassword.php @@ -160,7 +160,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $this->controllerResetSuccessRedirect = $io->ask( 'What route should users be redirected to after their password has been successfully reset?', 'app_home', - [Validator::class, 'notBlank'] + Validator::notBlank(...) ); $io->section('- Email -'); @@ -170,13 +170,13 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $this->fromEmailAddress = $io->ask( 'What email address will be used to send reset confirmations? e.g. mailer@your-domain.com', null, - [Validator::class, 'validateEmailAddress'] + Validator::validateEmailAddress(...) ); $this->fromEmailName = $io->ask( 'What "name" should be associated with that email address? e.g. "Acme Mail Bot"', null, - [Validator::class, 'notBlank'] + Validator::notBlank(...) ); } diff --git a/src/Maker/MakeStimulusController.php b/src/Maker/MakeStimulusController.php index fa4ecbf1b..4dd23e65e 100644 --- a/src/Maker/MakeStimulusController.php +++ b/src/Maker/MakeStimulusController.php @@ -175,7 +175,7 @@ private function askForNextValue(ConsoleStyle $io, array $values, bool $isFirstV // convert to snake case for simplicity $snakeCasedField = Str::asSnakeCase($valueName); - if ('_id' === substr($snakeCasedField, -3)) { + if (str_ends_with($snakeCasedField, '_id')) { $defaultType = 'Number'; } elseif (str_starts_with($snakeCasedField, 'is_')) { $defaultType = 'Boolean'; diff --git a/src/Maker/MakeSubscriber.php b/src/Maker/MakeSubscriber.php index d5b8423dc..ef431f72c 100644 --- a/src/Maker/MakeSubscriber.php +++ b/src/Maker/MakeSubscriber.php @@ -70,7 +70,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $io->listing($this->eventRegistry->listActiveEvents($events)); $question = new Question(sprintf(' %s', $command->getDefinition()->getArgument('event')->getDescription())); $question->setAutocompleterValues($events); - $question->setValidator([Validator::class, 'notBlank']); + $question->setValidator(Validator::notBlank(...)); $event = $io->askQuestion($question); $input->setArgument('event', $event); } diff --git a/src/Maker/MakeTest.php b/src/Maker/MakeTest.php index b98a314bc..a948a1f1e 100644 --- a/src/Maker/MakeTest.php +++ b/src/Maker/MakeTest.php @@ -126,7 +126,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma ]); $nameArgument = $command->getDefinition()->getArgument('name'); - $value = $io->ask($nameArgument->getDescription(), $nameArgument->getDefault(), [Validator::class, 'notBlank']); + $value = $io->ask($nameArgument->getDescription(), $nameArgument->getDefault(), Validator::notBlank(...)); $input->setArgument($nameArgument->getName(), $value); } } diff --git a/src/Maker/MakeUser.php b/src/Maker/MakeUser.php index a5302e187..ebecd9a88 100644 --- a/src/Maker/MakeUser.php +++ b/src/Maker/MakeUser.php @@ -104,7 +104,7 @@ class_exists(DoctrineBundle::class) } $input->setOption('is-entity', $userIsEntity); - $identityFieldName = $io->ask('Enter a property name that will be the unique "display" name for the user (e.g. email, username, uuid)', 'email', [Validator::class, 'validatePropertyName']); + $identityFieldName = $io->ask('Enter a property name that will be the unique "display" name for the user (e.g. email, username, uuid)', 'email', Validator::validatePropertyName(...)); $input->setOption('identity-property-name', $identityFieldName); $io->text('Will this app need to hash/check user passwords? Choose No if passwords are not needed or will be checked/hashed by some other system (e.g. a single sign-on server).'); diff --git a/src/Maker/Security/MakeFormLogin.php b/src/Maker/Security/MakeFormLogin.php index 072346bab..34d5bd12f 100644 --- a/src/Maker/Security/MakeFormLogin.php +++ b/src/Maker/Security/MakeFormLogin.php @@ -111,7 +111,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $this->controllerName = $io->ask( 'Choose a name for the controller class (e.g. SecurityController)', 'SecurityController', - [Validator::class, 'validateClassName'] + Validator::validateClassName(...) ); $securityHelper = new InteractiveSecurityHelper(); diff --git a/src/Security/InteractiveSecurityHelper.php b/src/Security/InteractiveSecurityHelper.php index d6a472ca5..dca18c7f8 100644 --- a/src/Security/InteractiveSecurityHelper.php +++ b/src/Security/InteractiveSecurityHelper.php @@ -25,9 +25,7 @@ public function guessFirewallName(SymfonyStyle $io, array $securityData, ?string { $realFirewalls = array_filter( $securityData['security']['firewalls'] ?? [], - static function ($item) { - return !isset($item['security']) || true === $item['security']; - } + static fn ($item) => !isset($item['security']) || true === $item['security'] ); if (0 === \count($realFirewalls)) { @@ -56,7 +54,7 @@ public function guessUserClass(SymfonyStyle $io, array $providers, ?string $ques return $io->ask( $questionText ?? 'Enter the User class that you want to authenticate (e.g. App\\Entity\\User)', $this->guessUserClassDefault(), - [Validator::class, 'classIsUserInterface'] + Validator::classIsUserInterface(...) ); } @@ -145,9 +143,7 @@ public function guessPasswordField(SymfonyStyle $io, string $userClass): string public function getAuthenticatorClasses(array $firewallData): array { if (isset($firewallData['guard'])) { - return array_filter($firewallData['guard']['authenticators'] ?? [], static function ($authenticator) { - return class_exists($authenticator); - }); + return array_filter($firewallData['guard']['authenticators'] ?? [], static fn ($authenticator) => class_exists($authenticator)); } if (isset($firewallData['custom_authenticator'])) { @@ -156,9 +152,7 @@ public function getAuthenticatorClasses(array $firewallData): array $authenticators = [$authenticators]; } - return array_filter($authenticators, static function ($authenticator) { - return class_exists($authenticator); - }); + return array_filter($authenticators, static fn ($authenticator) => class_exists($authenticator)); } return []; diff --git a/src/Security/SecurityConfigUpdater.php b/src/Security/SecurityConfigUpdater.php index 2f45b0c8e..e713bc1b6 100644 --- a/src/Security/SecurityConfigUpdater.php +++ b/src/Security/SecurityConfigUpdater.php @@ -23,7 +23,7 @@ */ final class SecurityConfigUpdater { - private ?YamlSourceManipulator $manipulator; + private ?YamlSourceManipulator $manipulator = null; public function __construct( private ?Logger $ysmLogger = null, diff --git a/src/Util/ClassSourceManipulator.php b/src/Util/ClassSourceManipulator.php index 9d429624d..4dbe9c05d 100644 --- a/src/Util/ClassSourceManipulator.php +++ b/src/Util/ClassSourceManipulator.php @@ -234,9 +234,7 @@ public function addTrait(string $trait): void $importedClassName = $this->addUseStatementIfNecessary($trait); /** @var Node\Stmt\TraitUse[] $traitNodes */ - $traitNodes = $this->findAllNodes(function ($node) { - return $node instanceof Node\Stmt\TraitUse; - }); + $traitNodes = $this->findAllNodes(fn ($node) => $node instanceof Node\Stmt\TraitUse); foreach ($traitNodes as $node) { if ($node->traits[0]->toString() === $importedClassName) { @@ -734,7 +732,7 @@ private function addStatementToConstructor(Node\Stmt $stmt): void new Node\Expr\StaticCall(new Node\Name('parent'), new Node\Identifier('__construct')) ); } - } catch (\ReflectionException $e) { + } catch (\ReflectionException) { } $this->addNodeAfterProperties($constructorNode); @@ -914,7 +912,7 @@ private function setSourceCode(string $sourceCode): void /* @legacy Support for nikic/php-parser v4 */ if (\is_callable([$this->parser, 'getTokens'])) { $this->oldTokens = $this->parser->getTokens(); - } elseif (\is_callable([$this->lexer, 'getTokens'])) { + } elseif (\is_callable($this->lexer->getTokens(...))) { $this->oldTokens = $this->lexer->getTokens(); } @@ -928,9 +926,7 @@ private function setSourceCode(string $sourceCode): void private function getClassNode(): Node\Stmt\Class_ { - $node = $this->findFirstNode(function ($node) { - return $node instanceof Node\Stmt\Class_; - }); + $node = $this->findFirstNode(fn ($node) => $node instanceof Node\Stmt\Class_); if (!$node) { throw new \Exception('Could not find class node'); @@ -941,9 +937,7 @@ private function getClassNode(): Node\Stmt\Class_ private function getNamespaceNode(): Node\Stmt\Namespace_ { - $node = $this->findFirstNode(function ($node) { - return $node instanceof Node\Stmt\Namespace_; - }); + $node = $this->findFirstNode(fn ($node) => $node instanceof Node\Stmt\Namespace_); if (!$node) { throw new \Exception('Could not find namespace node'); @@ -1114,22 +1108,16 @@ private function addNodeAfterProperties(Node $newNode): void $classNode = $this->getClassNode(); // try to add after last property - $targetNode = $this->findLastNode(function ($node) { - return $node instanceof Node\Stmt\Property; - }, [$classNode]); + $targetNode = $this->findLastNode(fn ($node) => $node instanceof Node\Stmt\Property, [$classNode]); // otherwise, try to add after the last constant if (!$targetNode) { - $targetNode = $this->findLastNode(function ($node) { - return $node instanceof Node\Stmt\ClassConst; - }, [$classNode]); + $targetNode = $this->findLastNode(fn ($node) => $node instanceof Node\Stmt\ClassConst, [$classNode]); } // otherwise, try to add after the last trait if (!$targetNode) { - $targetNode = $this->findLastNode(function ($node) { - return $node instanceof Node\Stmt\TraitUse; - }, [$classNode]); + $targetNode = $this->findLastNode(fn ($node) => $node instanceof Node\Stmt\TraitUse, [$classNode]); } // add the new property after this node @@ -1322,12 +1310,10 @@ private function buildNodeExprByValue(mixed $value): Node\Expr break; case 'array': $context = $this; - $arrayItems = array_map(static function ($key, $value) use ($context) { - return new Node\Expr\ArrayItem( - $context->buildNodeExprByValue($value), - !\is_int($key) ? $context->buildNodeExprByValue($key) : null - ); - }, array_keys($value), array_values($value)); + $arrayItems = array_map(static fn ($key, $value) => new Node\Expr\ArrayItem( + $context->buildNodeExprByValue($value), + !\is_int($key) ? $context->buildNodeExprByValue($key) : null + ), array_keys($value), array_values($value)); $nodeValue = new Node\Expr\Array_($arrayItems, ['kind' => Node\Expr\Array_::KIND_SHORT]); break; default: @@ -1361,9 +1347,7 @@ private function sortOptionsByClassConstructorParameters(array $options, string $classString = sprintf('Doctrine\\ORM\\Mapping\\%s', substr($classString, 4)); } - $constructorParameterNames = array_map(static function (\ReflectionParameter $reflectionParameter) { - return $reflectionParameter->getName(); - }, (new \ReflectionClass($classString))->getConstructor()->getParameters()); + $constructorParameterNames = array_map(static fn (\ReflectionParameter $reflectionParameter) => $reflectionParameter->getName(), (new \ReflectionClass($classString))->getConstructor()->getParameters()); $sorted = []; foreach ($constructorParameterNames as $name) { diff --git a/src/Util/YamlSourceManipulator.php b/src/Util/YamlSourceManipulator.php index 67da7a486..0728a5145 100644 --- a/src/Util/YamlSourceManipulator.php +++ b/src/Util/YamlSourceManipulator.php @@ -456,7 +456,7 @@ private function removeKeyFromYaml($key, $currentVal) * * @param mixed $value The new value to set into YAML */ - private function changeValueInYaml($value) + private function changeValueInYaml(mixed $value) { $originalVal = $this->getCurrentData(); @@ -696,7 +696,7 @@ private function updateContents(string $newContents, array $newData, int $newPos if ($parsedContentsData !== $newData) { throw new YamlManipulationFailedException(sprintf('Content was updated, but updated content does not match expected data. Original source: "%s", updated source: "%s", updated data: %s', $this->contents, $newContents, var_export($newData, true))); } - } catch (ParseException $e) { + } catch (ParseException) { throw new YamlManipulationFailedException(sprintf('Could not update YAML: a parse error occurred in the new content: "%s"', $newContents)); } @@ -829,7 +829,7 @@ private function findEndPositionOfValue($value, $offset = null) } if (\is_scalar($value) || null === $value) { - $offset = null === $offset ? $this->currentPosition : $offset; + $offset ??= $this->currentPosition; if (\is_bool($value)) { // (?i) & (?-i) opens/closes case insensitive match @@ -1090,9 +1090,7 @@ private function isHash($value): bool private function normalizeSequences(array $data) { // https://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential/4254008#4254008 - $hasStringKeys = function (array $array) { - return \count(array_filter(array_keys($array), 'is_string')) > 0; - }; + $hasStringKeys = fn (array $array) => \count(array_filter(array_keys($array), 'is_string')) > 0; foreach ($data as $key => $val) { if (!\is_array($val)) { @@ -1176,7 +1174,7 @@ private function manuallyIncrementIndentation() private function isEOF(?int $position = null) { - $position = null === $position ? $this->currentPosition : $position; + $position ??= $this->currentPosition; return $position === \strlen($this->contents); }