Exemple #1
0
 /**
  * @param \PhpParser\Node\Stmt\ClassMethod $methodNode
  * @return \EBT\ExtensionBuilder\Domain\Model\ClassObject\Method
  */
 public function buildClassMethodObject(\PhpParser\Node\Stmt\ClassMethod $methodNode)
 {
     $methodObject = new Model\ClassObject\Method($methodNode->name);
     $methodObject->setModifiers($methodNode->type);
     $this->addCommentsFromAttributes($methodObject, $methodNode);
     $this->setFunctionProperties($methodNode, $methodObject);
     return $methodObject;
 }
 /**
  * @param \EBT\ExtensionBuilder\Domain\Model\ClassObject\Method $classMethod
  * @return \EBT\ExtensionBuilder\Domain\Model\ClassObject\ClassObject
  */
 public function addMethod($classMethod)
 {
     if (!$this->methodExists($classMethod->getName())) {
         $this->methods[$classMethod->getName()] = $classMethod;
     }
     return $this;
 }
Exemple #3
0
 /**
  * @param \EBT\ExtensionBuilder\Domain\Model\ClassObject\Method $methodObject
  * @return \PhpParser\Node\Stmt\ClassMethod
  */
 public function buildMethodNode(\EBT\ExtensionBuilder\Domain\Model\ClassObject\Method $methodObject)
 {
     $factory = new \PhpParser\BuilderFactory();
     $methodNodeBuilder = $factory->method($methodObject->getName());
     $parameters = $methodObject->getParameters();
     if (count($parameters) > 0) {
         foreach ($parameters as $parameter) {
             $parameterNode = $this->buildParameterNode($parameter);
             $methodNodeBuilder->addParam($parameterNode);
         }
     }
     $methodNodeBuilder->addStmts($methodObject->getBodyStmts());
     $methodNode = $methodNodeBuilder->getNode();
     $methodNode->type = $methodObject->getModifiers();
     $methodNode->setAttribute('startLine', $methodObject->getStartLine());
     $methodNode->setAttribute('endLine', $methodObject->getEndLine());
     $methodObject->updateParamTags();
     $this->addCommentAttributes($methodObject, $methodNode);
     return $methodNode;
 }
Exemple #4
0
 /**
  * @param \EBT\ExtensionBuilder\Domain\Model\ClassObject\Method $method
  * @param array $replacements
  * @return void
  */
 protected function updateMethodBody($method, $replacements)
 {
     $stmts = $method->getBodyStmts();
     $stmts = current($this->parserService->replaceNodeProperty(array($stmts), $replacements, null, 'name'));
     $stmts = current($this->parserService->replaceNodeProperty(array($stmts), $replacements, null, 'value'));
     $method->setBodyStmts($stmts);
 }