|
12 | 12 | use function array_reduce;
|
13 | 13 | use function count;
|
14 | 14 | use function fnmatch;
|
| 15 | +use function in_array; |
15 | 16 | use function round;
|
16 | 17 | use function strlen;
|
17 | 18 | use function strpos;
|
@@ -123,60 +124,73 @@ private function printResultErrors(
|
123 | 124 | $prodDependencyOnlyInDevErrors = $result->getProdDependencyOnlyInDevErrors();
|
124 | 125 | $unusedDependencyErrors = $result->getUnusedDependencyErrors();
|
125 | 126 |
|
126 |
| - if (count($unknownClassErrors) > 0) { |
| 127 | + $unknownClassErrorsCount = count($unknownClassErrors); |
| 128 | + $unknownFunctionErrorsCount = count($unknownFunctionErrors); |
| 129 | + $shadowDependencyErrorsCount = count($shadowDependencyErrors); |
| 130 | + $devDependencyInProductionErrorsCount = count($devDependencyInProductionErrors); |
| 131 | + $prodDependencyOnlyInDevErrorsCount = count($prodDependencyOnlyInDevErrors); |
| 132 | + $unusedDependencyErrorsCount = count($unusedDependencyErrors); |
| 133 | + |
| 134 | + if ($unknownClassErrorsCount > 0) { |
127 | 135 | $hasError = true;
|
| 136 | + $classes = $this->pluralize($unknownClassErrorsCount, 'class'); |
128 | 137 | $this->printSymbolBasedErrors(
|
129 |
| - 'Unknown classes!', |
| 138 | + "Found $unknownClassErrorsCount unknown $classes!", |
130 | 139 | 'unable to autoload those, so we cannot check them',
|
131 | 140 | $unknownClassErrors,
|
132 | 141 | $maxShownUsages
|
133 | 142 | );
|
134 | 143 | }
|
135 | 144 |
|
136 |
| - if (count($unknownFunctionErrors) > 0) { |
| 145 | + if ($unknownFunctionErrorsCount > 0) { |
137 | 146 | $hasError = true;
|
| 147 | + $functions = $this->pluralize($unknownFunctionErrorsCount, 'function'); |
138 | 148 | $this->printSymbolBasedErrors(
|
139 |
| - 'Unknown functions!', |
| 149 | + "Found $unknownFunctionErrorsCount unknown $functions!", |
140 | 150 | 'those are not declared, so we cannot check them',
|
141 | 151 | $unknownFunctionErrors,
|
142 | 152 | $maxShownUsages
|
143 | 153 | );
|
144 | 154 | }
|
145 | 155 |
|
146 |
| - if (count($shadowDependencyErrors) > 0) { |
| 156 | + if ($shadowDependencyErrorsCount > 0) { |
147 | 157 | $hasError = true;
|
| 158 | + $dependencies = $this->pluralize($shadowDependencyErrorsCount, 'dependency'); |
148 | 159 | $this->printPackageBasedErrors(
|
149 |
| - 'Found shadow dependencies!', |
| 160 | + "Found $shadowDependencyErrorsCount shadow $dependencies!", |
150 | 161 | 'those are used, but not listed as dependency in composer.json',
|
151 | 162 | $shadowDependencyErrors,
|
152 | 163 | $maxShownUsages
|
153 | 164 | );
|
154 | 165 | }
|
155 | 166 |
|
156 |
| - if (count($devDependencyInProductionErrors) > 0) { |
| 167 | + if ($devDependencyInProductionErrorsCount > 0) { |
157 | 168 | $hasError = true;
|
| 169 | + $dependencies = $this->pluralize($devDependencyInProductionErrorsCount, 'dependency'); |
158 | 170 | $this->printPackageBasedErrors(
|
159 |
| - 'Found dev dependencies in production code!', |
| 171 | + "Found $devDependencyInProductionErrorsCount dev $dependencies in production code!", |
160 | 172 | 'those should probably be moved to "require" section in composer.json',
|
161 | 173 | $devDependencyInProductionErrors,
|
162 | 174 | $maxShownUsages
|
163 | 175 | );
|
164 | 176 | }
|
165 | 177 |
|
166 |
| - if (count($prodDependencyOnlyInDevErrors) > 0) { |
| 178 | + if ($prodDependencyOnlyInDevErrorsCount > 0) { |
167 | 179 | $hasError = true;
|
| 180 | + $dependencies = $this->pluralize($prodDependencyOnlyInDevErrorsCount, 'dependency'); |
168 | 181 | $this->printPackageBasedErrors(
|
169 |
| - 'Found prod dependencies used only in dev paths!', |
| 182 | + "Found $prodDependencyOnlyInDevErrorsCount prod $dependencies used only in dev paths!", |
170 | 183 | 'those should probably be moved to "require-dev" section in composer.json',
|
171 | 184 | array_fill_keys($prodDependencyOnlyInDevErrors, []),
|
172 | 185 | $maxShownUsages
|
173 | 186 | );
|
174 | 187 | }
|
175 | 188 |
|
176 |
| - if (count($unusedDependencyErrors) > 0) { |
| 189 | + if ($unusedDependencyErrorsCount > 0) { |
177 | 190 | $hasError = true;
|
| 191 | + $dependencies = $this->pluralize($unusedDependencyErrorsCount, 'dependency'); |
178 | 192 | $this->printPackageBasedErrors(
|
179 |
| - 'Found unused dependencies!', |
| 193 | + "Found $unusedDependencyErrorsCount unused $dependencies!", |
180 | 194 | 'those are listed in composer.json, but no usage was found in scanned paths',
|
181 | 195 | array_fill_keys($unusedDependencyErrors, []),
|
182 | 196 | $maxShownUsages
|
@@ -433,4 +447,21 @@ private function willLimitUsages(array $usages, int $limit): bool
|
433 | 447 | return false;
|
434 | 448 | }
|
435 | 449 |
|
| 450 | + private function pluralize(int $count, string $singular): string |
| 451 | + { |
| 452 | + if ($count === 1) { |
| 453 | + return $singular; |
| 454 | + } |
| 455 | + |
| 456 | + if (substr($singular, -1) === 's' || substr($singular, -1) === 'x' || substr($singular, -2) === 'sh' || substr($singular, -2) === 'ch') { |
| 457 | + return $singular . 'es'; |
| 458 | + } |
| 459 | + |
| 460 | + if (substr($singular, -1) === 'y' && !in_array($singular[strlen($singular) - 2], ['a', 'e', 'i', 'o', 'u'], true)) { |
| 461 | + return substr($singular, 0, -1) . 'ies'; |
| 462 | + } |
| 463 | + |
| 464 | + return $singular . 's'; |
| 465 | + } |
| 466 | + |
436 | 467 | }
|
0 commit comments