Skip to content
PHP Ecosystem
Explore

UnknownCommandException

API reference › yii › console › UnknownCommandException

classyii\console\UnknownCommandException
ExtendsException » yii\base\UserException » yii\base\Exception » Exception
Since2.0.11
Sourceframework/console/UnknownCommandException.php

UnknownCommandException represents an exception caused by incorrect usage of a console command.

PropertyTypeDescriptionDefined by
$commandstringThe name of the command that could not be recognized. Default: null.UnknownCommandException
$application protectedApplicationDefault: null.UnknownCommandException
MethodDescriptionDefined by
__construct()Construct the exception.UnknownCommandException
getName()UnknownCommandException
getSuggestedAlternatives()Suggest alternative commands for $command based on string similarity.UnknownCommandException
public function __construct(string $route, yii\console\Application $application, int $code = 0, Throwable|null $previous = null)

Construct the exception.

Parameters

ParameterTypeDescription
$routestringThe route of the command that could not be found.
$applicationApplicationThe console application instance involved.
$codeintThe Exception code.
$previousThrowable|nullThe previous exception used for the exception chaining.
public function getName(): string

Returns

string: The user-friendly name of this exception

public function getSuggestedAlternatives(): array

Suggest alternative commands for $command based on string similarity.

Alternatives are searched using the following steps:

  • suggest alternatives that begin with $command
  • find typos by calculating the Levenshtein distance between the unknown command and all available commands. The Levenshtein distance is defined as the minimal number of characters you have to replace, insert or delete to transform str1 into str2.

Returns

array: A list of suggested alternatives sorted by similarity.

See also