8000 bug #20900 [Console] Descriptors should use Helper::strlen (ogizanagi) · symfony/symfony@f1f5bff · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit f1f5bff

Browse files
bug #20900 [Console] Descriptors should use Helper::strlen (ogizanagi)
This PR was squashed before being merged into the 2.7 branch (closes #20900). Discussion ---------- [Console] Descriptors should use Helper::strlen | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A Commits ------- 8e9a5f8 [Console] Descriptors should use Helper::strlen
2 parents d85febc + 8e9a5f8 commit f1f5bff

11 files changed

+479
-11
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Console\Application;
1515
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Helper\Helper;
1617
use Symfony\Component\Console\Input\InputArgument;
1718
use Symfony\Component\Console\Input\InputDefinition;
1819
use Symfony\Component\Console\Input\InputOption;
@@ -94,7 +95,7 @@ protected function describeCommand(Command $command, array $options = array())
9495

9596
$this->write(
9697
$command->getName()."\n"
97-
.str_repeat('-', strlen($command->getName()))."\n\n"
98+
.str_repeat('-', Helper::strlen($command->getName()))."\n\n"
9899
.'* Description: '.($command->getDescription() ?: '<none>')."\n"
99100
.'* Usage:'."\n\n"
100101
.array_reduce(array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()), function ($carry, $usage) {
@@ -121,7 +122,7 @@ protected function describeApplication(Application $application, array $options
121122
$describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
122123
$description = new ApplicationDescription($application, $describedNamespace);
123124

124-
$this->write($application->getName()."\n".str_repeat('=', strlen($application->getName())));
125+
$this->write($application->getName()."\n".str_repeat('=', Helper::strlen($application->getName())));
125126

126127
foreach ($description->getNamespaces() as $namespace) {
127128
if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Console\Application;
1515
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Helper\Helper;
1617
use Symfony\Component\Console\Input\InputArgument;
1718
use Symfony\Component\Console\Input\InputDefinition;
1819
use Symfony\Component\Console\Input\InputOption;
@@ -37,7 +38,7 @@ protected function describeInputArgument(InputArgument $argument, array $options
3738
$default = '';
3839
}
3940

40-
$totalWidth = isset($options['total_width']) ? $options['total_width'] : strlen($argument->getName());
41+
$totalWidth = isset($options['total_width']) ? $options['total_width'] : Helper::strlen($argument->getName());
4142
$spacingWidth = $totalWidth - strlen($argument->getName());
4243

4344
$this->writeText(sprintf(' <info>%s</info> %s%s%s',
@@ -75,7 +76,7 @@ protected function describeInputOption(InputOption $option, array $ 57AE options = arr
7576
sprintf('--%s%s', $option->getName(), $value)
7677
);
7778

78-
$spacingWidth = $totalWidth - strlen($synopsis);
79+
$spacingWidth = $totalWidth - Helper::strlen($synopsis);
7980

8081
$this->writeText(sprintf(' <info>%s</info> %s%s%s%s',
8182
$synopsis,
@@ -94,7 +95,7 @@ protected function describeInputDefinition(InputDefinition $definition, array $o
9495
{
9596
$totalWidth = $this->calculateTotalWidthForOptions($definition->getOptions());
9697
foreach ($definition->getArguments() as $argument) {
97-
$totalWidth = max($totalWidth, strlen($argument->getName()));
98+
$totalWidth = max($totalWidth, Helper::strlen($argument->getName()));
9899
}
99100

100101
if ($definition->getArguments()) {
@@ -206,7 +207,7 @@ protected function describeApplication(Application $application, array $options
206207

207208
foreach ($namespace['commands'] as $name) {
208209
$this->writeText("\n");
209-
$spacingWidth = $width - strlen($name);
210+
$spacingWidth = $width - Helper::strlen($name);
210211
$this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options);
211212
}
212213
}
@@ -252,9 +253,9 @@ private function getColumnWidth(array $commands)
252253
$widths = array();
253254

254255
foreach ($commands as $command) {
255-
$widths[] = strlen($command->getName());
256+
$widths[] = Helper::strlen($command->getName());
256257
foreach ($command->getAliases() as $alias) {
257-
$widths[] = strlen($alias);
258+
$widths[] = Helper::strlen($alias);
258259
}
259260
}
260261

@@ -271,10 +272,10 @@ private function calculateTotalWidthForOptions($options)
271272
$totalWidth = 0;
272273
foreach ($options as $option) {
273274
// "-" + shortcut + ", --" + name
274-
$nameLength = 1 + max(strlen($option->getShortcut()), 1) + 4 + strlen($option->getName());
275+
$nameLength = 1 + max(strlen($option->getShortcut()), 1) + 4 + Helper::strlen($option->getName());
275276

276277
if ($option->acceptValue()) {
277-
$valueLength = 1 + strlen($option->getName()); // = + value
278+
$valueLength = 1 + Helper::strlen($option->getName()); // = + value
278279
$valueLength += $option->isValueOptional() ? 2 : 0; // [ + ]
279280

280281
$nameLength += $valueLength;

src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ abstract protected function getDescriptor();
8686

8787
abstract protected function getFormat();
8888

89-
private function getDescriptionTestData(array $objects)
89+
protected function getDescriptionTestData(array $objects)
9090
{
9191
$data = array();
9292
foreach ($objects as $name => $object) {

src/Symfony/Component/Console/Tests/Descriptor/MarkdownDescriptorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,27 @@
1212
namespace Symfony\Component\Console\Tests\Descriptor;
1313

1414
use Symfony\Component\Console\Descriptor\MarkdownDescriptor;
15+
use Symfony\Component\Console\Tests\Fixtures\DescriptorApplicationMbString;
16+
use Symfony\Component\Console\Tests\Fixtures\DescriptorCommandMbString;
1517

1618
class MarkdownDescriptorTest extends AbstractDescriptorTest
1719
{
20+
public function getDescribeCommandTestData()
21+
{
22+
return $this->getDescriptionTestData(array_merge(
23+
ObjectsProvider::getCommands(),
24+
array('command_mbstring' => new DescriptorCommandMbString())
25+
));
26+
}
27+
28+
public function getDescribeApplicationTestData()
29+
{
30+
return $this->getDescriptionTestData(array_merge(
31+
ObjectsProvider::getApplications(),
32+
array('application_mbstring' => new DescriptorApplicationMbString())
33+
));
34+
}
35+
1836
protected function getDescriptor()
1937
{
2038
return new MarkdownDescriptor();

src/Symfony/Component/Console/Tests/Descriptor/TextDescriptorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,27 @@
1212
namespace Symfony\Component\Console\Tests\Descriptor;
1313

1414
use Symfony\Component\Console\Descriptor\TextDescriptor;
15+
use Symfony\Component\Console\Tests\Fixtures\DescriptorApplicationMbString;
16+
use Symfony\Component\Console\Tests\Fixtures\DescriptorCommandMbString;
1517

1618
class TextDescriptorTest extends AbstractDescriptorTest
1719
{
20+
public function getDescribeCommandTestData()
21+
{
22+
return $this->getDescriptionTestData(array_merge(
23+
ObjectsProvider::getCommands(),
24+
array('command_mbstring' => new DescriptorCommandMbString())
25+
));
26+
}
27+
28+
public function getDescribeApplicationTestData()
29+
{
30+
return $this->getDescriptionTestData(array_merge(
31+
ObjectsProvider::getApplications(),
32+
array('application_mbstring' => new DescriptorApplicationMbString())
33+
));
34+
}
35+
1836
protected function getDescriptor()
1937
{
2038
return new TextDescriptor();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Tests\Fixtures;
13+
14+
use Symfony\Component\Console\Application;
15+
16+
class DescriptorApplicationMbString extends Application
17+
{
18+
public function __construct()
19+
{
20+
parent::__construct('MbString åpplicätion');
21+
22+
$this->add(new DescriptorCommandMbString());
23+
}
24+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Tests\Fixtures;
13+
14+
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Input\InputArgument;
16+
use Symfony\Component\Console\Input\InputOption;
17+
18+
class DescriptorCommandMbString extends Command
19+
{
20+
protected function configure()
21+
{
22+
$this
23+
->setName('descriptor:åèä')
24+
->setDescription('command åèä description')
25+
->setHelp('command åèä help')
26+
->addUsage('-o|--option_name <argument_name>')
27+
->addUsage('<argument_name>')
28+
->addArgument('argument_åèä', InputArgument::REQUIRED)
29+
->addOption('option_åèä', 'o', InputOption::VALUE_NONE)
30+
;
31+
}
32+
}

0 commit comments

Comments
 (0)
0