/**
  * testAcceptsCallsNestedFilterWhenSet
  *
  * @return void
  */
 public function testAcceptsCallsNestedFilterWhenSet()
 {
     $class = new ASTClass(__CLASS__);
     $filter = $this->getMock('\\PDepend\\Source\\AST\\ASTArtifactList\\ArtifactFilter');
     $filter->expects($this->once())->method('accept')->with($this->equalTo($class));
     $collection = new CollectionArtifactFilter();
     $collection->setFilter($filter);
     $collection->accept($class);
 }
 /**
  * Tests that the analyzer calculates the correct average hierarchy height.
  *
  * @return void
  */
 public function testAnalyzerCalculatesCorrectAHHValue()
 {
     $filter = CollectionArtifactFilter::getInstance();
     $filter->setFilter(new PackageArtifactFilter(array('library')));
     $namespaces = self::parseTestCaseSource(__METHOD__);
     $analyzer = $this->createAnalyzer();
     $analyzer->analyze($namespaces);
     $project = $analyzer->getProjectMetrics();
     $this->assertEquals(1, $project['ahh']);
 }
 /**
  * Constructs a new node iterator from the given {@link \PDepend\Source\AST\ASTArtifact}
  * node array.
  *
  * @param \PDepend\Source\AST\ASTArtifact[] $artifacts
  */
 public function __construct(array $artifacts)
 {
     $filter = CollectionArtifactFilter::getInstance();
     $nodeKeys = array();
     foreach ($artifacts as $artifact) {
         $id = $artifact->getId();
         if (isset($nodeKeys[$id])) {
             continue;
         }
         if ($filter->accept($artifact)) {
             $nodeKeys[$id] = $id;
             $this->artifacts[] = $artifact;
             ++$this->count;
         }
     }
 }
 /**
  * testGetParentReturnsNullWhenParentIsFiltered
  *
  * @return void
  * @since 1.0.0
  */
 public function testGetParentReturnsNullWhenParentIsFiltered()
 {
     CollectionArtifactFilter::getInstance()->setFilter(new PackageArtifactFilter(array('org.pdepend.filter')));
     $class = $this->getFirstClassForTestCase();
     $this->assertNull($class->getParentClass());
 }
Example #5
0
 /**
  * This method performs the analysing process of the parsed source files. It
  * creates the required analyzers for the registered listeners and then
  * applies them to the source tree.
  *
  * @return void
  */
 private function performAnalyzeProcess()
 {
     $analyzerLoader = $this->createAnalyzers($this->options);
     $collection = CollectionArtifactFilter::getInstance();
     $this->fireStartAnalyzeProcess();
     ini_set('xdebug.max_nesting_level', $this->configuration->parser->nesting);
     foreach ($analyzerLoader as $analyzer) {
         // Add filters if this analyzer is filter aware
         if ($analyzer instanceof AnalyzerFilterAware) {
             $collection->setFilter($this->codeFilter);
         }
         $analyzer->analyze($this->builder->getNamespaces());
         // Remove filters if this analyzer is filter aware
         $collection->setFilter();
         foreach ($this->generators as $logger) {
             $logger->log($analyzer);
         }
     }
     ini_restore('xdebug.max_nesting_level');
     $this->fireEndAnalyzeProcess();
 }
 /**
  * Returns the parent class or <b>null</b> if this class has no parent.
  *
  * @return \PDepend\Source\AST\ASTClass
  * @throws \PDepend\Source\AST\ASTClassOrInterfaceRecursiveInheritanceException
  */
 public function getParentClass()
 {
     // No parent? Stop here!
     if ($this->parentClassReference === null) {
         return null;
     }
     $parentClass = $this->parentClassReference->getType();
     if ($parentClass === $this) {
         throw new ASTClassOrInterfaceRecursiveInheritanceException($this);
     }
     // Check parent against global filter
     $collection = CollectionArtifactFilter::getInstance();
     if ($collection->accept($parentClass) === false) {
         return null;
     }
     return $parentClass;
 }
 /**
  * Resets the global iterator filter.
  *
  * @return void
  */
 protected function tearDown()
 {
     CollectionArtifactFilter::getInstance()->setFilter();
     $this->clearRunResources();
     $this->resetWorkingDirectory();
     parent::tearDown();
 }