Skip to content
Permalink
Browse files

Pass success flag to progress

  • Loading branch information...
iluuu1994 authored and muglug committed May 25, 2019
1 parent 63b46be commit 5e8acf0b0e5595a24868c45f551686538e004ee9
@@ -221,20 +221,22 @@ public function analyzeFiles(ProjectAnalyzer $project_analyzer, $pool_size, $alt
* @param int $_
* @param string $file_path
*
* @return void
* @return array
*/
function ($_, $file_path) use ($project_analyzer, $filetype_analyzers) {
$file_analyzer = $this->getFileAnalyzer($project_analyzer, $file_path, $filetype_analyzers);
$this->progress->debug('Analyzing ' . $file_analyzer->getFilePath() . "\n");
$file_analyzer->analyze(null);
return $this->getFileIssues($file_path);
};
$this->progress->start(count($this->files_to_analyze));
$task_done_closure = function (): void {
$this->progress->taskDone(true);
$task_done_closure = function (array $issues): void {
$this->progress->taskDone(count($issues) === 0);
};
if ($pool_size > 1 && count($this->files_to_analyze) > $pool_size) {
@@ -380,7 +382,9 @@ function () {
foreach ($this->files_to_analyze as $file_path => $_) {
$analysis_worker($i, $file_path);
++$i;
$task_done_closure();
$issues = $this->getFileIssues($file_path);
$task_done_closure($issues);
}
foreach (IssueBuffer::getIssuesData() as $issue_data) {
@@ -417,6 +421,13 @@ function () {
}
}
private function getFileIssues(string $file_path): array
{
return array_filter(IssueBuffer::getIssuesData(), function (array $issue) use ($file_path): bool {
return $issue['file_path'] === $file_path;
});
}
/**
* @return void
*/
@@ -3,4 +3,14 @@
class ForkTaskDoneMessage implements ForkMessage
{
/** @var mixed */
public $data;
/**
* @param mixed $data
*/
public function __construct($data)
{
$this->data = $data;
}
}
@@ -38,7 +38,7 @@ class Pool
* This closure must return an array (to be gathered).
* @param \Closure $shutdown_closure
* A closure to execute upon shutting down a child
* @param ?\Closure(): void $task_done_closure
* @param ?\Closure(mixed $data): void $task_done_closure
* A closure to execute when a task is done
*
* @psalm-suppress MixedAssignment
@@ -130,8 +130,8 @@ public function __construct(
// Get the work for this process
$task_data_iterator = array_values($process_task_data_iterator)[$proc_id];
foreach ($task_data_iterator as $i => $task_data) {
$task_closure($i, $task_data);
$task_done_message = new ForkTaskDoneMessage();
$task_result = $task_closure($i, $task_data);
$task_done_message = new ForkTaskDoneMessage($task_result);
fwrite($write_stream, base64_encode(serialize($task_done_message)) . PHP_EOL);
}
@@ -249,7 +249,7 @@ private function readResultsFromChildren()
$terminationMessages[] = $message->data;
} elseif ($message instanceof ForkTaskDoneMessage) {
if ($this->task_done_closure !== null) {
($this->task_done_closure)();
($this->task_done_closure)($message->data);
}
} else {
error_log('Child should return ForkMessage - response type=' . gettype($message));

0 comments on commit 5e8acf0

Please sign in to comment.
You can’t perform that action at this time.