Пример #1
0
 /**
  * @return string
  */
 public function getDocComment()
 {
     if (!$this->node->hasAttribute('comments')) {
         return '';
     }
     /* @var \PhpParser\Comment\Doc $comment */
     $comment = $this->node->getAttribute('comments')[0];
     return $comment->getReformattedText();
 }
Пример #2
0
 /**
  * Given a property, attempt to find the type of the property
  *
  * @param PropertyNode $node
  * @param ReflectionProperty $reflectionProperty
  * @return Type[]
  */
 public function __invoke(PropertyNode $node, ReflectionProperty $reflectionProperty)
 {
     $contextFactory = new ContextFactory();
     $context = $contextFactory->createForNamespace($reflectionProperty->getDeclaringClass()->getNamespaceName(), $reflectionProperty->getDeclaringClass()->getLocatedSource()->getSource());
     /* @var \PhpParser\Comment\Doc $comment */
     if (!$node->hasAttribute('comments')) {
         return [];
     }
     $comment = $node->getAttribute('comments')[0];
     $docBlock = new DocBlock($comment->getReformattedText(), new DocBlock\Context($context->getNamespace(), $context->getNamespaceAliases()));
     /* @var \phpDocumentor\Reflection\DocBlock\Tag\VarTag $varTag */
     $resolvedTypes = [];
     $varTags = $docBlock->getTagsByName('var');
     foreach ($varTags as $varTag) {
         $resolvedTypes = array_merge($resolvedTypes, (new ResolveTypes())->__invoke($varTag->getTypes(), $context));
     }
     return $resolvedTypes;
 }
 public function addProperty(PropertyNode $node)
 {
     foreach ($node->props as $prop) {
         $property = new ReflectionProperty($prop->name);
         $property->setStartLine((int) $node->getAttribute('startLine'));
         $property->setEndLine((int) $node->getAttribute('endLine'));
         $property->setDocComment((string) $node->getDocComment());
         $property->setStatic((bool) $node->isStatic());
         if (!is_null($prop->default)) {
             $value = $this->resolveValue($prop->default);
             $property->setDefault(strtolower(gettype($value)), $value);
         }
         if ($node->isPrivate()) {
             $property->setVisibility(ReflectionProperty::IS_PRIVATE);
         } elseif ($node->isProtected()) {
             $property->setVisibility(ReflectionProperty::IS_PROTECTED);
         } else {
             $property->setVisibility(ReflectionProperty::IS_PUBLIC);
         }
         $this->context->getReflection()->addProperty($property);
     }
 }