isDefaultValueAvailable() public method

Note this is distinct from "isOptional" because you can have a default value, but the parameter not be optional. In the example, the $foo parameter isOptional() == false, but isDefaultValueAvailable == true
Exemplo n.º 1
0
 /**
  * Factory depuis une reflection
  *
  * @param ReflectionParameter $reflection
  * @return static
  */
 public static function fromReflection(ReflectionParameter $reflection)
 {
     // VALUE
     $value = $reflection->isDefaultValueAvailable() ? $reflection->getDefaultValue() : Maker::NO_VALUE;
     // TYPE
     $type = $reflection->getTypeHint();
     // analyse du type
     if (!is_null($type)) {
         if ($type instanceof Object_) {
             $type = strval($type->getFqsen());
         } elseif ($type instanceof Array_) {
             $type = 'array';
         } else {
             exc('Impossible de determiner le type du paramètre : ' . $reflection->getName());
         }
     }
     // construction
     $parameter = new static($reflection->getName(), $value, $type);
     return $parameter;
 }
Exemplo n.º 2
0
 public function formatParameter(ReflectionMethod $method, ReflectionParameter $parameter)
 {
     $code = '$' . $parameter->getName();
     $text = '';
     if ($parameter->isDefaultValueAvailable()) {
         if ($parameter->isDefaultValueConstant()) {
             $code .= ' = ' . $parameter->getDefaultValueConstantName();
         }
         $code .= ' = ' . $parameter->getDefaultValueAsString();
     }
     if ($parameter->isPassedByReference()) {
         $code = '&' . $code;
     }
     $doc = $this->getMethodDocBlock($method);
     $paramTags = $doc->getTagsByName('param');
     $type = 'mixed';
     /** @var \phpDocumentor\Reflection\DocBlock\Tag\ParamTag $paramTag */
     foreach ($paramTags as $paramTag) {
         if ($paramTag->getVariableName() === '$' . $parameter->getName() && $paramTag->getDescription() !== '') {
             $text .= ' — ' . $paramTag->getDescription();
             $type = $paramTag->getType();
         }
     }
     return sprintf('%d. `%s` — `%s` %s', $parameter->getPosition() + 1, $code, $type, $text);
 }
 /**
  * {@inheritDoc}
  */
 public function isDefaultValueAvailable()
 {
     return $this->betterReflectionParameter->isDefaultValueAvailable();
 }