Exemplo n.º 1
0
 /**
  * This method parses a {@link PHP_Depend_Code_ASTParentReference} node.
  *
  * @param PHP_Depend_Token $token The "self" keyword token.
  *
  * @return PHP_Depend_Code_ASTNode
  * @throws PHP_Depend_Parser_Exception When an error occured during the
  *         parsing process.
  * @throws PHP_Depend_Parser_InvalidStateException When the keyword parent
  *         was used outside of a class or interface scope.
  * @since 0.9.6
  */
 private function _parseParentReference(PHP_Depend_Token $token)
 {
     if ($this->_classOrInterface === null) {
         throw new PHP_Depend_Parser_InvalidStateException($token->startLine, (string) $this->_sourceFile, 'The keyword "parent" was used as type hint but the parameter ' . 'declaration is not in a class scope.');
     }
     $classReference = $this->_classOrInterface->getParentClassReference();
     if ($classReference === null) {
         throw new PHP_Depend_Parser_InvalidStateException($token->startLine, (string) $this->_sourceFile, sprintf('The keyword "parent" was used as type hint but the ' . 'class "%s" does not declare a parent.', $this->_classOrInterface->getName()));
     }
     $ref = $this->builder->buildASTParentReference($classReference);
     $ref->configureLinesAndColumns($token->startLine, $token->endLine, $token->startColumn, $token->endColumn);
     return $ref;
 }
Exemplo n.º 2
0
 /**
  * This method will parse a formal parameter that has the keyword parent as
  * parameter type hint.
  *
  * <code>
  * class Foo extends Bar
  * {
  *     //                   ---------
  *     public function test(parent $o) {}
  *     //                   ---------
  * }
  * </code>
  *
  * @return PHP_Depend_Code_ASTFormalParameter
  * @throws PHP_Depend_Parser_InvalidStateException When this type hint is
  *         used outside the scope of a class. When this type hint is used
  *         for a class that has no parent.
  * @since 0.9.6
  */
 private function _parseFormalParameterAndParentTypeHint()
 {
     $token = $this->_consumeToken(self::T_PARENT);
     if ($this->_classOrInterface === null) {
         throw new PHP_Depend_Parser_InvalidStateException($token->startLine, (string) $this->_sourceFile, 'The keyword "parent" was used as type hint but the parameter ' . 'declaration is not in a class scope.');
     }
     $classReference = $this->_classOrInterface->getParentClassReference();
     if ($classReference === null) {
         throw new PHP_Depend_Parser_InvalidStateException($token->startLine, (string) $this->_sourceFile, sprintf('The keyword "parent" was used as type hint but the parent ' . 'class "%s" does not declare a parent.', $this->_classOrInterface->getName()));
     }
     $classReference = clone $classReference;
     $classReference->configureLinesAndColumns($token->startLine, $token->endLine, $token->startColumn, $token->endColumn);
     $parameter = $this->_parseFormalParameterOrByReference();
     $parameter->addChild($classReference);
     return $parameter;
 }