Phan\CLI::progress PHP Method

progress() public static method

Update a progress bar on the screen
public static progress ( string $msg, float $p ) : null
$msg string A short message to display with the progress meter
$p float The percentage to display
return null
    public static function progress(string $msg, float $p)
    {
        // Bound the percentage to [0, 1]
        $p = min(max($p, 0.0), 1.0);
        if (!Config::get()->progress_bar || Config::get()->dump_ast) {
            return;
        }
        // Don't update every time when we're moving
        // super fast
        if ($p < 1.0 && rand(0, 1000) > 1000 * Config::get()->progress_bar_sample_rate) {
            return;
        }
        // If we're on windows, just print a dot to show we're
        // working
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
            fwrite(STDERR, '.');
            return;
        }
        $memory = memory_get_usage() / 1024 / 1024;
        $peak = memory_get_peak_usage() / 1024 / 1024;
        $padded_message = str_pad($msg, 10, ' ', STR_PAD_LEFT);
        fwrite(STDERR, "{$padded_message} ");
        $current = (int) ($p * 60);
        $rest = max(60 - $current, 0);
        fwrite(STDERR, str_repeat("█", $current));
        fwrite(STDERR, str_repeat("░", $rest));
        fwrite(STDERR, " " . sprintf("% 3d", (int) (100 * $p)) . "%");
        fwrite(STDERR, sprintf(' %0.2dMB/%0.2dMB', $memory, $peak) . "\r");
    }

Usage Example

コード例 #1
0
 /**
  * @param CodeBase $code_base
  * @param Map|array $element_list
  * @param string $issue_type
  * @param int $total_count
  * @param int $i
  *
  * @return void
  */
 private static function analyzeElementListReferenceCounts(CodeBase $code_base, $element_list, string $issue_type, int $total_count, int &$i)
 {
     foreach ($element_list as $element) {
         CLI::progress('dead code', ++$i / $total_count);
         self::analyzeElementReferenceCounts($code_base, $element, $issue_type);
     }
 }
All Usage Examples Of Phan\CLI::progress