name = $name; } /** * Default value to use if none provided. * * @return mixed */ public function getDefault() { return $this->default; } public function getDescription(): string { return $this->description; } public function getName(): string { return $this->name; } public function getOptionMode(): int { return $this->optionMode; } /** * @return null|string|string[] */ public function getShortcut() { return $this->shortcut; } public function isRequired(): bool { return $this->required; } /** * @param mixed $defaultValue * @psalm-suppress LessSpecificImplementedReturnType */ public function setDefault($defaultValue): InputParamInterface { $this->default = $defaultValue; return $this; } public function setDescription(string $description): InputParamInterface { $this->description = $description; return $this; } /** * @param null|string|string[] $shortcut * @psalm-suppress LessSpecificImplementedReturnType */ public function setShortcut($shortcut): InputParamInterface { $this->validateShortcut($shortcut); $this->shortcut = $shortcut; return $this; } public function setRequiredFlag(bool $required): InputParamInterface { $this->required = $required; return $this; } /** * @param mixed $shortcut * @throws InvalidArgumentException When shortcut is an invalid type. * @throws InvalidArgumentException When shortcut is empty. */ private function validateShortcut($shortcut): void { if (null === $shortcut) { return; } if (is_string($shortcut)) { $trimmedShortcut = trim($shortcut, ' -'); Assert::stringNotEmpty($trimmedShortcut, sprintf( 'Shortcut must be null, a non-zero-length string, or an array of strings; received "%s"', get_debug_type($shortcut) )); return; } Assert::isNonEmptyList( $shortcut, sprintf( 'Shortcut must be null, a non-zero-length string, or an array of strings; received "%s"', get_debug_type($shortcut) ) ); array_walk( $shortcut, /** @param mixed $shortcut */ static function ($shortcut) { Assert::stringNotEmpty($shortcut, sprintf( 'Only non-empty strings are allowed as shortcut names; received "%s"', get_debug_type($shortcut) )); if ('' === trim($shortcut, ' -')) { throw new InvalidArgumentException( 'String values in arrays provided as shortcut names must not be empty' ); } } ); } }