예제 #1
0
 public function testFixtureWithoutPhpInternals()
 {
     $code = file_get_contents(realpath(dirname(__FILE__) . '/Fixture.php'));
     $result = $this->constantGuesser->scan($code, array('PHP_EOF'));
     // var_dump($result);
     $this->assertEquals(2, count($result));
 }
예제 #2
0
 /**
  * @param string $path
  * @param int $showPhpInternalConstants
  * @param array $ignoredConstants
  * @return View
  */
 public function execute($path, $showPhpInternalConstants, array $ignoredConstants, array $ignoredPaths)
 {
     try {
         if (empty($path)) {
             throw new Exception('no path specified');
         }
         $files = array();
         $Directory = new \RecursiveDirectoryIterator($path);
         $Iterator = new \RecursiveIteratorIterator($Directory);
         $Regex = new \RegexIterator($Iterator, '/^.+(\\.php|\\.phtml)$/i', \RecursiveRegexIterator::GET_MATCH);
         foreach ($Regex as $something) {
             $files[] = $something[0];
         }
         $constantGuesser = new ConstantGuesser();
         $filesWithConstants = array();
         if ($showPhpInternalConstants === true) {
             $ignoredConstants = array_merge($ignoredConstants, array_keys(get_defined_constants()));
         }
         foreach ($files as $file) {
             foreach ($ignoredPaths as $ignoredPath) {
                 if (strstr($file, $ignoredPath)) {
                     continue 2;
                 }
             }
             $code = file_get_contents($file);
             $constants = $constantGuesser->scan($code, $ignoredConstants);
             if (!empty($constants)) {
                 $fileWithConstants = new File();
                 $fileWithConstants->setPath($file);
                 $fileWithConstants->setConstants($constants);
                 $filesWithConstants[] = $fileWithConstants;
             }
         }
         $view = $this->createConsoleView();
         $view->setFiles($filesWithConstants);
     } catch (Exception $e) {
         $view = $this->createErrorView();
         $view->setExcpetion($e);
     }
     return $view;
 }