コード例 #1
0
ファイル: Command.php プロジェクト: natmchugh/horse
 public function main($arguments, $excludes, $suffixes)
 {
     $this->printVersionString();
     $files = $this->findFiles($arguments, $excludes, $suffixes);
     if (empty($files)) {
         $this->showError("No files found to scan.\n");
     }
     $analyser = new PHPLOC_Analyser($verbose);
     $count = $analyser->countFiles($files, $countTests);
     $printer = new PHPLOC_TextUI_ResultPrinter_Text();
     $printer->printResult($count, $countTests);
     $logCsv = implode('_', $arguments) . '.csv';
     $printer = new PHPLOC_TextUI_ResultPrinter_CSV();
     $printer->printResult($logCsv, $count);
 }
コード例 #2
0
ファイル: ParallelAnalyser.php プロジェクト: natmchugh/phploc
 public function countFiles(array $files, $countTests)
 {
     $chunkSize = ceil(count($files) / $this->_cores);
     $chunks = array_chunk($files, $chunkSize);
     $forks = array();
     $sockets = array();
     for ($i = 0; $i < $this->_cores; $i++) {
         if (socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $sockets) === false) {
             echo "socket_create_pair failed. Reason: " . socket_strerror(socket_last_error());
         }
         $this->socketPairs[] = $sockets;
         $forks[] = $pid = pcntl_fork();
         if ($pid === 0) {
             parent::countFiles($chunks[$i], $countTests);
             $data = array('count' => $this->count, 'namespaces' => $this->namespaces);
             $dataString = serialize($data);
             socket_set_nonblock($sockets[0]);
             if (socket_write($sockets[0], str_pad($dataString, self::MESSAGE_LENGTH), self::MESSAGE_LENGTH) === false) {
                 throw new Exception("socket_write() failed. Reason: " . socket_strerror(socket_last_error($sockets[0])));
             }
             socket_close($sockets[0]);
             die;
         }
     }
     do {
         pcntl_wait($status);
         array_pop($forks);
     } while (count($forks) > 0);
     for ($i = 0; $i < $this->_cores; $i++) {
         $sockets = $this->socketPairs[$i];
         $childMessage = '';
         $childMessage = socket_read($sockets[1], self::MESSAGE_LENGTH);
         $data = unserialize(trim($childMessage));
         socket_close($sockets[1]);
         $this->mergeAndSumCount($data['count']);
         $this->mergeNamespaces($data['namespaces']);
         // $this->mergeDirectories($data['directories']);
     }
     // need to find some way to pass the number of directories from the child to the paent so
     // we don't have to do this again
     // same with namespaces which are also a object variable
     $count = $this->getCount($countTests);
     foreach ($files as $file) {
         $directory = dirname($file);
         if (!isset($directories[$directory])) {
             $directories[$directory] = TRUE;
         }
     }
     $count['directories'] = count($directories) - 1;
     return $count;
 }
コード例 #3
0
ファイル: Command.php プロジェクト: natmchugh/phploc
 /**
  * Main method.
  */
 public function main()
 {
     $input = new ezcConsoleInput();
     $output = new ezcConsoleOutput();
     $input->registerOption(new ezcConsoleOption('', 'count-tests', ezcConsoleInput::TYPE_NONE, FALSE, FALSE));
     $input->registerOption(new ezcConsoleOption('', 'exclude', ezcConsoleInput::TYPE_STRING, array(), TRUE));
     $input->registerOption(new ezcConsoleOption('h', 'help', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE));
     $input->registerOption(new ezcConsoleOption('', 'log-xml', ezcConsoleInput::TYPE_STRING));
     $input->registerOption(new ezcConsoleOption('', 'log-csv', ezcConsoleInput::TYPE_STRING));
     $input->registerOption(new ezcConsoleOption('', 'cores', ezcConsoleInput::TYPE_STRING, 1));
     $input->registerOption(new ezcConsoleOption('', 'suffixes', ezcConsoleInput::TYPE_STRING, 'php', FALSE));
     $input->registerOption(new ezcConsoleOption('v', 'version', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE));
     $input->registerOption(new ezcConsoleOption('', 'verbose', ezcConsoleInput::TYPE_NONE));
     try {
         $input->process();
     } catch (ezcConsoleOptionException $e) {
         print $e->getMessage() . "\n";
         exit(1);
     }
     if ($input->getOption('help')->value) {
         $this->showHelp();
         exit(0);
     } else {
         if ($input->getOption('version')->value) {
             $this->printVersionString();
             exit(0);
         }
     }
     $arguments = $input->getArguments();
     if (empty($arguments)) {
         $this->showHelp();
         exit(1);
     }
     $countTests = $input->getOption('count-tests')->value;
     $excludes = $input->getOption('exclude')->value;
     $logXml = $input->getOption('log-xml')->value;
     $logCsv = $input->getOption('log-csv')->value;
     $cores = $input->getOption('cores')->value;
     $suffixes = array_map('trim', explode(',', $input->getOption('suffixes')->value));
     if ($input->getOption('verbose')->value !== FALSE) {
         $verbose = $output;
     } else {
         $verbose = NULL;
     }
     $this->printVersionString();
     $files = $this->findFiles($arguments, $excludes, $suffixes);
     if (empty($files)) {
         $this->showError("No files found to scan.\n");
     }
     $analyser = new PHPLOC_Analyser($verbose);
     if ($cores > 1 && extension_loaded('pcntl') && extension_loaded('sockets')) {
         $parallelAnalyser = new PHPLOC_ParallelAnalyser($cores);
         $count = $parallelAnalyser->countFiles($files, $countTests);
     } else {
         $count = $analyser->countFiles($files, $countTests);
     }
     $printer = new PHPLOC_TextUI_ResultPrinter_Text();
     $printer->printResult($count, $countTests);
     if ($logXml) {
         $printer = new PHPLOC_TextUI_ResultPrinter_XML();
         $printer->printResult($logXml, $count);
     }
     if ($logCsv) {
         $printer = new PHPLOC_TextUI_ResultPrinter_CSV();
         $printer->printResult($logCsv, $count);
     }
 }