Inheritance: extends PhpParser\Node\Stmt
 function importVarType(Property $prop)
 {
     $prop->getDocComment();
     $comment = $prop->getDocComment();
     if ($comment) {
         $str = $comment->getText();
         if (count($prop->props) >= 1) {
             try {
                 $docBlock = $this->factory->create($str, $this->getDocBlockContext());
                 /** @var Var_[] $types */
                 $types = $docBlock->getTagsByName("var");
                 if (count($types) > 0) {
                     $type = strval($types[0]->getType());
                     if (!empty($type)) {
                         if ($type[0] == '\\') {
                             $type = substr($type, 1);
                         }
                         $prop->props[0]->setAttribute("namespacedType", strval($type));
                     }
                 }
             } catch (\InvalidArgumentException $e) {
                 // Skip it.
             }
         }
     }
 }
Ejemplo n.º 2
0
 private function enterProperty(Property $node)
 {
     if ($node->isPrivate()) {
         foreach ($node->props as $property) {
             $this->privateAttributes[$property->name] = $node;
         }
     }
 }
 public function visitProperty(Property $node)
 {
     $prop = $node->props[0];
     $p = new PhpProperty($prop->name);
     $p->setStatic($node->isStatic());
     $p->setVisibility($this->getVisibility($node));
     $this->parseValue($p, $prop);
     $this->parseMemberDocblock($p, $node->getDocComment());
     $this->struct->setProperty($p);
 }
Ejemplo n.º 4
0
 /**
  * @param Stmt\Property $node
  *
  * @return string
  */
 public function convert(Stmt\Property $node)
 {
     foreach ($node->props as $key => $prop) {
         $prop->name = $this->reservedWordReplacer->replace($prop->name);
         $node->props[$key] = $prop;
     }
     if ($node->props[0]->default instanceof Expr\Array_ && $node->isStatic() === true) {
         $node->type = $node->type - Stmt\Class_::MODIFIER_STATIC;
         $this->dispatcher->moveToNonStaticVar($node->props[0]->name);
         $this->logger->logNode("Static attribute default array not supported in zephir, (see #188). Changed into non static. ", $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
     }
     return $this->dispatcher->pModifiers($node->type) . $this->dispatcher->pCommaSeparated($node->props) . ';';
 }
Ejemplo n.º 5
0
 /**
  * @param \ReflectionProperty $accessedProperty
  * @param string              $nameSuffix
  */
 public function __construct(\ReflectionProperty $accessedProperty, $nameSuffix)
 {
     $this->accessedProperty = $accessedProperty;
     $originalName = $accessedProperty->getName();
     $name = UniqueIdentifierGenerator::getIdentifier($originalName . $nameSuffix);
     parent::__construct(Class_::MODIFIER_PRIVATE, [new PropertyProperty($name)]);
 }
Ejemplo n.º 6
0
 /**
  * @param PropertyNode $node
  * @param ReflectionClass $declaringClass
  * @return ReflectionProperty
  */
 public static function createFromNode(PropertyNode $node, ReflectionClass $declaringClass)
 {
     $prop = new self();
     $prop->name = $node->props[0]->name;
     $prop->declaringClass = $declaringClass;
     if ($node->isPrivate()) {
         $prop->visibility = self::IS_PRIVATE;
     } elseif ($node->isProtected()) {
         $prop->visibility = self::IS_PROTECTED;
     } else {
         $prop->visibility = self::IS_PUBLIC;
     }
     $prop->isStatic = $node->isStatic();
     $prop->docBlockTypes = (new FindPropertyType())->__invoke($node, $prop);
     return $prop;
 }
Ejemplo n.º 7
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();
 }
Ejemplo n.º 8
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;
 }
 protected function getProperty(Property $node)
 {
     $prop = $node->props[0];
     $p = new PhpProperty($prop->name);
     $default = $prop->default;
     if ($default !== null) {
         $p->setDefaultValue($this->getValue($default));
     }
     $p->setStatic($node->isStatic());
     $p->setVisibility($this->getVisibility($node));
     $this->parseMemberDocblock($p, $node->getDocComment());
     return $p;
 }
Ejemplo n.º 10
0
 private function processProperty(\PhpParser\Node\Stmt\Property $node) {
     $property = $node->props[0];
     $member = $this->unit->addMember($property->name);
     $this->setVariableType($member, $property->type);
     $this->setVariableDefaultValue($member, $property->default);
     $visibility = 'public';
     if ($node->isPrivate()) {
         $visibility = 'private';
     } elseif ($node->isProtected()) {
         $visibility = 'protected';
     }
     $member->setVisibility($visibility);
     $docComment = $node->getDocComment();
     if ($docComment !== NULL) {
         $block = $this->dockblocParser->parse($docComment, $this->aliasMap);
         $member->setDocBlock($block);
     }
     $member->setLine($node->getLine());
 }
Ejemplo n.º 11
0
 /**
  * @param Property $node
  *
  * @return RefProperty
  */
 private function createProperty(Property $node)
 {
     $ref = new RefProperty();
     $ref->class = $this->class;
     $ref->name = $node->props[0]->name;
     $ref->default = $this->getValue($node->props[0]->default);
     if ($node->isPrivate()) {
         $ref->visibility = Visibility::IS_PRIVATE;
     } elseif ($node->isProtected()) {
         $ref->visibility = Visibility::IS_PROTECTED;
     } elseif ($node->isPublic()) {
         $ref->visibility = Visibility::IS_PUBLIC;
     }
     $ref->isStatic = $node->isStatic();
     $ref->line = $node->getLine();
     $ref->docComment = $this->createDocComment($node);
     return $ref;
 }
 /**
  * {@inheritDoc}
  */
 public function isStatic()
 {
     return $this->propertyTypeNode->isStatic();
 }
 /**
  * @param Node\Stmt\Property $node
  */
 protected function parseClassPropertyNode(Node\Stmt\Property $node)
 {
     foreach ($node->props as $property) {
         $this->structuralElements[$this->currentStructuralElement->namespacedName->toString()]['properties'][] = ['name' => $property->name, 'startLine' => $node->getLine(), 'isPublic' => $node->isPublic(), 'isPrivate' => $node->isPrivate(), 'isStatic' => $node->isStatic(), 'isProtected' => $node->isProtected(), 'docComment' => $node->getDocComment() ? $node->getDocComment()->getText() : null];
     }
 }
Ejemplo n.º 14
0
 /**
  * @return int
  */
 public function getLine()
 {
     return $this->propertyBefore->getLine();
 }
Ejemplo n.º 15
0
 /**
  * @return int
  */
 public function getLine()
 {
     return $this->propertyAfter->getLine();
 }
 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);
     }
 }
Ejemplo n.º 17
0
 protected function addProperty(PropertyNode $node)
 {
     foreach ($node->props as $prop) {
         $property = new PropertyReflection($prop->name, $prop->getLine());
         $property->setModifiers($node->type);
         $property->setDefault($prop->default);
         $comment = $this->context->getDocBlockParser()->parse($node->getDocComment(), $this->context, $property);
         $property->setDocComment($node->getDocComment());
         $property->setShortDesc($comment->getShortDesc());
         $property->setLongDesc($comment->getLongDesc());
         if ($errors = $comment->getErrors()) {
             $property->setErrors($errors);
         } else {
             if ($tag = $comment->getTag('var')) {
                 $property->setHint($this->resolveHint($tag[0][0]));
                 $property->setHintDesc($tag[0][1]);
             }
             $property->setTags($comment->getOtherTags());
         }
         if ($this->context->getFilter()->acceptProperty($property)) {
             $this->context->getClass()->addProperty($property);
             if ($errors) {
                 $this->context->addErrors((string) $property, $prop->getLine(), $errors);
             }
         }
     }
 }