![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/friendsofphp/php-cs-fixer/src/Console/Report/FixReport/ |
<?php declare(strict_types=1); /* * This file is part of PHP CS Fixer. * * (c) Fabien Potencier <[email protected]> * Dariusz RumiĆski <[email protected]> * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace PhpCsFixer\Console\Report\FixReport; use PhpCsFixer\Differ\DiffConsoleFormatter; /** * @author Boris Gorbylev <[email protected]> * * @internal */ final class TextReporter implements ReporterInterface { public function getFormat(): string { return 'txt'; } public function generate(ReportSummary $reportSummary): string { $output = ''; $identifiedFiles = 0; foreach ($reportSummary->getChanged() as $file => $fixResult) { ++$identifiedFiles; $output .= sprintf('%4d) %s', $identifiedFiles, $file); if ($reportSummary->shouldAddAppliedFixers()) { $output .= $this->getAppliedFixers( $reportSummary->isDecoratedOutput(), $fixResult['appliedFixers'], ); } $output .= $this->getDiff($reportSummary->isDecoratedOutput(), $fixResult['diff']); $output .= PHP_EOL; } return $output.$this->getFooter( $reportSummary->getTime(), $identifiedFiles, $reportSummary->getFilesCount(), $reportSummary->getMemory(), $reportSummary->isDryRun() ); } /** * @param list<string> $appliedFixers */ private function getAppliedFixers(bool $isDecoratedOutput, array $appliedFixers): string { return sprintf( $isDecoratedOutput ? ' (<comment>%s</comment>)' : ' (%s)', implode(', ', $appliedFixers) ); } private function getDiff(bool $isDecoratedOutput, string $diff): string { if ('' === $diff) { return ''; } $diffFormatter = new DiffConsoleFormatter($isDecoratedOutput, sprintf( '<comment> ---------- begin diff ----------</comment>%s%%s%s<comment> ----------- end diff -----------</comment>', PHP_EOL, PHP_EOL )); return PHP_EOL.$diffFormatter->format($diff).PHP_EOL; } private function getFooter(int $time, int $identifiedFiles, int $files, int $memory, bool $isDryRun): string { if (0 === $time || 0 === $memory) { return ''; } return PHP_EOL.sprintf( '%s %d of %d %s in %.3f seconds, %.3f MB memory used'.PHP_EOL, $isDryRun ? 'Found' : 'Fixed', $identifiedFiles, $files, $isDryRun ? 'files that can be fixed' : 'files', $time / 1_000, $memory / 1_024 / 1_024 ); } }