/** * Returns the source file where this method was declared. * * @return PHP_Depend_Code_File * @throws PHP_Depend_Code_Exceptions_SourceNotFoundException When no parent * class or interface was set for this method instance. * @since 0.10.0 */ public function getSourceFile() { if ($this->parent === null) { throw new PHP_Depend_Code_Exceptions_SourceNotFoundException($this); } return $this->parent->getSourceFile(); }
/** * The magic wakeup method will be called by PHP's runtime environment when * a serialized instance of this class was unserialized. This implementation * of the wakeup method will register this object in the the global class * context. * * @return void * @since 0.10.0 */ public function __wakeup() { parent::__wakeup(); $this->context->registerClass($this); }
/** * 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); }
/** * 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); }
/** * Generic visitor method for classes and interfaces. Both visit methods * delegate calls to this method. * * @param PHP_Depend_Code_AbstractClassOrInterface $type The context type * instance. * * @return void */ protected function visitType(PHP_Depend_Code_AbstractClassOrInterface $type) { $pkg = $type->getPackage(); $this->initNode($pkg); $this->initNode($type); foreach ($type->getDependencies() as $dep) { $depPkg = $dep->getPackage(); $this->initNode($dep); $this->initNode($depPkg); $this->nodes[$type->getUuid()]['in'][] = $dep->getUuid(); $this->nodes[$dep->getUuid()]['out'][] = $type->getUuid(); // No self references if ($pkg !== $depPkg) { $this->nodes[$pkg->getUuid()]['in'][] = $depPkg->getUuid(); $this->nodes[$depPkg->getUuid()]['out'][] = $pkg->getUuid(); } } }
/** * 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; }
/** * 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); }
/** * This method can be called by the PHP_Depend runtime environment or a * utilizing component to free up memory. This methods are required for * PHP version < 5.3 where cyclic references can not be resolved * automatically by PHP's garbage collector. * * @return void * @since 0.9.12 */ public function free() { parent::free(); $this->_removeReferencesToProperties(); }
/** * Generic visit method for classes and interfaces. Both visit methods * delegate calls to this method. * * @param PHP_Depend_Code_AbstractClassOrInterface $type The type instance. * * @return void */ protected function visitType(PHP_Depend_Code_AbstractClassOrInterface $type) { // Get context package uuid $pkgUUID = $type->getPackage()->getUuid(); // Increment total classes count ++$this->nodeMetrics[$pkgUUID][self::M_NUMBER_OF_CLASSES]; // Check for abstract or concrete class if ($type->isAbstract()) { ++$this->nodeMetrics[$pkgUUID][self::M_NUMBER_OF_ABSTRACT_CLASSES]; } else { ++$this->nodeMetrics[$pkgUUID][self::M_NUMBER_OF_CONCRETE_CLASSES]; } foreach ($type->getDependencies() as $dep) { $this->collectDependencies($type->getPackage(), $dep->getPackage()); } foreach ($type->getMethods() as $method) { $method->accept($this); } }
/** * The magic wakeup method will be called by PHP's runtime environment when * a serialized instance of this class was unserialized. This implementation * of the wakeup method will register this object in the the global class * context. * * @return void * @since 0.10.0 */ public function __wakeup() { parent::__wakeup(); $this->context->registerInterface($this); }
/** * 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; }
/** * This method will initialize a temporary coupling container for the given * given class or interface instance. * * @param PHP_Depend_Code_AbstractClassOrInterface $classOrInterface The * currently visited/traversed class or interface instance. * * @return void * @since 0.10.2 */ private function _initClassOrInterfaceDependencyMap(PHP_Depend_Code_AbstractClassOrInterface $classOrInterface) { if (isset($this->_temporaryCouplingMap[$classOrInterface->getUUID()])) { return; } $this->_temporaryCouplingMap[$classOrInterface->getUUID()] = array('ce' => array(), 'ca' => array()); }
/** * 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())); }