GetOptionKit\Option::renderValueHint PHP Method

renderValueHint() public method

public renderValueHint ( )
    public function renderValueHint()
    {
        $n = null;
        if ($this->valueName) {
            $n = $this->valueName;
        } else {
            if ($values = $this->getValidValues()) {
                $n = '(' . implode(',', $values) . ')';
            } else {
                if ($values = $this->getSuggestions()) {
                    $n = '[' . implode(',', $values) . ']';
                } else {
                    if ($val = $this->defaultValue) {
                        // This allows for `0` and `false` values to be displayed also.
                        if (is_scalar($val) && strlen((string) $val) || is_bool($val)) {
                            if (is_bool($val)) {
                                $n = $val ? 'true' : 'false';
                            } else {
                                $n = $val;
                            }
                        }
                    }
                }
            }
        }
        if (!$n && $this->isa !== null) {
            $n = '<' . $this->isa . '>';
        }
        if ($this->isRequired()) {
            return sprintf('=%s', $n);
        } else {
            if ($this->isOptional() || $this->defaultValue) {
                return sprintf('[=%s]', $n);
            } else {
                if ($n) {
                    return '=' . $n;
                }
            }
        }
        return '';
    }

Usage Example

Example #1
0
 public function testValueName()
 {
     $opt = new Option('z');
     $opt->defaultValue(10);
     $opt->valueName('priority');
     $this->assertEquals('[=priority]', $opt->renderValueHint());
     $this->assertEquals('-z[=priority]', $opt->renderReadableSpec());
 }
All Usage Examples Of GetOptionKit\Option::renderValueHint