Cli/src/Commands/ParameterDefinition.php

72 lines
1.3 KiB
PHP
Raw Normal View History

2024-11-08 15:56:14 +01:00
<?php
namespace Nest\Cli\Commands;
/**
* A parameter definition object.
*/
class ParameterDefinition
{
/**
* Parameter description.
* @var string|null
*/
protected ?string $description = null;
/**
* Set if the parameter is optional or not. By default, it is NOT optional.
* @var bool
*/
protected bool $optional = false;
/**
* Set the description of the parameter.
* @param string $description The description of the parameter.
* @return $this
*/
public function description(string $description): static
{
// Set description.
$this->description = $description;
return $this;
}
/**
* Set the parameter as optional (or not).
* @param bool $optional True to set the parameter as optional.
* @return $this
*/
public function optional(bool $optional = true): static
{
$this->optional = $optional;
return $this;
}
/**
* Set the parameter as required.
* @return $this
*/
public function require(): static
{
return $this->optional(false);
}
/**
* Get parameter description.
* @return string
*/
public function getDescription(): string
{
return $this->description ?? "";
}
/**
* Determine if the parameter is required or not.
* @return bool True if the parameter is required.
*/
public function isRequired(): bool
{
return !$this->optional;
}
}