コード例 #1
0
 function scan($scanners = array('checks', 'analyzers'))
 {
     // Run the scan
     $scan_pass = parent::scan($scanners);
     // Get the results
     $results = $this->get_results();
     // Get the previously scanned files
     $scanned_files = $this->get_scanned_files($this->directory);
     $directory = $this->get_normalized_dir_path($this->directory);
     // Save the results
     foreach ($this->files as $file_group_type => $files) {
         foreach ($files as $file => $file_contents) {
             // Get the post id to update
             if (array_key_exists($file, $scanned_files)) {
                 $post_id = $scanned_files[$file]['post_id'];
             } else {
                 // This file does not already have a db entry, insert one
                 $post_id = wp_insert_post(array('post_type' => self::ASYNC_SCAN_CPT, 'post_title' => $file));
                 if (is_wp_error($post_id)) {
                     continue;
                 }
                 update_post_meta($post_id, 'vip_scanner_dir', $directory);
             }
             // Save the scan results for this file
             update_post_meta($post_id, 'vip_scanner_async_results', $results);
             update_post_meta($post_id, 'vip_scanner_async_pass', $scan_pass);
         }
     }
     return $scan_pass;
 }
コード例 #2
0
ファイル: ComposerLintTask.php プロジェクト: Ryu0621/SaNaVi
 protected function findFiles()
 {
     $ds = new DirectoryScanner();
     $ds->setBasedir($this->dir);
     $ds->setIncludes(array('**/composer.json'));
     $ds->scan();
     return $ds->getIncludedFiles();
 }
コード例 #3
0
ファイル: Excludes.php プロジェクト: xxspartan16/BMS-Market
 /**
  * Returns the excluded files
  *
  * @return array
  */
 public function getExcludedFiles()
 {
     $includes = array();
     foreach ($this->files as $file) {
         $includes[] = $file->getName();
     }
     $this->directoryScanner->setIncludes($includes);
     $this->directoryScanner->scan();
     $files = $this->directoryScanner->getIncludedFiles();
     $dir = $this->directoryScanner->getBasedir();
     $fileList = array();
     foreach ($files as $file) {
         $fileList[] = $dir . DIRECTORY_SEPARATOR . $file;
     }
     return $fileList;
 }
コード例 #4
0
 /**
  * Perform checks on a directory
  *
  * [<dir>]
  * : Directory to scan. Defaults to current.
  *
  * [--scan_type=<scan_type>]
  * : Type of scan to perform. Defaults to "WP.org Theme Review"
  *
  * [--summary]
  * : Summarize the results.
  *
  * [--format=<format>]
  * : Output results to a given format: table, JSON, CSV. Defaults to table.
  *
  * @subcommand scan
  */
 public function scan($args, $assoc_args)
 {
     if (empty($args[0])) {
         $dir = getcwd();
     } else {
         $dir = realpath($args[0]);
     }
     $defaults = array('scan_type' => 'VIP Theme Review', 'format' => 'table');
     $args = wp_parse_args($assoc_args, $defaults);
     $review = VIP_Scanner::get_instance()->get_review($args['scan_type']);
     if (!$review) {
         WP_CLI::error(sprintf('Scanning of %s failed', $dir));
     }
     $scanner = new DirectoryScanner($dir, $review);
     $scanner->scan(array('checks', 'analyzers'));
     if (!$scanner) {
         WP_CLI::error(sprintf('Scanning of %s failed', $dir));
     }
     self::scan_dir($scanner, $args);
 }
コード例 #5
0
ファイル: GuzzleSubSplitTask.php プロジェクト: Ryu0621/SaNaVi
 protected function findSplits()
 {
     $this->log("checking heads for subsplits");
     $repo = $this->getRepository();
     $base = $this->getBase();
     $splits = array();
     $heads = $this->getHeads();
     if (!empty($base)) {
         $base = '/' . ltrim($base, '/');
     } else {
         $base = '/';
     }
     chdir($repo . '/.subsplit');
     foreach ($heads as $head) {
         $splits[$head] = array();
         passthru("git checkout '{$head}'");
         $ds = new DirectoryScanner();
         $ds->setBasedir($repo . '/.subsplit' . $base);
         $ds->setIncludes(array('**/' . $this->subIndicatorFile));
         $ds->scan();
         $files = $ds->getIncludedFiles();
         foreach ($files as $file) {
             $pkg = file_get_contents($repo . '/.subsplit' . $base . '/' . $file);
             $pkg_json = json_decode($pkg, true);
             $name = $pkg_json['name'];
             $component = str_replace('/composer.json', '', $file);
             $tmpreponame = explode('/', $name);
             $reponame = $tmpreponame[1];
             $splits[$head][$component]['repo'] = $reponame;
             $nscomponent = str_replace('/', '\\', $component);
             $splits[$head][$component]['desc'] = "[READ ONLY] Subtree split of {$nscomponent}: " . $pkg_json['description'];
         }
     }
     passthru("git checkout master");
     chdir($repo);
     $this->splits = $splits;
 }
コード例 #6
0
 private function makeEntityNames($dirnames, PhingFile $rootDir)
 {
     if (empty($dirnames)) {
         return;
     }
     foreach ($dirnames as $dirname) {
         $this->output .= "<!-- dir: {$dirname} -->\n";
         $ds = new DirectoryScanner();
         $ds->setIncludes(array("**/*.xml"));
         $futil = new FileUtils();
         $baseDir = $futil->resolveFile($rootDir, $dirname);
         $ds->setBasedir($baseDir->getPath());
         $ds->scan();
         $xmlFiles = $ds->getIncludedFiles();
         $allEntities = '';
         foreach ($xmlFiles as $xmlFilename) {
             $xmlFile = $futil->resolveFile($baseDir, $xmlFilename);
             $entityName = $this->fileToEntity($xmlFile, $rootDir);
             $this->output .= "<!-- {$dirname}/{$xmlFilename}-->\n";
             $this->output .= "<!ENTITY {$entityName} SYSTEM \"{$dirname}/{$xmlFilename}\">\n";
             $allEntities .= "&{$entityName};";
         }
         $this->output .= "<!-- {$dirname} -->\n";
         $this->output .= "<!ENTITY {$dirname}.all \"{$allEntities}\">\n";
     }
 }
コード例 #7
0
 public function findComponents()
 {
     $ds = new DirectoryScanner();
     $ds->setBasedir((string) $this->basedir . '/.subsplit/src');
     $ds->setIncludes(array('**/composer.json'));
     $ds->scan();
     $files = $ds->getIncludedFiles();
     $this->subpackages = $files;
 }
コード例 #8
0
 /**
  * Inspired by http://www.phing.info/trac/ticket/137
  */
 public function testMultipleExcludes()
 {
     $this->executeTarget("multiple-setup");
     $ds = new DirectoryScanner();
     $ds->setBasedir($this->_basedir . "/echo");
     $ds->setIncludes(array("**"));
     $ds->setExcludes(array("**/.gitignore", ".svn/", ".git/", "cache/", "build.xml", "a/a.xml"));
     $ds->scan();
     $this->compareFiles($ds, array("b/b.xml"), array("", "a", "b"));
 }
コード例 #9
0
ファイル: class-wp-cli.php プロジェクト: Zackio/vip-scanner
 /**
  * Perform analysis on a directory
  *
  * [<dir>]
  * : Directory to scan. Defaults to current.
  *
  * [--scan_type=<scan_type>]
  * : Type of scan to perform. Defaults to "WP.org Theme Review"
  *
  * [--depth=<depth>]
  * : Number of levels of hierarchy to output. 0 outputs everything.
  * Defaults to 1.
  * @subcommand analyze
  */
 public function analyze($args, $assoc_args)
 {
     if (empty($args[0])) {
         $dir = getcwd();
     } else {
         $dir = realpath($args[0]);
     }
     $defaults = array('scan_type' => 'VIP Theme Review', 'depth' => 1);
     $args = wp_parse_args($assoc_args, $defaults);
     $scanner = VIP_Scanner::get_instance()->get_review($args['scan_type'], array('analyzers'));
     if (!$scanner) {
         WP_CLI::error(sprintf('Scanning of %s failed', $args['theme']));
     }
     $scanner = new DirectoryScanner($dir, $scanner);
     $scanner->scan(array('analyzers'));
     $errors = $scanner->get_errors();
     if (!empty($errors)) {
         self::display_errors($scanner, 'table');
     }
     $empty = array();
     $display_args = array('bare' => true, 'depth' => intval($args['depth']));
     foreach ($scanner->elements as $element) {
         // Display empty elements after the others
         if ($element->is_empty()) {
             $empty[] = $element;
             continue;
         }
         if ($element->name() !== 'Files') {
             $element->analyze_prefixes();
         }
         $r = new ElementRenderer($element);
         WP_CLI::line($r->display(false, $display_args));
     }
     foreach ($empty as $element) {
         $r = new ElementRenderer($element);
         $r->display(true, $display_args);
     }
 }