Skip to content

Commit 0bc4037

Browse files
committed
code style fixes
1 parent 0f869b7 commit 0bc4037

File tree

1 file changed

+32
-52
lines changed

1 file changed

+32
-52
lines changed

src/Symfony/Component/Console/Descriptor/ReStructuredTextDescriptor.php

Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Console\Descriptor;
1313

14-
use Exception;
1514
use Symfony\Component\Console\Application;
1615
use Symfony\Component\Console\Command\Command;
1716
use Symfony\Component\Console\Helper\Helper;
@@ -77,11 +76,11 @@ protected function describeInputOption(InputOption $option, array $options = [])
7776
$name .= '|-'.str_replace('|', '|-', $option->getShortcut());
7877
}
7978

80-
$option_description = $option->getDescription() ? preg_replace('/\s*[\r\n]\s*/', "\n\n", $option->getDescription())."\n\n" : '';
81-
$option_description = (new UnicodeString($option_description))->ascii();
79+
$optionDescription = $option->getDescription() ? preg_replace('/\s*[\r\n]\s*/', "\n\n", $option->getDescription())."\n\n" : '';
80+
$optionDescription = (new UnicodeString($optionDescription))->ascii();
8281
$this->write(
8382
$name."\n".str_repeat($this->paragraphsChar, Helper::width($name))."\n\n"
84-
.$option_description
83+
.$optionDescription
8584
.'- **Accept value**: '.($option->acceptValue() ? 'yes' : 'no')."\n"
8685
.'- **Is value required**: '.($option->isValueRequired() ? 'yes' : 'no')."\n"
8786
.'- **Is multiple**: '.($option->isArray() ? 'yes' : 'no')."\n"
@@ -92,22 +91,21 @@ protected function describeInputOption(InputOption $option, array $options = [])
9291

9392
protected function describeInputDefinition(InputDefinition $definition, array $options = []): void
9493
{
95-
if ($showArguments = (\count($definition->getArguments()) > 0)) {
94+
if ($showArguments = ((bool)$definition->getArguments())) {
9695
$this->write("Arguments\n".str_repeat($this->subsubsectionChar, 9))."\n\n";
9796
foreach ($definition->getArguments() as $argument) {
9897
$this->write("\n\n");
9998
$this->describeInputArgument($argument);
10099
}
101100
}
102101

103-
$non_default_options = $this->getNonDefaultOptions($definition);
104-
if (\count($non_default_options) > 0) {
102+
if ($nonDefaultOptions = $this->getNonDefaultOptions($definition)) {
105103
if ($showArguments) {
106104
$this->write("\n\n");
107105
}
108106

109107
$this->write("Options\n".str_repeat($this->subsubsectionChar, 7)."\n\n");
110-
foreach ($non_default_options as $option) {
108+
foreach ($nonDefaultOptions as $option) {
111109
$this->describeInputOption($option);
112110
$this->write("\n");
113111
}
@@ -122,9 +120,7 @@ protected function describeCommand(Command $command, array $options = []): void
122120
.str_repeat($this->subsectionChar, Helper::width($command->getName()))."\n\n"
123121
.($command->getDescription() ? $command->getDescription()."\n\n" : '')
124122
."Usage\n".str_repeat($this->paragraphsChar, 5)."\n\n"
125-
.array_reduce($command->getAliases(), static function ($carry, $usage) {
126-
return $carry.'- ``'.$usage.'``'."\n";
127-
})
123+
.array_reduce($command->getAliases(), static fn ($carry, $usage) => $carry.'- ``'.$usage.'``'."\n")
128124
);
129125

130126
return;
@@ -140,9 +136,7 @@ protected function describeCommand(Command $command, array $options = []): void
140136
.str_repeat($this->subsectionChar, Helper::width($command->getName()))."\n\n"
141137
.($command->getDescription() ? $command->getDescription()."\n\n" : '')
142138
."Usage\n".str_repeat($this->subsubsectionChar, 5)."\n\n"
143-
.array_reduce(array_merge([$command->getSynopsis()], $command->getAliases(), $command->getUsages()), static function ($carry, $usage) {
144-
return $carry.'- ``'.$usage.'``'."\n";
145-
})
139+
.array_reduce(array_merge([$command->getSynopsis()], $command->getAliases(), $command->getUsages()), static fn ($carry, $usage) => $carry.'- ``'.$usage.'``'."\n")
146140
);
147141

148142
if ($help = $command->getProcessedHelp()) {
@@ -159,8 +153,7 @@ protected function describeCommand(Command $command, array $options = []): void
159153

160154
protected function describeApplication(Application $application, array $options = []): void
161155
{
162-
$describedNamespace = $options['namespace'] ?? null;
163-
$description = new ApplicationDescription($application, $describedNamespace);
156+
$description = new ApplicationDescription($application, $options['namespace'] ?? null);
164157
$title = $this->getApplicationTitle($application);
165158

166159
$this->write($title."\n".str_repeat($this->partChar, Helper::width($title)));
@@ -170,15 +163,14 @@ protected function describeApplication(Application $application, array $options
170163

171164
private function getApplicationTitle(Application $application): string
172165
{
173-
if ('UNKNOWN' !== $application->getName()) {
174-
if ('UNKNOWN' !== $application->getVersion()) {
175-
return sprintf('%s %s', $application->getName(), $application->getVersion());
176-
}
177-
178-
return $application->getName();
166+
if ('UNKNOWN' === $application->getName()) {
167+
return 'Console Tool';
168+
}
169+
if ('UNKNOWN' !== $application->getVersion()) {
170+
return sprintf('%s %s', $application->getName(), $application->getVersion());
179171
}
180172

181-
return 'Console Tool';
173+
return $application->getName();
182174
}
183175

184176
private function describeCommands($application, array $options): void
@@ -193,23 +185,19 @@ private function describeCommands($application, array $options): void
193185
$commands = $application->all($namespace);
194186
$this->write($namespace."\n".str_repeat($this->sectionChar, Helper::width($namespace))."\n\n");
195187
}
196-
$commands = $this->removeAliasesAndHiddenCommands($commands);
197188

198-
foreach ($commands as $command) {
189+
foreach ($this->removeAliasesAndHiddenCommands($commands) as $command) {
199190
$this->describeCommand($command, $options);
200191
$this->write("\n\n");
201192
}
202193
}
203194
}
204195

205-
/**
206-
* @param \Symfony\Component\Console\Descriptor\ApplicationDescription $description
207-
*/
208196
private function createTableOfContents(ApplicationDescription $description, Application $application): void
209197
{
210198
$this->setVisibleNamespaces($description);
211-
$chapter_title = 'Table of Contents';
212-
$this->write("\n\n$chapter_title\n".str_repeat($this->chapterChar, Helper::width($chapter_title))."\n\n");
199+
$chapterTitle = 'Table of Contents';
200+
$this->write("\n\n$chapterTitle\n".str_repeat($this->chapterChar, Helper::width($chapterTitle))."\n\n");
213201
foreach ($this->visibleNamespaces as $namespace) {
214202
if ('_global' === $namespace) {
215203
$commands = $application->all('');
@@ -221,65 +209,57 @@ private function createTableOfContents(ApplicationDescription $description, Appl
221209
$commands = $this->removeAliasesAndHiddenCommands($commands);
222210

223211
$this->write("\n\n");
224-
$this->write(implode("\n", array_map(static function ($commandName) {
225-
return sprintf('- `%s`_', $commandName);
226-
}, array_keys($commands))));
212+
$this->write(implode("\n", array_map(static fn ($commandName) => sprintf('- `%s`_', $commandName), array_keys($commands))));
227213
}
228214
}
229215

230216
private function getNonDefaultOptions(InputDefinition $definition): array
231217
{
232-
$global_options = [
218+
$globalOptions = [
233219
'help',
234220
'quiet',
235221
'verbose',
236222
'version',
237223
'ansi',
238224
'no-interaction',
239225
];
240-
$non_default_options = [];
226+
$nonDefaultOptions = [];
241227
foreach ($definition->getOptions() as $option) {
242228
// Skip global options.
243-
// @todo Show these once at the beginning.
244-
if (!\in_array($option->getName(), $global_options)) {
245-
$non_default_options[] = $option;
229+
if (!\in_array($option->getName(), $globalOptions)) {
230+
$nonDefaultOptions[] = $option;
246231
}
247232
}
248233

249-
return $non_default_options;
234+
return $nonDefaultOptions;
250235
}
251236

252-
/**
253-
* @param \Symfony\Component\Console\Descriptor\ApplicationDescription $description
254-
*/
255237
private function setVisibleNamespaces(ApplicationDescription $description): void
256238
{
257239
$commands = $description->getCommands();
258240
foreach ($description->getNamespaces() as $namespace) {
259241
try {
260-
// Remove aliases.
261-
$namespace_commands = $namespace['commands'];
262-
foreach ($namespace_commands as $key => $command_name) {
263-
if (!\array_key_exists($command_name, $commands)) {
242+
$namespaceCommands = $namespace['commands'];
243+
foreach ($namespaceCommands as $key => $commandName) {
244+
if (!\array_key_exists($commandName, $commands)) {
264245
// If the array key does not exist, then this is an alias.
265-
unset($namespace_commands[$key]);
266-
} elseif ($commands[$command_name]->isHidden()) {
267-
unset($namespace_commands[$key]);
246+
unset($namespaceCommands[$key]);
247+
} elseif ($commands[$commandName]->isHidden()) {
248+
unset($namespaceCommands[$key]);
268249
}
269250
}
270-
if (!\count($namespace_commands)) {
251+
if (!$namespaceCommands) {
271252
// If the namespace contained only aliases or hidden commands, skip the namespace.
272253
continue;
273254
}
274-
} catch (Exception) {
255+
} catch (\Exception) {
275256
}
276257
$this->visibleNamespaces[] = $namespace['id'];
277258
}
278259
}
279260

280261
private function removeAliasesAndHiddenCommands(array $commands): array
281262
{
282-
// Remove aliases.
283263
foreach ($commands as $key => $command) {
284264
if ($command->isHidden() || \in_array($key, $command->getAliases(), true)) {
285265
unset($commands[$key]);

0 commit comments

Comments
 (0)