Пример #1
0
 /**
  * Builds a new self reference instance.
  *
  * @param PHP_Depend_Code_AbstractClassOrInterface $type The type instance
  *        that reference the concrete target of self.
  *
  * @return PHP_Depend_Code_ASTSelfReference
  * @since 0.9.6
  */
 public function buildASTSelfReference(PHP_Depend_Code_AbstractClassOrInterface $type)
 {
     include_once 'PHP/Depend/Code/ASTSelfReference.php';
     PHP_Depend_Util_Log::debug('Creating: PHP_Depend_Code_ASTSelfReference(' . $type->getName() . ')');
     return new PHP_Depend_Code_ASTSelfReference($type);
 }
Пример #2
0
 /**
  * Generic visit method for classes and interfaces.
  *
  * @param PHP_Depend_Code_AbstractClassOrInterface $type The context type.
  *
  * @return void
  */
 private function _visitType(PHP_Depend_Code_AbstractClassOrInterface $type)
 {
     $type->getSourceFile()->accept($this);
     $fileXml = end($this->_xmlStack);
     $document = $fileXml->ownerDocument;
     $classXml = $document->createElement('class');
     $classXml->setAttribute('name', $type->getName());
     $this->_appendMetrics($classXml, $type);
     $fileXml->appendChild($classXml);
     array_push($this->_xmlStack, $classXml);
     foreach ($type->getMethods() as $method) {
         $method->accept($this);
     }
     // Update file element @classes count
     $fileXml->setAttribute('classes', 1 + $fileXml->getAttribute('classes'));
     // Remove xml class element
     array_pop($this->_xmlStack);
     // Remove xml file element
     array_pop($this->_xmlStack);
 }
Пример #3
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;
 }
Пример #4
0
 /**
  * Builds a new self reference instance.
  *
  * @param PHP_Depend_Code_AbstractClassOrInterface $type The type instance
  *        that reference the concrete target of self.
  *
  * @return PHP_Depend_Code_ASTSelfReference
  * @since 0.9.6
  */
 public function buildASTSelfReference(PHP_Depend_Code_AbstractClassOrInterface $type)
 {
     PHP_Depend_Util_Log::debug('Creating: PHP_Depend_Code_ASTSelfReference(' . $type->getName() . ')');
     return new PHP_Depend_Code_ASTSelfReference($this->context, $type);
 }
Пример #5
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;
 }
 /**
  * Constructs a new exception instance.
  *
  * @param PHP_Depend_Code_AbstractClassOrInterface $type The class or
  *        interface that is part of the endless inheritance hierarchy.
  */
 public function __construct(PHP_Depend_Code_AbstractClassOrInterface $type)
 {
     parent::__construct(sprintf('Type %s\\%s is part of an endless inheritance hierarchy.', preg_replace('(\\W+)', '\\', $type->getPackage()->getName()), $type->getName()));
 }