Skip to content

Commit

Permalink
minor #43628 [Console] Remove CompletionInterface (derrabus)
Browse files Browse the repository at this point in the history
This PR was merged into the 5.4 branch.

Discussion
----------

[Console] Remove `CompletionInterface`

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | #43620 (comment)
| License       | MIT
| Doc PR        | N/A

Commits
-------

cd49146 [Console] Remove CompletionInterface
  • Loading branch information
fabpot committed Oct 21, 2021
2 parents ec34dd5 + cd49146 commit 540ee0a
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 52 deletions.
Expand Up @@ -14,7 +14,6 @@
use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionInterface;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -29,7 +28,7 @@
*
* @internal
*/
final class SecretsRemoveCommand extends Command implements CompletionInterface
final class SecretsRemoveCommand extends Command
{
protected static $defaultName = 'secrets:remove';
protected static $defaultDescription = 'Remove a secret from the vault';
Expand Down
5 changes: 2 additions & 3 deletions src/Symfony/Component/Console/Application.php
Expand Up @@ -20,7 +20,6 @@
use Symfony\Component\Console\Command\SignalableCommandInterface;
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionInterface;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
Expand Down Expand Up @@ -69,7 +68,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Application implements ResetInterface, CompletionInterface
class Application implements ResetInterface
{
private $commands = [];
private $wantHelps = false;
Expand Down Expand Up @@ -356,7 +355,7 @@ public function getDefinition()
}

/**
* {@inheritdoc}
* Adds suggestions to $suggestions for the current completion input (e.g. option or argument).
*/
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/Console/Command/Command.php
Expand Up @@ -13,6 +13,8 @@

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Exception\ExceptionInterface;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\LogicException;
Expand Down Expand Up @@ -303,6 +305,13 @@ public function run(InputInterface $input, OutputInterface $output)
return is_numeric($statusCode) ? (int) $statusCode : 0;
}

/**
* Adds suggestions to $suggestions for the current completion input (e.g. option or argument).
*/
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
}

/**
* Sets the code to execute when running this command.
*
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Console/Command/CompleteCommand.php
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Console\Command;

use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionInterface;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Completion\Output\BashCompletionOutput;
use Symfony\Component\Console\Exception\CommandNotFoundException;
Expand Down Expand Up @@ -107,7 +106,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->log(' Completing option names for the <comment>'.\get_class($command instanceof LazyCommand ? $command->getCommand() : $command).'</> command.');

$suggestions->suggestOptions($command->getDefinition()->getOptions());
} elseif ($command instanceof CompletionInterface) {
} else {
$this->log([
' Completing using the <comment>'.\get_class($command).'</> class.',
' Completing <comment>'.$completionInput->getCompletionType().'</> for <comment>'.$completionInput->getCompletionName().'</>',
Expand Down
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Console\Command;

use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionInterface;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -26,7 +25,7 @@
*
* @author Wouter de Jong <wouter@wouterj.nl>
*/
final class DumpCompletionCommand extends Command implements CompletionInterface
final class DumpCompletionCommand extends Command
{
protected static $defaultName = 'completion';
protected static $defaultDescription = 'Dump the shell completion script';
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Console/Command/HelpCommand.php
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Console\Command;

use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionInterface;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Descriptor\ApplicationDescription;
use Symfony\Component\Console\Helper\DescriptorHelper;
Expand All @@ -26,7 +25,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class HelpCommand extends Command implements CompletionInterface
class HelpCommand extends Command
{
private $command;

Expand Down
7 changes: 2 additions & 5 deletions src/Symfony/Component/Console/Command/LazyCommand.php
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionInterface;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\InputDefinition;
Expand All @@ -23,7 +22,7 @@
/**
* @author Nicolas Grekas <p@tchwork.com>
*/
final class LazyCommand extends Command implements CompletionInterface
final class LazyCommand extends Command
{
private $command;
private $isEnabled;
Expand Down Expand Up @@ -74,9 +73,7 @@ public function run(InputInterface $input, OutputInterface $output): int

public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
if ($this->getCommand() instanceof CompletionInterface) {
$this->getCommand()->complete($input, $suggestions);
}
$this->getCommand()->complete($input, $suggestions);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Console/Command/ListCommand.php
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Console\Command;

use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionInterface;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Descriptor\ApplicationDescription;
use Symfony\Component\Console\Helper\DescriptorHelper;
Expand All @@ -26,7 +25,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class ListCommand extends Command implements CompletionInterface
class ListCommand extends Command
{
/**
* {@inheritdoc}
Expand Down
27 changes: 0 additions & 27 deletions src/Symfony/Component/Console/Completion/CompletionInterface.php

This file was deleted.

Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionInterface;
use Symfony\Component\Console\Completion\CompletionSuggestions;

/**
Expand All @@ -35,10 +34,6 @@ public function __construct(Command $command)
*/
public function complete(array $input): array
{
if (!$this->command instanceof CompletionInterface) {
throw new \LogicException(sprintf('Command "%s" must implement "%s" to support completion.', \get_class($this->command), CompletionInput::class));
}

$currentIndex = \count($input);
if ('' === end($input)) {
array_pop($input);
Expand Down
Expand Up @@ -16,7 +16,6 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Command\CompleteCommand;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionInterface;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -115,7 +114,7 @@ private function execute(array $input)
}
}

class CompleteCommandTest_HelloCommand extends Command implements CompletionInterface
class CompleteCommandTest_HelloCommand extends Command
{
public function configure(): void
{
Expand Down

0 comments on commit 540ee0a

Please sign in to comment.