예제 #1
0
파일: LocalFile.php 프로젝트: thekabal/tki
 /**
  * Processes the file.
  *
  * @return void
  */
 public function process()
 {
     if ($this->ignored === true) {
         return;
     }
     if ($this->configCache['cache'] === false) {
         return parent::process();
     }
     $hash = md5_file($this->path);
     $cache = Cache::get($this->path);
     if ($cache !== false && $cache['hash'] === $hash) {
         // We can't filter metrics, so just load all of them.
         $this->metrics = $cache['metrics'];
         if ($this->configCache['recordErrors'] === true) {
             // Replay the cached errors and warnings to filter out the ones
             // we don't need for this specific run.
             $this->configCache['cache'] = false;
             $this->replayErrors($cache['errors'], $cache['warnings']);
             $this->configCache['cache'] = true;
         } else {
             $this->errorCount = $cache['errorCount'];
             $this->warningCount = $cache['warningCount'];
             $this->fixableCount = $cache['fixableCount'];
         }
         if (PHP_CODESNIFFER_VERBOSITY > 0 || PHP_CODESNIFFER_CBF === true && empty($this->config->files) === false) {
             echo "[loaded from cache]... ";
         }
         $this->numTokens = $cache['numTokens'];
         $this->fromCache = true;
         return;
     }
     //end if
     if (PHP_CODESNIFFER_VERBOSITY > 1) {
         echo PHP_EOL;
     }
     parent::process();
     $cache = array('hash' => $hash, 'errors' => $this->errors, 'warnings' => $this->warnings, 'metrics' => $this->metrics, 'errorCount' => $this->errorCount, 'warningCount' => $this->warningCount, 'fixableCount' => $this->fixableCount, 'numTokens' => $this->numTokens);
     Cache::set($this->path, $cache);
     // During caching, we don't filter out errors in any way, so
     // we need to do that manually now by replaying them.
     if ($this->configCache['recordErrors'] === true) {
         $this->configCache['cache'] = false;
         $this->replayErrors($this->errors, $this->warnings);
         $this->configCache['cache'] = true;
     }
 }
예제 #2
0
파일: Runner.php 프로젝트: thekabal/tki
 /**
  * Waits for child processes to complete and cleans up after them.
  *
  * The reporting information returned by each child process is merged
  * into the main reporter class.
  *
  * @param array $childProcs An array of child processes to wait for.
  *
  * @return void
  */
 private function processChildProcs($childProcs)
 {
     $numProcessed = 0;
     $totalBatches = count($childProcs);
     while (count($childProcs) > 0) {
         foreach ($childProcs as $key => $procData) {
             $res = pcntl_waitpid($procData['pid'], $status, WNOHANG);
             if ($res === $procData['pid']) {
                 if (file_exists($procData['out']) === true) {
                     include $procData['out'];
                     if (isset($childOutput) === true) {
                         $this->reporter->totalFiles += $childOutput['totalFiles'];
                         $this->reporter->totalErrors += $childOutput['totalErrors'];
                         $this->reporter->totalWarnings += $childOutput['totalWarnings'];
                         $this->reporter->totalFixable += $childOutput['totalFixable'];
                         $this->reporter->totalFixed += $childOutput['totalFixed'];
                     }
                     if (isset($debugOutput) === true) {
                         echo $debugOutput;
                     }
                     if (isset($childCache) === true) {
                         foreach ($childCache as $path => $cache) {
                             Cache::set($path, $cache);
                         }
                     }
                     unlink($procData['out']);
                     unset($childProcs[$key]);
                     $numProcessed++;
                     // Fake a processed file so we can print progress output for the batch.
                     $file = new DummyFile(null, $this->ruleset, $this->config);
                     $file->setErrorCounts($childOutput['totalErrors'], $childOutput['totalWarnings'], $childOutput['totalFixable'], $childOutput['totalFixed']);
                     $this->printProgress($file, $totalBatches, $numProcessed);
                 }
                 //end if
             }
             //end if
         }
         //end foreach
     }
     //end while
 }