コード例 #1
0
 /**
  * Tests that the factory throws the expected exception for an invalid
  * strategy identifier.
  *
  * @return void
  */
 public function testFactoryMethodThrowsExceptionForInvalidStrategyIdentifier()
 {
     $factory = new StrategyFactory();
     $this->setExpectedException('InvalidArgumentException', 'Cannot load file for identifier "foo_bar_baz".');
     $factory->createStrategy('foo_bar_baz');
 }
コード例 #2
0
 /**
  * Processes all {@link \PDepend\Source\AST\ASTNamespace} code nodes.
  *
  * @param  \PDepend\Source\AST\ASTNamespace[] $namespaces
  * @return void
  */
 public function analyze($namespaces)
 {
     if ($this->nodeMetrics === null) {
         $this->fireStartAnalyzer();
         $factory = new StrategyFactory();
         if (isset($this->options[self::STRATEGY_OPTION])) {
             foreach ($this->options[self::STRATEGY_OPTION] as $identifier) {
                 $this->strategies[] = $factory->createStrategy($identifier);
             }
         } else {
             $this->strategies[] = $factory->createDefaultStrategy();
         }
         // Register all listeners
         foreach ($this->getVisitListeners() as $listener) {
             foreach ($this->strategies as $strategy) {
                 $strategy->addVisitListener($listener);
             }
         }
         foreach ($namespaces as $namespace) {
             // Traverse all strategies
             foreach ($this->strategies as $strategy) {
                 $namespace->accept($strategy);
             }
         }
         // Collect all nodes
         foreach ($this->strategies as $strategy) {
             $collected = $strategy->getCollectedNodes();
             $this->nodes = array_merge_recursive($collected, $this->nodes);
         }
         // Init node metrics
         $this->nodeMetrics = array();
         // Calculate code rank metrics
         $this->buildCodeRankMetrics();
         $this->fireEndAnalyzer();
     }
 }