/** * @return NodeCollection */ public function getOptionalParameters() { return $this->parameters->children(Filter::isInstanceOf('\\Pharborist\\ParameterNode'))->filter(function (ParameterNode $parameter) { $value = $parameter->getValue(); return isset($value); }); }
/** * Insert argument before argument at index. * * @param LexicalVariableNode $variable * The lexical variable to insert. * @param int $index * Position to insert argument at. * @throws \OutOfBoundsException * Index out of bounds. * * @return $this */ public function insertLexicalVariable(LexicalVariableNode $variable, $index) { if ($index < 0) { throw new \OutOfBoundsException('index out of bounds'); } if (!$this->hasLexicalVariables() && $index !== 0) { throw new \OutOfBoundsException('index out of bounds'); } $this->createLexicalVariables(); $this->lexicalVariables->insertItem($variable, $index); }
/** * @param string|\Pharborist\Namespaces\NameNode $extends * @return $this */ public function setExtends($extends) { if ($extends === NULL) { if (isset($this->extends)) { // Remove whitespace after extends keyword. $this->extends->previous()->remove(); // Remove extends keyword. $this->extends->previous()->remove(); // Remove whitespace before extends keyword. $this->extends->previous()->remove(); // Remove extends namespace. $this->extends->remove(); $this->extends = NULL; } } else { if (!is_array($extends)) { $extends = [$extends]; } $extendsList = new CommaListNode(); foreach ($extends as $extend) { if (is_string($extend)) { $extendsList->appendItem(NameNode::create($extend)); } elseif ($extend instanceof NameNode) { $extendsList->appendItem($extend); } else { throw new \InvalidArgumentException('Invalid $extends argument'); } } $extends = $extendsList; if (isset($this->extends)) { $this->extends->replaceWith($extends); } else { $this->name->after([Token::space(), Token::_extends(), Token::space(), $extends]); } $this->extends = $extends; } return $this; }
/** * Get the values of the array. * * @param boolean $recursive * (optional) TRUE to get values of array elements that are also arrays. * * @return NodeCollection */ public function getValues($recursive = TRUE) { $values = new NodeCollection(); foreach ($this->elements->getItems() as $element) { if ($element instanceof ArrayPairNode) { $value = $element->getValue(); if ($recursive && $value instanceof ArrayNode) { $values->add($value->getValues($recursive)); } else { $values->add($value); } } else { $values->add($element); } } return $values; }
/** * @return NodeCollection|StaticVariableNode[] */ public function getVariables() { return $this->variables->getItems(); }
/** * @return NodeCollection|ConstantDeclarationNode[] */ public function getDeclarations() { return $this->declarations->getItems(); }
public function endCommaListNode(CommaListNode $node) { if ($node->isEmpty()) { return; } $keep_wrap = $this->config['list_keep_wrap']; $wrap_if_long = $this->config['list_wrap_if_long']; if ($node->parent() instanceof ArrayNode) { $keep_wrap = TRUE; $wrap_if_long = TRUE; } $wrap_list = FALSE; if ($keep_wrap) { $wrap_list = $this->nodeData[$node]; unset($this->nodeData[$node]); } if (!$wrap_list && $wrap_if_long) { $column_position = $this->calculateColumnPosition($node); $column_position += strlen($node->getText()); $soft_limit = $this->config['soft_limit']; $wrap_list = $column_position > $soft_limit; } if ($wrap_list) { $this->newlineBefore($node); foreach ($node->children(Filter::isTokenType(',')) as $comma_node) { $this->newlineAfter($comma_node); } $this->newlineAfter($node, TRUE); } }
/** * @return NodeCollection|DeclareDirectiveNode[] */ public function getDirectives() { return $this->directives->getItems(); }
/** * @param string|NameNode|CommaListNode|array|NULL $implements * @throws \InvalidArgumentException * @return $this */ public function setImplements($implements) { if ($implements === NULL) { if (isset($this->implements)) { // Remove whitespace after implements keyword. $this->implements->previous()->remove(); // Remove implements keyword $this->implements->previous()->remove(); // Remove whitespace before implements keyword. $this->implements->previous()->remove(); // Remove implements list. $this->implements->remove(); $this->implements = NULL; } } else { // Type conversions. if (is_string($implements)) { $implements = NameNode::create($implements); } if ($implements instanceof NameNode) { $implementList = new CommaListNode(); $implementList->append($implements); $implements = $implementList; } if (is_array($implements)) { $implementList = new CommaListNode(); foreach ($implements as $implement) { if (is_string($implement)) { $implementList->appendItem(NameNode::create($implement)); } elseif ($implement instanceof NameNode) { $implementList->appendItem($implement); } else { throw new \InvalidArgumentException('Invalid $implements argument'); } } $implements = $implementList; } // Set implements. if (isset($this->implements)) { $this->implements->replaceWith($implements); } else { $after = isset($this->extends) ? $this->extends : $this->name; $after->after([Token::space(), Token::_implements(), Token::space(), $implements]); } $this->implements = $implements; } return $this; }
/** * @return NodeCollection|NameNode[] */ public function getTraitNames() { return $this->traitNames->getItems(); }
/** * @return NodeCollection|ClassMemberNode[] */ public function getMembers() { return $this->members->getItems(); }