|
26 | 26 | */ |
27 | 27 | abstract class AbstractValidationResultRenderer implements ValidationResultRendererInterface |
28 | 28 | { |
| 29 | + /** |
| 30 | + * Resolved current working directory, cached per renderer instance so it is |
| 31 | + * not recomputed for every path during grouping. `false` means resolution |
| 32 | + * failed; null means not yet resolved. |
| 33 | + */ |
| 34 | + private string|false|null $resolvedCwd = null; |
| 35 | + |
29 | 36 | public function __construct( |
30 | 37 | protected readonly OutputInterface $output, |
31 | 38 | protected readonly bool $dryRun = false, |
@@ -112,12 +119,8 @@ protected function normalizePath(string $path): string |
112 | 119 |
|
113 | 120 | $normalizedPath = rtrim($realPath, \DIRECTORY_SEPARATOR); |
114 | 121 |
|
115 | | - $cwd = getcwd(); |
| 122 | + $realCwd = $this->resolvedCwd(); |
116 | 123 | // @codeCoverageIgnoreStart |
117 | | - if (false === $cwd) { |
118 | | - return $normalizedPath; |
119 | | - } |
120 | | - $realCwd = realpath($cwd); |
121 | 124 | if (false === $realCwd) { |
122 | 125 | return $normalizedPath; |
123 | 126 | } |
@@ -156,4 +159,18 @@ protected function calculateExitCode(ValidationResult $validationResult): int |
156 | 159 | return $validationResult->getOverallResult() |
157 | 160 | ->resolveErrorToCommandExitCode($this->dryRun, $this->strict); |
158 | 161 | } |
| 162 | + |
| 163 | + /** |
| 164 | + * Resolves and caches the current working directory for this renderer. |
| 165 | + */ |
| 166 | + private function resolvedCwd(): string|false |
| 167 | + { |
| 168 | + if (null !== $this->resolvedCwd) { |
| 169 | + return $this->resolvedCwd; |
| 170 | + } |
| 171 | + |
| 172 | + $cwd = getcwd(); |
| 173 | + |
| 174 | + return $this->resolvedCwd = false === $cwd ? false : realpath($cwd); |
| 175 | + } |
159 | 176 | } |
0 commit comments