/** * @inheritdoc */ public function format(MessageBag $bag) { $output = []; foreach ($bag->getAll() as $message) { $output[] = sprintf("[%s] %s", $this->formatType($message), $message->format(true)); } return implode(PHP_EOL, $output); }
/** * If a formatter was specified, run it, return true. Otherwise, return false. * @codeCoverageIgnore * * @param Output $output * @return boolean */ protected function useFormatter(Output $output) { if (is_null($this->formatter)) { return false; } if (!array_key_exists($this->formatter, $this->formatters)) { throw new \InvalidArgumentException("Invalid formatter name '{$this->formatter}'."); } $output->writeln("Running formatter <comment>{$this->formatter}</comment>..."); $output->writeln(""); $bag = new MessageBag(); $startTime = microtime(true); foreach ($this->validators as $validator) { $bag = new MessageBag(array_merge($validator->handle()->getAll(), $bag->getAll())); } // Update the counters. $this->updateCounters($bag); $output->writeln($this->formatters[$this->formatter]->format($bag)); $output->writeln(""); $output->writeln(sprintf("Done in %s seconds.", round(microtime(true) - $startTime, 5))); return true; }