Webmozart\Console\Api\Command\CannotAddCommandException::optionExists PHP Méthode

optionExists() public static méthode

Creates an exception for the code {@link OPTION_EXISTS}.
public static optionExists ( string $name, Exception $cause = null ) : static
$name string The command name.
$cause Exception The exception that caused this exception.
Résultat static The created exception.
    public static function optionExists($name, Exception $cause = null)
    {
        return new static(sprintf('An option named "%s%s" exists already.', strlen($name) > 1 ? '--' : '-', $name), self::OPTION_EXISTS, $cause);
    }

Usage Example

Exemple #1
0
 private function validateSubCommandName(SubCommandConfig $config)
 {
     $name = $config->getName();
     if (!$name) {
         throw CannotAddCommandException::nameEmpty();
     }
     if ($this->subCommands->contains($name)) {
         throw CannotAddCommandException::nameExists($name);
     }
     if ($config instanceof OptionCommandConfig) {
         if ($this->argsFormat->hasOption($name)) {
             throw CannotAddCommandException::optionExists($name);
         }
         if ($shortName = $config->getShortName()) {
             if ($this->subCommands->contains($shortName)) {
                 throw CannotAddCommandException::nameExists($name);
             }
             if ($this->argsFormat->hasOption($shortName)) {
                 throw CannotAddCommandException::optionExists($shortName);
             }
         }
     }
 }