Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * This method parses a {@link \PDepend\Source\AST\ASTParentReference} node.
  *
  * @param  \PDepend\Source\Tokenizer\Token $token The "self" keyword token.
  * @return \PDepend\Source\AST\ASTNode
  * @throws \PDepend\Source\Parser\ParserException
  * @throws \PDepend\Source\Parser\InvalidStateException
  * @since  0.9.6
  */
 private function parseParentReference(Token $token)
 {
     if ($this->classOrInterface === null) {
         throw new InvalidStateException($token->startLine, (string) $this->compilationUnit, 'The keyword "parent" was used as type hint but the parameter ' . 'declaration is not in a class scope.');
     }
     if ($this->classOrInterface instanceof ASTTrait) {
         $classReference = $this->builder->buildAstClassReference('__PDepend_TraitRuntimeReference');
     } else {
         $classReference = $this->classOrInterface->getParentClassReference();
     }
     if ($classReference === null) {
         throw new InvalidStateException($token->startLine, (string) $this->compilationUnit, 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;
 }
 /**
  * Generic visit method for classes and interfaces. Both visit methods
  * delegate calls to this method.
  *
  * @param \PDepend\Source\AST\AbstractASTClassOrInterface $type
  * @return void
  */
 protected function visitType(AbstractASTClassOrInterface $type)
 {
     $id = $type->getNamespace()->getId();
     // Increment total classes count
     ++$this->nodeMetrics[$id][self::M_NUMBER_OF_CLASSES];
     // Check for abstract or concrete class
     if ($type->isAbstract()) {
         ++$this->nodeMetrics[$id][self::M_NUMBER_OF_ABSTRACT_CLASSES];
     } else {
         ++$this->nodeMetrics[$id][self::M_NUMBER_OF_CONCRETE_CLASSES];
     }
     foreach ($type->getDependencies() as $dependency) {
         $this->collectDependencies($type->getNamespace(), $dependency->getNamespace());
     }
     foreach ($type->getMethods() as $method) {
         $method->accept($this);
     }
 }
Exemplo n.º 4
0
 /**
  * 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);
 }
Exemplo n.º 5
0
 /**
  * Builds a new self reference instance.
  *
  * @param  \PDepend\Source\AST\AbstractASTClassOrInterface $type
  * @return \PDepend\Source\AST\ASTSelfReference
  * @since  0.9.6
  */
 public function buildAstSelfReference(AbstractASTClassOrInterface $type)
 {
     Log::debug('Creating: \\PDepend\\Source\\AST\\ASTSelfReference(' . $type->getName() . ')');
     return new \PDepend\Source\AST\ASTSelfReference($this->context, $type);
 }
 /**
  * Generic visitor method for classes and interfaces. Both visit methods
  * delegate calls to this method.
  *
  * @param \PDepend\Source\AST\AbstractASTClassOrInterface $type
  * @return void
  */
 protected function visitType(AbstractASTClassOrInterface $type)
 {
     $namespace = $type->getNamespace();
     $this->initNode($namespace);
     $this->initNode($type);
     foreach ($type->getDependencies() as $dependency) {
         $depPkg = $dependency->getNamespace();
         $this->initNode($dependency);
         $this->initNode($depPkg);
         $this->nodes[$type->getId()]['in'][] = $dependency->getId();
         $this->nodes[$dependency->getId()]['out'][] = $type->getId();
         // No self references
         if ($namespace !== $depPkg) {
             $this->nodes[$namespace->getId()]['in'][] = $depPkg->getId();
             $this->nodes[$depPkg->getId()]['out'][] = $namespace->getId();
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Generates the XML for a class or trait node.
  *
  * @param  \PDepend\Source\AST\ASTClass $type
  * @param  string                       $typeIdentifier
  * @return void
  */
 private function generateTypeXml(AbstractASTClassOrInterface $type, $typeIdentifier)
 {
     if (!$type->isUserDefined()) {
         return;
     }
     $xml = end($this->xmlStack);
     $doc = $xml->ownerDocument;
     $typeXml = $doc->createElement($typeIdentifier);
     $typeXml->setAttribute('name', Utf8Util::ensureEncoding($type->getName()));
     $xml->appendChild($typeXml);
     array_push($this->xmlStack, $typeXml);
     $this->writeNodeDependencies($typeXml, $type);
     $this->writeFileReference($typeXml, $type->getCompilationUnit());
     array_pop($this->xmlStack);
 }
Exemplo n.º 8
0
 /**
  * Initializes the node metric record for the given <b>$type</b>.
  *
  * @param \PDepend\Source\AST\AbstractASTClassOrInterface $type
  * @return void
  */
 protected function initTypeMetric(AbstractASTClassOrInterface $type)
 {
     $id = $type->getId();
     if (!isset($this->nodeMetrics[$id])) {
         $this->nodeSet[$id] = $type;
         $this->nodeMetrics[$id] = array(self::M_AFFERENT_COUPLING => array(), self::M_EFFERENT_COUPLING => array());
     }
 }