/**
  * @param \PhpParser\Node $node
  * @return \PhpParser\Node|void
  */
 public function leaveNode(\PhpParser\Node $node)
 {
     if (null !== $node->__get('class')) {
         $oldClassName = \EBT\ExtensionBuilder\Parser\Utility\NodeConverter::getValueFromNode($node->__get('class'));
         if (strpos($oldClassName, $this->oldClassPrefix) !== false) {
             $newClassName = str_replace($this->oldClassPrefix, $this->newClassPrefix, $oldClassName);
             $node->setClass(\EBT\ExtensionBuilder\Parser\NodeFactory::buildNodeFromName($newClassName));
             return $node;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * getModifierNames
  *
  * @return array
  */
 public function getModifierNames()
 {
     $modifiers = $this->getModifiers();
     return \EBT\ExtensionBuilder\Parser\Utility\NodeConverter::modifierToNames($modifiers);
 }
Ejemplo n.º 3
0
 /**
  * @param \PhpParser\Node\Stmt $node
  * @param \EBT\ExtensionBuilder\Domain\Model\FunctionObject $object
  * @return \EBT\ExtensionBuilder\Domain\Model\AbstractObject
  */
 protected function setFunctionProperties(\PhpParser\Node\Stmt $node, Model\FunctionObject $object)
 {
     if (property_exists($node, 'type')) {
         $object->setModifiers($node->type);
     }
     $object->setBodyStmts($node->stmts);
     $position = 0;
     $object->setStartLine($node->getAttribute('startLine'));
     $object->setEndLine($node->getAttribute('endLine'));
     $getVarTypeFromParamTag = false;
     $paramTags = array();
     if ($object->isTaggedWith('param') && is_array($object->getTagValues('param'))) {
         $paramTags = $object->getTagValues('param');
         if (count($paramTags) == count($node->params)) {
             $getVarTypeFromParamTag = true;
         }
     }
     /** @var $param \PhpParser\NodeAbstract */
     foreach ($node->params as $param) {
         $parameter = new Model\ClassObject\MethodParameter($param->name);
         $parameter->setPosition($position);
         $parameter->setStartLine($param->getAttribute('startLine'));
         $parameter->setEndLine($param->getAttribute('endLine'));
         if (!is_null($param->type)) {
             $parameter->setTypeHint(NodeConverter::getValueFromNode($param->type));
             if (!$getVarTypeFromParamTag) {
                 $parameter->setVarType(NodeConverter::getValueFromNode($param->type));
             }
         } elseif ($getVarTypeFromParamTag) {
             // if there is not type hint but a varType in the param tag,
             // we set the varType of the parameter
             $paramTag = explode(' ', $paramTags[$position]);
             if ($paramTag[0] !== '$' . $param->name) {
                 $parameter->setVarType($paramTag[0]);
                 $parameter->setTypeForParamTag($paramTag[0]);
             }
         }
         if (!is_null($param->default)) {
             $parameter->setDefaultValue($param->default);
         }
         $object->setParameter($parameter);
         $position++;
     }
     $object->updateParamTags();
     return $object;
 }
Ejemplo n.º 4
0
 /**
  * @param \PhpParser\Node $node
  */
 public function leaveNode(\PhpParser\Node $node)
 {
     array_pop($this->contextStack);
     if ($this->isContainerNode(end($this->contextStack)) || count($this->contextStack) === 0) {
         // we are on the first level
         if ($node instanceof Node\Stmt\Class_) {
             if (count($this->contextStack) > 0) {
                 if (end($this->contextStack)->getType() == 'Stmt_Namespace') {
                     $currentNamespaceName = NodeConverter::getValueFromNode(end($this->contextStack));
                     $this->currentClassObject->setNamespaceName($currentNamespaceName);
                     $this->currentNamespace->addClass($this->currentClassObject);
                 }
             } else {
                 $this->fileObject->addClass($this->currentClassObject);
                 $this->currentClassObject = null;
                 $this->currentContainer = $this->fileObject;
             }
         } elseif ($node instanceof Node\Stmt\Namespace_) {
             if (null !== $this->currentNamespace) {
                 $this->fileObject->addNamespace($this->currentNamespace);
                 $this->currentNamespace = null;
                 $this->currentContainer = $this->fileObject;
             } else {
                 //TODO: find how this could happen
             }
         } elseif ($node instanceof Node\Stmt\TraitUse) {
             if ($this->currentClassObject) {
                 $this->currentClassObject->addUseTraitStatement($node);
             }
         } elseif ($node instanceof Node\Stmt\Use_) {
             $this->currentContainer->addAliasDeclaration(NodeConverter::convertUseAliasStatementNodeToArray($node));
         } elseif ($node instanceof Node\Stmt\ClassConst) {
             $constants = NodeConverter::convertClassConstantNodeToArray($node);
             foreach ($constants as $constant) {
                 $this->currentContainer->setConstant($constant['name'], $constant['value']);
             }
         } elseif ($node instanceof Node\Stmt\ClassMethod) {
             $this->onFirstLevel = true;
             $method = $this->classFactory->buildClassMethodObject($node);
             $this->currentClassObject->addMethod($method);
         } elseif ($node instanceof Node\Stmt\Property) {
             $property = $this->classFactory->buildPropertyObject($node);
             $this->currentClassObject->addProperty($property);
         } elseif ($node instanceof Node\Stmt\Function_) {
             $this->onFirstLevel = true;
             $function = $this->classFactory->buildFunctionObject($node);
             $this->currentContainer->addFunction($function);
         } elseif (!$node instanceof Node\Name) {
             // any other nodes (except the name node of the current container node)
             // go into statements container
             if ($this->currentContainer->getFirstClass() === false) {
                 $this->currentContainer->addPreClassStatements($node);
             } else {
                 $this->currentContainer->addPostClassStatements($node);
             }
         }
     }
 }