FunctionLike.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace PhpParser\Builder;
  3. use PhpParser;
  4. use PhpParser\Node;
  5. use PhpParser\Node\Stmt;
  6. abstract class FunctionLike extends Declaration
  7. {
  8. protected $returnByRef = false;
  9. protected $params = array();
  10. /**
  11. * Make the function return by reference.
  12. *
  13. * @return $this The builder instance (for fluid interface)
  14. */
  15. public function makeReturnByRef() {
  16. $this->returnByRef = true;
  17. return $this;
  18. }
  19. /**
  20. * Adds a parameter.
  21. *
  22. * @param Node\Param|Param $param The parameter to add
  23. *
  24. * @return $this The builder instance (for fluid interface)
  25. */
  26. public function addParam($param) {
  27. $param = $this->normalizeNode($param);
  28. if (!$param instanceof Node\Param) {
  29. throw new \LogicException(sprintf('Expected parameter node, got "%s"', $param->getType()));
  30. }
  31. $this->params[] = $param;
  32. return $this;
  33. }
  34. /**
  35. * Adds multiple parameters.
  36. *
  37. * @param array $params The parameters to add
  38. *
  39. * @return $this The builder instance (for fluid interface)
  40. */
  41. public function addParams(array $params) {
  42. foreach ($params as $param) {
  43. $this->addParam($param);
  44. }
  45. return $this;
  46. }
  47. }