Exemplo n.º 1
0
 /**
  * This method performs the parsing process of all source files. It expects
  * that the <b>$_builder</b> property was initialized with a concrete builder
  * implementation.
  *
  * @return void
  */
 private function performParseProcess()
 {
     // Reset list of thrown exceptions
     $this->parseExceptions = array();
     $tokenizer = new PHP_Depend_Tokenizer_Internal();
     $this->fireStartParseProcess($this->builder);
     foreach ($this->createFileIterator() as $file) {
         $tokenizer->setSourceFile($file);
         $parser = new PHP_Depend_Parser_VersionAllParser($tokenizer, $this->builder, $this->cacheFactory->create());
         $parser->setMaxNestingLevel($this->configuration->parser->nesting);
         // Disable annotation parsing?
         if ($this->withoutAnnotations === true) {
             $parser->setIgnoreAnnotations();
         }
         $this->fireStartFileParsing($tokenizer);
         try {
             $parser->parse();
         } catch (PHP_Depend_Parser_Exception $e) {
             $this->parseExceptions[] = $e;
         }
         $this->fireEndFileParsing($tokenizer);
     }
     $this->fireEndParseProcess($this->builder);
 }
Exemplo n.º 2
0
 /**
  * Parses the given test file and then returns the builder instance.
  *
  * @param string $file Relative path to a test file for the calling test.
  *
  * @return PHP_Depend_Builder_Default
  */
 protected function parseSourceAndReturnBuilder($file)
 {
     copy(self::createCodeResourceUriForTest() . '/' . $file, $this->testFile);
     $cache = new PHP_Depend_Util_Cache_Driver_File($this->cacheDir);
     $tokenizer = new PHP_Depend_Tokenizer_Internal();
     $tokenizer->setSourceFile($this->testFile);
     $builder = new PHP_Depend_Builder_Default();
     $builder->setCache($cache);
     $parser = new PHP_Depend_Parser_VersionAllParser($tokenizer, $builder, $cache);
     $parser->parse();
     return $builder;
 }
Exemplo n.º 3
0
 /**
  * Parses the given source file or directory with the default tokenizer
  * and node builder implementations.
  *
  * @param string  $fileOrDirectory   A source file or a source directory.
  * @param boolean $ignoreAnnotations The parser should ignore annotations.
  *
  * @return PHP_Depend_Code_NodeIterator
  */
 public static function parseSource($fileOrDirectory, $ignoreAnnotations = false)
 {
     if (file_exists($fileOrDirectory) === false) {
         $fileOrDirectory = self::createCodeResourceURI($fileOrDirectory);
     }
     if (is_dir($fileOrDirectory)) {
         $it = new PHP_Depend_Input_Iterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fileOrDirectory)), new PHP_Depend_Input_ExcludePathFilter(array('.svn')));
     } else {
         $it = new ArrayIterator(array($fileOrDirectory));
     }
     $files = array();
     foreach ($it as $file) {
         if (is_object($file)) {
             $files[] = realpath($file->getPathname());
         } else {
             $files[] = $file;
         }
     }
     sort($files);
     $cache = new PHP_Depend_Util_Cache_Driver_Memory();
     $builder = new PHP_Depend_Builder_Default();
     foreach ($files as $file) {
         $tokenizer = new PHP_Depend_Tokenizer_Internal();
         $tokenizer->setSourceFile($file);
         $parser = new PHP_Depend_Parser_VersionAllParser($tokenizer, $builder, $cache);
         if ($ignoreAnnotations === true) {
             $parser->setIgnoreAnnotations();
         }
         $parser->parse();
     }
     return $builder->getPackages();
 }
Exemplo n.º 4
0
 /**
  * Parses the source of the given file and returns the first package found
  * in that file.
  *
  * @param string $sourceFile Name of the test source file.
  *
  * @return PHP_Depend_Code_Package
  */
 private function parseSource($sourceFile)
 {
     if (file_exists($sourceFile) === false) {
         throw new ErrorException('Cannot locate source file: ' . $sourceFile);
     }
     $tokenizer = new PHP_Depend_Tokenizer_Internal();
     $tokenizer->setSourceFile($sourceFile);
     $builder = new PHP_Depend_Builder_Default();
     $parser = new PHP_Depend_Parser_VersionAllParser($tokenizer, $builder, new PHP_Depend_Util_Cache_Driver_Memory());
     $parser->parse();
     return $builder->getPackages()->current();
 }
Exemplo n.º 5
0
 /**
  * testParserStopsProcessingWhenCacheContainsValidResult
  *
  * @return void
  * @covers PHP_Depend_Parser
  * @group pdepend
  * @group pdepend::parser
  * @group unittest
  */
 public function testParserStopsProcessingWhenCacheContainsValidResult()
 {
     $builder = $this->getMock('PHP_Depend_BuilderI');
     $tokenizer = new PHP_Depend_Tokenizer_Internal();
     $tokenizer->setSourceFile(__FILE__);
     $cache = $this->getMock('PHP_Depend_Util_Cache_Driver');
     $cache->expects($this->once())->method('restore')->will(self::returnValue(true));
     $cache->expects($this->never())->method('store');
     $parser = new PHP_Depend_Parser_VersionAllParser($tokenizer, $builder, $cache);
     $parser->parse();
 }