Esempio n. 1
0
 /**
  * testParserHandlesMaxNestingLevel
  * 
  * @return void
  * @covers PHP_Depend_Parser
  * @group pdepend
  * @group pdepend::parser
  * @group unittest
  */
 public function testParserHandlesMaxNestingLevel()
 {
     if (version_compare(phpversion(), '5.2.10') < 0) {
         $this->markTestSkipped();
     }
     ini_set('xdebug.max_nesting_level', '100');
     $builder = new PHP_Depend_Builder_Default();
     $tokenizer = new PHP_Depend_Tokenizer_Internal();
     $tokenizer->setSourceFile(self::createCodeResourceURI('parser/' . __FUNCTION__ . '.php'));
     $parser = new PHP_Depend_Parser($tokenizer, $builder);
     $parser->setMaxNestingLevel(512);
     $parser->parse();
 }
Esempio n. 2
0
File: 030.php Progetto: kingsj/core
 /**
  * Tests that the parser ignores backtick expressions. 
  * 
  * http://bugs.xplib.de/index.php?do=details&task_id=15&project=3
  *
  * @return void
  */
 public function testParserBacktickExpressionBug15()
 {
     $sourceFile = dirname(__FILE__) . '/_code/bugs/15.php';
     $tokenizer = new PHP_Depend_Tokenizer_Internal($sourceFile);
     $builder = new PHP_Depend_Builder_Default();
     $parser = new PHP_Depend_Parser($tokenizer, $builder);
     $parser->parse();
     $package = $builder->getPackages()->current();
     $classes = $package->getClasses();
     $this->assertEquals(1, $classes->count());
     $methods = $classes->current()->getMethods();
     $this->assertEquals(1, $methods->count());
 }
Esempio 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)
 {
     include_once 'PHP/Depend/Parser.php';
     include_once 'PHP/Depend/Builder/Default.php';
     include_once 'PHP/Depend/Code/Filter/Collection.php';
     include_once 'PHP/Depend/Tokenizer/Internal.php';
     include_once 'PHP/Depend/Input/ExcludePathFilter.php';
     include_once 'PHP/Depend/Input/Iterator.php';
     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);
     $builder = new PHP_Depend_Builder_Default();
     foreach ($files as $file) {
         $tokenizer = new PHP_Depend_Tokenizer_Internal();
         $tokenizer->setSourceFile($file);
         $parser = new PHP_Depend_Parser($tokenizer, $builder);
         if ($ignoreAnnotations === true) {
             $parser->setIgnoreAnnotations();
         }
         $parser->parse();
     }
     return $builder->getPackages();
 }
 /**
  * Implements some quirks and hacks to support php here- and now-doc for
  * PHP 5.2.x versions :/
  *
  * @return PHP_Depend_Code_ASTHeredoc
  * @since 1.0.0
  */
 protected function parseHeredoc()
 {
     $heredoc = parent::parseHeredoc();
     if (version_compare(phpversion(), "5.3.0alpha") >= 0) {
         return $heredoc;
     }
     // Consume dangling semicolon
     $this->tokenizer->next();
     $token = $this->tokenizer->next();
     preg_match('(/\\*(\'|")\\*/)', $token->image, $match);
     return $heredoc;
 }
Esempio n. 5
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);
     }
     include_once 'PHP/Depend/Parser.php';
     include_once 'PHP/Depend/Builder/Default.php';
     include_once 'PHP/Depend/Tokenizer/Internal.php';
     $tokenizer = new PHP_Depend_Tokenizer_Internal();
     $tokenizer->setSourceFile($sourceFile);
     $builder = new PHP_Depend_Builder_Default();
     $parser = new PHP_Depend_Parser($tokenizer, $builder);
     $parser->parse();
     return $builder->getPackages()->current();
 }
Esempio n. 6
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_CacheDecorator(new PHP_Depend_Tokenizer_Internal());
     $this->fireStartParseProcess($this->_builder);
     foreach ($this->_createFileIterator() as $file) {
         $tokenizer->setSourceFile($file);
         $parser = new PHP_Depend_Parser($tokenizer, $this->_builder);
         $parser->setMaxNestingLevel(1024);
         // 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);
 }