getName() public method

Get the name of the parameter.
public getName ( ) : string
return string
Ejemplo n.º 1
0
 /**
  * @return string
  */
 public function getDescription()
 {
     $docBlock = new DocBlock($this->reflectionParameter->getDeclaringFunction()->getDocComment());
     /** @var \phpDocumentor\Reflection\DocBlock\Tag\ParamTag[] $paramTags */
     $paramTags = $docBlock->getTagsByName('param');
     foreach ($paramTags as $paramTag) {
         if ($paramTag->getVariableName() === '$' . $this->reflectionParameter->getName()) {
             $lines = Multiline::create($paramTag->getDescription());
             $lines->apply('ltrim');
             return (string) $lines;
         }
     }
     return '';
 }
Ejemplo n.º 2
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;
 }
 private function assertSameParameterAttributes(\ReflectionParameter $original, ReflectionParameter $stubbed)
 {
     $this->assertSame($original->getName(), $stubbed->getName());
     $this->assertSame($original->isArray(), $stubbed->isArray());
     $this->assertSame($original->isCallable(), $stubbed->isCallable());
     //$this->assertSame($original->allowsNull(), $stubbed->allowsNull()); @TODO WTF?
     $this->assertSame($original->canBePassedByValue(), $stubbed->canBePassedByValue());
     $this->assertSame($original->isOptional(), $stubbed->isOptional());
     $this->assertSame($original->isPassedByReference(), $stubbed->isPassedByReference());
     $this->assertSame($original->isVariadic(), $stubbed->isVariadic());
     if ($class = $original->getClass()) {
         $stubbedClass = $stubbed->getClass();
         $this->assertInstanceOf(ReflectionClass::class, $stubbedClass);
         $this->assertSame($class->getName(), $stubbedClass->getName());
     } else {
         $this->assertNull($stubbed->getClass());
     }
 }
Ejemplo n.º 4
0
 public function name() : string
 {
     return $this->reflection->getName();
 }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
0
 function it_has_a_name(ReflectionParameter $parameter)
 {
     $parameter->getName()->willReturn('id');
     $this->name()->shouldBe('id');
 }
 /**
  * {@inheritDoc}
  */
 public function getName()
 {
     return $this->betterReflectionParameter->getName();
 }