Пример #1
0
 /**
  * Builds a new class instance or reuses a previous created class.
  *
  * Where possible you should give a qualified class name, that is prefixed
  * with the package identifier.
  *
  * <code>
  *   $builder->buildClass('php::depend::Parser');
  * </code>
  *
  * To determine the correct class, this method implements the following
  * algorithm.
  *
  * <ol>
  *   <li>Check for an exactly matching instance and reuse it.</li>
  *   <li>Check for a class instance that belongs to the default package. If
  *   such an instance exists, reuse it and replace the default package with
  *   the newly given package information.</li>
  *   <li>Check that the requested class is in the default package, if this
  *   is true, reuse the first class instance and ignore the default package.
  *   </li>
  *   <li>Create a new instance for the specified package.</li>
  * </ol>
  *
  * @param string $name The class name.
  *
  * @return \PDepend\Source\AST\ASTClass The created class object.
  */
 public function buildClass($name)
 {
     $this->checkBuilderState();
     $class = new ASTClass($this->extractTypeName($name));
     $class->setCache($this->cache)->setContext($this->context)->setCompilationUnit($this->defaultCompilationUnit);
     return $class;
 }
 /**
  * Creates an abstract item instance.
  *
  * @return \PDepend\Source\AST\AbstractASTArtifact
  */
 protected function createItem()
 {
     $class = new ASTClass(__CLASS__);
     $class->setCompilationUnit(new ASTCompilationUnit(__FILE__));
     $class->setCache(new MemoryCacheDriver());
     $class->setContext($this->getMock('PDepend\\Source\\Builder\\BuilderContext'));
     return $class;
 }
 /**
  * Creates a ready to use class fixture.
  *
  * @param string $name Optional class name.
  *
  * @return \PDepend\Source\AST\ASTClass
  * @since 1.0.2
  */
 protected function createClassFixture($name = null)
 {
     $name = $name ? $name : get_class($this);
     $class = new ASTClass($name);
     $class->setCompilationUnit(new ASTCompilationUnit($GLOBALS['argv'][0]));
     $class->setCache(new MemoryCacheDriver());
     $class->setContext($this->getMock('PDepend\\Source\\Builder\\BuilderContext'));
     return $class;
 }