formatTime() public static method

public static formatTime ( $secs )
Exemplo n.º 1
0
 private static function initPlaceholderFormatters()
 {
     return array('indicator' => function (ProgressIndicator $indicator) {
         return $indicator->getCurrentValue();
     }, 'message' => function (ProgressIndicator $indicator) {
         return $indicator->getMessage();
     }, 'elapsed' => function (ProgressIndicator $indicator) {
         return Helper::formatTime(time() - $indicator->getStartTime());
     }, 'memory' => function () {
         return Helper::formatMemory(memory_get_usage(true));
     });
 }
Exemplo n.º 2
0
 private static function initPlaceholderFormatters()
 {
     return array('indicator' => function (ProgressIndicator $indicator) {
         return $indicator->indicatorValues[$indicator->indicatorCurrent % count($indicator->indicatorValues)];
     }, 'message' => function (ProgressIndicator $indicator) {
         return $indicator->message;
     }, 'elapsed' => function (ProgressIndicator $indicator) {
         return Helper::formatTime(time() - $indicator->startTime);
     }, 'memory' => function () {
         return Helper::formatMemory(memory_get_usage(true));
     });
 }
Exemplo n.º 3
0
 private static function initPlaceholderFormatters()
 {
     return array('bar' => function (ProgressBar $bar, OutputInterface $output) {
         $completeBars = floor($bar->getMaxSteps() > 0 ? $bar->getProgressPercent() * $bar->getBarWidth() : $bar->getProgress() % $bar->getBarWidth());
         $display = str_repeat($bar->getBarCharacter(), $completeBars);
         if ($completeBars < $bar->getBarWidth()) {
             $emptyBars = $bar->getBarWidth() - $completeBars - Helper::strlenWithoutDecoration($output->getFormatter(), $bar->getProgressCharacter());
             $display .= $bar->getProgressCharacter() . str_repeat($bar->getEmptyBarCharacter(), $emptyBars);
         }
         return $display;
     }, 'elapsed' => function (ProgressBar $bar) {
         return Helper::formatTime(time() - $bar->getStartTime());
     }, 'remaining' => function (ProgressBar $bar) {
         if (!$bar->getMaxSteps()) {
             throw new LogicException('Unable to display the remaining time if the maximum number of steps is not set.');
         }
         if (!$bar->getProgress()) {
             $remaining = 0;
         } else {
             $remaining = round((time() - $bar->getStartTime()) / $bar->getProgress() * ($bar->getMaxSteps() - $bar->getProgress()));
         }
         return Helper::formatTime($remaining);
     }, 'estimated' => function (ProgressBar $bar) {
         if (!$bar->getMaxSteps()) {
             throw new LogicException('Unable to display the estimated time if the maximum number of steps is not set.');
         }
         if (!$bar->getProgress()) {
             $estimated = 0;
         } else {
             $estimated = round((time() - $bar->getStartTime()) / $bar->getProgress() * $bar->getMaxSteps());
         }
         return Helper::formatTime($estimated);
     }, 'memory' => function (ProgressBar $bar) {
         return Helper::formatMemory(memory_get_usage(true));
     }, 'current' => function (ProgressBar $bar) {
         return str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', STR_PAD_LEFT);
     }, 'max' => function (ProgressBar $bar) {
         return $bar->getMaxSteps();
     }, 'percent' => function (ProgressBar $bar) {
         return floor($bar->getProgressPercent() * 100);
     });
 }
Exemplo n.º 4
0
 /**
  * @dataProvider formatTimeProvider
  *
  * @param int    $secs
  * @param string $expectedFormat
  */
 public function testFormatTime($secs, $expectedFormat)
 {
     $this->assertEquals($expectedFormat, Helper::formatTime($secs));
 }
Exemplo n.º 5
0
 /**
  * @return string
  */
 public function getRemaining()
 {
     if (!$this->getMaxSteps()) {
         return '???';
     }
     if (!$this->getProgress()) {
         $remaining = 0;
     } else {
         $remaining = round((time() - $this->getStartTime()) / $this->getProgress() * ($this->getMaxSteps() - $this->getProgress()));
     }
     return Helper::formatTime($remaining);
 }
Exemplo n.º 6
0
 /**
  * Executes the current command.
  *
  * This method is not abstract because you can use this class
  * as a concrete class. In this case, instead of defining the
  * execute() method, you set the code to execute by passing
  * a Closure to the setCode() method.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @throws LogicException When this abstract method is not implemented
  *
  * @return null|int null or 0 if everything went fine, or an error code
  *
  * @see setCode()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $startTime = microtime(true);
     $startMemUsage = memory_get_usage(true);
     $output->writeln($this->getApplication()->getLongVersion() . " by overtrue and contributors.\n");
     $options = $this->mergeOptions();
     $verbosity = $output->getVerbosity();
     if ($verbosity >= OutputInterface::VERBOSITY_DEBUG) {
         $output->writeln('Options: ' . json_encode($options));
     }
     $linter = new Linter($options['path'], $options['exclude'], $options['extensions']);
     $linter->setProcessLimit($options['jobs']);
     if (!$input->getOption('no-cache') && Cache::isCached()) {
         $output->writeln('Using cache.');
         $linter->setCache(Cache::get());
     }
     $fileCount = count($linter->getFiles());
     if ($fileCount <= 0) {
         $output->writeln('<info>Could not find files to lint</info>');
         return 0;
     }
     $errors = $this->executeLint($linter, $output, $fileCount, !$input->getOption('no-cache'));
     $timeUsage = Helper::formatTime(microtime(true) - $startTime);
     $memUsage = Helper::formatMemory(memory_get_usage(true) - $startMemUsage);
     $code = 0;
     $errCount = count($errors);
     $output->writeln("\n\nTime: {$timeUsage}, Memory: {$memUsage}MB\n");
     if ($errCount > 0) {
         $output->writeln('<error>FAILURES!</error>');
         $output->writeln("<error>Files: {$fileCount}, Failures: {$errCount}</error>");
         $this->showErrors($errors);
         $code = 1;
     } else {
         $output->writeln("<info>OK! (Files: {$fileCount}, Success: {$fileCount})</info>");
     }
     return $code;
 }
 /**
  * @param StopwatchEvent $event
  *
  * @return string
  */
 private function formatStopwatchEvent(StopwatchEvent $event)
 {
     return sprintf('Time: %s, Memory: %s.', Helper::formatTime($event->getDuration() / 1000), Helper::formatMemory($event->getMemory()));
 }