/
CommandHelper.php
582 lines (507 loc) · 22 KB
/
CommandHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
<?php declare(strict_types = 1);
namespace PHPStan\Command;
use Closure;
use Composer\XdebugHandler\XdebugHandler;
use Nette\DI\Config\Adapters\PhpAdapter;
use Nette\DI\Helpers;
use Nette\DI\InvalidConfigurationException;
use Nette\DI\ServiceCreationException;
use Nette\FileNotFoundException;
use Nette\InvalidStateException;
use Nette\Schema\ValidationException;
use Nette\Utils\AssertionException;
use Nette\Utils\Strings;
use Nette\Utils\Validators;
use PHPStan\Command\Symfony\SymfonyOutput;
use PHPStan\Command\Symfony\SymfonyStyle;
use PHPStan\DependencyInjection\Container;
use PHPStan\DependencyInjection\ContainerFactory;
use PHPStan\DependencyInjection\InvalidIgnoredErrorPatternsException;
use PHPStan\DependencyInjection\LoaderFactory;
use PHPStan\DependencyInjection\NeonAdapter;
use PHPStan\ExtensionInstaller\GeneratedConfig;
use PHPStan\File\FileFinder;
use PHPStan\File\FileHelper;
use PHPStan\ShouldNotHappenException;
use ReflectionClass;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
use function array_diff_key;
use function array_key_exists;
use function array_map;
use function array_merge;
use function array_unique;
use function class_exists;
use function count;
use function dirname;
use function error_get_last;
use function get_class;
use function getcwd;
use function gettype;
use function implode;
use function ini_get;
use function ini_set;
use function is_dir;
use function is_file;
use function is_readable;
use function is_string;
use function mkdir;
use function register_shutdown_function;
use function sprintf;
use function str_ends_with;
use function str_repeat;
use function strpos;
use function sys_get_temp_dir;
use const DIRECTORY_SEPARATOR;
use const E_ERROR;
use const PHP_VERSION_ID;
class CommandHelper
{
public const DEFAULT_LEVEL = '0';
private static ?string $reservedMemory = null;
/**
* @param string[] $paths
* @param string[] $composerAutoloaderProjectPaths
*
* @throws InceptionNotSuccessfulException
*/
public static function begin(
InputInterface $input,
OutputInterface $output,
array $paths,
?string $memoryLimit,
?string $autoloadFile,
array $composerAutoloaderProjectPaths,
?string $projectConfigFile,
?string $generateBaselineFile,
?string $level,
bool $allowXdebug,
bool $debugEnabled = false,
?string $singleReflectionFile = null,
?string $singleReflectionInsteadOfFile = null,
bool $cleanupContainerCache = true,
): InceptionResult
{
if (!$allowXdebug) {
$xdebug = new XdebugHandler('phpstan');
$xdebug->setPersistent();
$xdebug->check();
unset($xdebug);
}
$stdOutput = new SymfonyOutput($output, new SymfonyStyle(new ErrorsConsoleStyle($input, $output)));
/** @var Output $errorOutput */
$errorOutput = (static function () use ($input, $output): Output {
$symfonyErrorOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
return new SymfonyOutput($symfonyErrorOutput, new SymfonyStyle(new ErrorsConsoleStyle($input, $symfonyErrorOutput)));
})();
if ($memoryLimit !== null) {
if (Strings::match($memoryLimit, '#^-?\d+[kMG]?$#i') === null) {
$errorOutput->writeLineFormatted(sprintf('Invalid memory limit format "%s".', $memoryLimit));
throw new InceptionNotSuccessfulException();
}
if (ini_set('memory_limit', $memoryLimit) === false) {
$errorOutput->writeLineFormatted(sprintf('Memory limit "%s" cannot be set.', $memoryLimit));
throw new InceptionNotSuccessfulException();
}
}
self::$reservedMemory = str_repeat('PHPStan', 1463); // reserve 10 kB of space
register_shutdown_function(static function () use ($errorOutput): void {
self::$reservedMemory = null;
$error = error_get_last();
if ($error === null) {
return;
}
if ($error['type'] !== E_ERROR) {
return;
}
if (strpos($error['message'], 'Allowed memory size') === false) {
return;
}
$errorOutput->writeLineFormatted('');
$errorOutput->writeLineFormatted(sprintf('<error>PHPStan process crashed because it reached configured PHP memory limit</error>: %s', ini_get('memory_limit')));
$errorOutput->writeLineFormatted('Increase your memory limit in php.ini or run PHPStan with --memory-limit CLI option.');
});
$currentWorkingDirectory = getcwd();
if ($currentWorkingDirectory === false) {
throw new ShouldNotHappenException();
}
$currentWorkingDirectoryFileHelper = new FileHelper($currentWorkingDirectory);
$currentWorkingDirectory = $currentWorkingDirectoryFileHelper->getWorkingDirectory();
if ($autoloadFile !== null) {
$autoloadFile = $currentWorkingDirectoryFileHelper->absolutizePath($autoloadFile);
if (!is_file($autoloadFile)) {
$errorOutput->writeLineFormatted(sprintf('Autoload file "%s" not found.', $autoloadFile));
throw new InceptionNotSuccessfulException();
}
(static function (string $file): void {
require_once $file;
})($autoloadFile);
}
if ($projectConfigFile === null) {
foreach (['phpstan.neon', 'phpstan.neon.dist', 'phpstan.dist.neon'] as $discoverableConfigName) {
$discoverableConfigFile = $currentWorkingDirectory . DIRECTORY_SEPARATOR . $discoverableConfigName;
if (is_file($discoverableConfigFile)) {
$projectConfigFile = $discoverableConfigFile;
$errorOutput->writeLineFormatted(sprintf('Note: Using configuration file %s.', $projectConfigFile));
break;
}
}
} else {
$projectConfigFile = $currentWorkingDirectoryFileHelper->absolutizePath($projectConfigFile);
}
if ($generateBaselineFile !== null) {
$generateBaselineFile = $currentWorkingDirectoryFileHelper->normalizePath($currentWorkingDirectoryFileHelper->absolutizePath($generateBaselineFile));
}
$defaultLevelUsed = false;
if ($projectConfigFile === null && $level === null) {
$level = self::DEFAULT_LEVEL;
$defaultLevelUsed = true;
}
$paths = array_map(static fn (string $path): string => $currentWorkingDirectoryFileHelper->normalizePath($currentWorkingDirectoryFileHelper->absolutizePath($path)), $paths);
$analysedPathsFromConfig = [];
$containerFactory = new ContainerFactory($currentWorkingDirectory);
$projectConfig = null;
if ($projectConfigFile !== null) {
if (!is_file($projectConfigFile)) {
$errorOutput->writeLineFormatted(sprintf('Project config file at path %s does not exist.', $projectConfigFile));
throw new InceptionNotSuccessfulException();
}
$loader = (new LoaderFactory(
$currentWorkingDirectoryFileHelper,
$containerFactory->getRootDirectory(),
$containerFactory->getCurrentWorkingDirectory(),
$generateBaselineFile,
))->createLoader();
try {
$projectConfig = $loader->load($projectConfigFile, null);
} catch (InvalidStateException | FileNotFoundException $e) {
$errorOutput->writeLineFormatted($e->getMessage());
throw new InceptionNotSuccessfulException();
}
$defaultParameters = [
'rootDir' => $containerFactory->getRootDirectory(),
'currentWorkingDirectory' => $containerFactory->getCurrentWorkingDirectory(),
];
if (isset($projectConfig['parameters']['tmpDir'])) {
$tmpDir = Helpers::expand($projectConfig['parameters']['tmpDir'], $defaultParameters);
}
if ($level === null && isset($projectConfig['parameters']['level'])) {
$level = (string) $projectConfig['parameters']['level'];
}
if (isset($projectConfig['parameters']['paths'])) {
$analysedPathsFromConfig = Helpers::expand($projectConfig['parameters']['paths'], $defaultParameters);
}
if (count($paths) === 0) {
$paths = $analysedPathsFromConfig;
}
}
$additionalConfigFiles = [];
if ($level !== null) {
$levelConfigFile = sprintf('%s/config.level%s.neon', $containerFactory->getConfigDirectory(), $level);
if (!is_file($levelConfigFile)) {
$errorOutput->writeLineFormatted(sprintf('Level config file %s was not found.', $levelConfigFile));
throw new InceptionNotSuccessfulException();
}
$additionalConfigFiles[] = $levelConfigFile;
}
if (class_exists('PHPStan\ExtensionInstaller\GeneratedConfig')) {
$generatedConfigReflection = new ReflectionClass('PHPStan\ExtensionInstaller\GeneratedConfig');
$generatedConfigDirectory = dirname($generatedConfigReflection->getFileName());
foreach (GeneratedConfig::EXTENSIONS as $name => $extensionConfig) {
foreach ($extensionConfig['extra']['includes'] ?? [] as $includedFile) {
if (!is_string($includedFile)) {
$errorOutput->writeLineFormatted(sprintf('Cannot include config from package %s, expecting string file path but got %s', $name, gettype($includedFile)));
throw new InceptionNotSuccessfulException();
}
$includedFilePath = null;
if (isset($extensionConfig['relative_install_path'])) {
$includedFilePath = sprintf('%s/%s/%s', $generatedConfigDirectory, $extensionConfig['relative_install_path'], $includedFile);
if (!is_file($includedFilePath) || !is_readable($includedFilePath)) {
$includedFilePath = null;
}
}
if ($includedFilePath === null) {
$includedFilePath = sprintf('%s/%s', $extensionConfig['install_path'], $includedFile);
}
if (!is_file($includedFilePath) || !is_readable($includedFilePath)) {
$errorOutput->writeLineFormatted(sprintf('Config file %s does not exist or isn\'t readable', $includedFilePath));
throw new InceptionNotSuccessfulException();
}
$additionalConfigFiles[] = $includedFilePath;
}
}
}
if (
$projectConfigFile !== null
&& $currentWorkingDirectoryFileHelper->normalizePath($projectConfigFile, '/') !== $currentWorkingDirectoryFileHelper->normalizePath(__DIR__ . '/../../conf/config.stubFiles.neon', '/')
) {
$additionalConfigFiles[] = $projectConfigFile;
}
$loaderParameters = [
'rootDir' => $containerFactory->getRootDirectory(),
'currentWorkingDirectory' => $containerFactory->getCurrentWorkingDirectory(),
];
self::detectDuplicateIncludedFiles(
$errorOutput,
$currentWorkingDirectoryFileHelper,
$additionalConfigFiles,
$loaderParameters,
);
$createDir = static function (string $path) use ($errorOutput): void {
if (!is_dir($path) && !@mkdir($path, 0777) && !is_dir($path)) {
$errorOutput->writeLineFormatted(sprintf('Cannot create a temp directory %s', $path));
throw new InceptionNotSuccessfulException();
}
};
if (!isset($tmpDir)) {
$tmpDir = sys_get_temp_dir() . '/phpstan';
$createDir($tmpDir);
}
try {
$container = $containerFactory->create($tmpDir, $additionalConfigFiles, $paths, $composerAutoloaderProjectPaths, $analysedPathsFromConfig, $level ?? self::DEFAULT_LEVEL, $generateBaselineFile, $autoloadFile, $singleReflectionFile, $singleReflectionInsteadOfFile);
} catch (InvalidConfigurationException | AssertionException $e) {
$errorOutput->writeLineFormatted('<error>Invalid configuration:</error>');
$errorOutput->writeLineFormatted($e->getMessage());
throw new InceptionNotSuccessfulException();
} catch (InvalidIgnoredErrorPatternsException $e) {
$errorOutput->writeLineFormatted(sprintf('<error>Invalid %s in ignoreErrors:</error>', count($e->getErrors()) === 1 ? 'entry' : 'entries'));
foreach ($e->getErrors() as $error) {
$errorOutput->writeLineFormatted($error);
$errorOutput->writeLineFormatted('');
}
throw new InceptionNotSuccessfulException();
} catch (ValidationException $e) {
foreach ($e->getMessages() as $message) {
$errorOutput->writeLineFormatted('<error>Invalid configuration:</error>');
$errorOutput->writeLineFormatted($message);
}
throw new InceptionNotSuccessfulException();
} catch (ServiceCreationException $e) {
$matches = Strings::match($e->getMessage(), '#Service of type (?<serviceType>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff\\\\]*[a-zA-Z0-9_\x7f-\xff]): Service of type (?<parserServiceType>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff\\\\]*[a-zA-Z0-9_\x7f-\xff]) needed by \$(?<parameterName>[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*) in (?<methodName>[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*)\(\)#');
if ($matches === null) {
throw $e;
}
if ($matches['parserServiceType'] !== 'PHPStan\\Parser\\Parser') {
throw $e;
}
if ($matches['methodName'] !== '__construct') {
throw $e;
}
$errorOutput->writeLineFormatted('<error>Invalid configuration:</error>');
$errorOutput->writeLineFormatted(sprintf("Service of type <fg=cyan>%s</> is no longer autowired.\n", $matches['parserServiceType']));
$errorOutput->writeLineFormatted('You need to choose one of the following services');
$errorOutput->writeLineFormatted(sprintf('and use it in the %s argument of your service <fg=cyan>%s</>:', $matches['parameterName'], $matches['serviceType']));
$errorOutput->writeLineFormatted('* <fg=cyan>defaultAnalysisParser</> (if you\'re parsing files from analysed paths)');
$errorOutput->writeLineFormatted('* <fg=cyan>currentPhpVersionSimpleDirectParser</> (in most other situations)');
$errorOutput->writeLineFormatted('');
$errorOutput->writeLineFormatted('After fixing this problem, your configuration will look something like this:');
$errorOutput->writeLineFormatted('');
$errorOutput->writeLineFormatted('-');
$errorOutput->writeLineFormatted(sprintf("\tclass: %s", $matches['serviceType']));
$errorOutput->writeLineFormatted(sprintf("\targuments:"));
$errorOutput->writeLineFormatted(sprintf("\t\t%s: @defaultAnalysisParser", $matches['parameterName']));
$errorOutput->writeLineFormatted('');
throw new InceptionNotSuccessfulException();
}
if ($cleanupContainerCache) {
$containerFactory->clearOldContainers($tmpDir);
}
if (count($paths) === 0) {
$errorOutput->writeLineFormatted('At least one path must be specified to analyse.');
throw new InceptionNotSuccessfulException();
}
/** @var bool|null $customRulesetUsed */
$customRulesetUsed = $container->getParameter('customRulesetUsed');
if ($customRulesetUsed === null) {
$errorOutput->writeLineFormatted('');
$errorOutput->writeLineFormatted('<comment>No rules detected</comment>');
$errorOutput->writeLineFormatted('');
$errorOutput->writeLineFormatted('You have the following choices:');
$errorOutput->writeLineFormatted('');
$errorOutput->writeLineFormatted('* while running the analyse option, use the <info>--level</info> option to adjust your rule level - the higher the stricter');
$errorOutput->writeLineFormatted('');
$errorOutput->writeLineFormatted(sprintf('* create your own <info>custom ruleset</info> by selecting which rules you want to check by copying the service definitions from the built-in config level files in <options=bold>%s</>.', $currentWorkingDirectoryFileHelper->normalizePath(__DIR__ . '/../../conf')));
$errorOutput->writeLineFormatted(' * in this case, don\'t forget to define parameter <options=bold>customRulesetUsed</> in your config file.');
$errorOutput->writeLineFormatted('');
throw new InceptionNotSuccessfulException();
} elseif ($customRulesetUsed) {
$defaultLevelUsed = false;
}
foreach ($container->getParameter('bootstrapFiles') as $bootstrapFileFromArray) {
self::executeBootstrapFile($bootstrapFileFromArray, $container, $errorOutput, $debugEnabled);
}
if (PHP_VERSION_ID >= 80000) {
require_once __DIR__ . '/../../stubs/runtime/Enum/UnitEnum.php';
require_once __DIR__ . '/../../stubs/runtime/Enum/BackedEnum.php';
require_once __DIR__ . '/../../stubs/runtime/Enum/ReflectionEnum.php';
require_once __DIR__ . '/../../stubs/runtime/Enum/ReflectionEnumUnitCase.php';
require_once __DIR__ . '/../../stubs/runtime/Enum/ReflectionEnumBackedCase.php';
}
foreach ($container->getParameter('scanFiles') as $scannedFile) {
if (is_file($scannedFile)) {
continue;
}
$errorOutput->writeLineFormatted(sprintf('Scanned file %s does not exist.', $scannedFile));
throw new InceptionNotSuccessfulException();
}
foreach ($container->getParameter('scanDirectories') as $scannedDirectory) {
if (is_dir($scannedDirectory)) {
continue;
}
$errorOutput->writeLineFormatted(sprintf('Scanned directory %s does not exist.', $scannedDirectory));
throw new InceptionNotSuccessfulException();
}
$alreadyAddedStubFiles = [];
foreach ($container->getParameter('stubFiles') as $stubFile) {
if (array_key_exists($stubFile, $alreadyAddedStubFiles)) {
$errorOutput->writeLineFormatted(sprintf('Stub file %s is added multiple times.', $stubFile));
throw new InceptionNotSuccessfulException();
}
$alreadyAddedStubFiles[$stubFile] = true;
if (is_file($stubFile)) {
continue;
}
$errorOutput->writeLineFormatted(sprintf('Stub file %s does not exist.', $stubFile));
throw new InceptionNotSuccessfulException();
}
$excludesAnalyse = $container->getParameter('excludes_analyse');
$excludePaths = $container->getParameter('excludePaths');
if (count($excludesAnalyse) > 0 && $excludePaths !== null) {
$errorOutput->writeLineFormatted(sprintf('Configuration parameters <fg=cyan>excludes_analyse</> and <fg=cyan>excludePaths</> cannot be used at the same time.'));
$errorOutput->writeLineFormatted('');
$errorOutput->writeLineFormatted(sprintf('Parameter <fg=cyan>excludes_analyse</> has been deprecated so use <fg=cyan>excludePaths</> only from now on.'));
$errorOutput->writeLineFormatted('');
throw new InceptionNotSuccessfulException();
} elseif (count($excludesAnalyse) > 0) {
$errorOutput->writeLineFormatted('⚠️ You\'re using a deprecated config option <fg=cyan>excludes_analyse</>. ⚠️️');
$errorOutput->writeLineFormatted('');
$errorOutput->writeLineFormatted(sprintf('Parameter <fg=cyan>excludes_analyse</> has been deprecated so use <fg=cyan>excludePaths</> only from now on.'));
}
$tempResultCachePath = $container->getParameter('tempResultCachePath');
$createDir($tempResultCachePath);
/** @var FileFinder $fileFinder */
$fileFinder = $container->getService('fileFinderAnalyse');
$pathRoutingParser = $container->getService('pathRoutingParser');
/** @var Closure(): array{string[], bool} $filesCallback */
$filesCallback = static function () use ($fileFinder, $pathRoutingParser, $paths): array {
$fileFinderResult = $fileFinder->findFiles($paths);
$files = $fileFinderResult->getFiles();
$pathRoutingParser->setAnalysedFiles($files);
return [$files, $fileFinderResult->isOnlyFiles()];
};
return new InceptionResult(
$filesCallback,
$stdOutput,
$errorOutput,
$container,
$defaultLevelUsed,
$projectConfigFile,
$projectConfig,
$generateBaselineFile,
);
}
/**
* @throws InceptionNotSuccessfulException
*/
private static function executeBootstrapFile(
string $file,
Container $container,
Output $errorOutput,
bool $debugEnabled,
): void
{
if (!is_file($file)) {
$errorOutput->writeLineFormatted(sprintf('Bootstrap file %s does not exist.', $file));
throw new InceptionNotSuccessfulException();
}
try {
(static function (string $file) use ($container): void {
require_once $file;
})($file);
} catch (Throwable $e) {
$errorOutput->writeLineFormatted(sprintf('%s thrown in %s on line %d while loading bootstrap file %s: %s', get_class($e), $e->getFile(), $e->getLine(), $file, $e->getMessage()));
if ($debugEnabled) {
$errorOutput->writeLineFormatted($e->getTraceAsString());
}
throw new InceptionNotSuccessfulException();
}
}
/**
* @param string[] $configFiles
* @param array<string, string> $loaderParameters
* @throws InceptionNotSuccessfulException
*/
private static function detectDuplicateIncludedFiles(
Output $output,
FileHelper $fileHelper,
array $configFiles,
array $loaderParameters,
): void
{
$neonAdapter = new NeonAdapter();
$phpAdapter = new PhpAdapter();
$allConfigFiles = [];
foreach ($configFiles as $configFile) {
$allConfigFiles = array_merge($allConfigFiles, self::getConfigFiles($fileHelper, $neonAdapter, $phpAdapter, $configFile, $loaderParameters, null));
}
$normalized = array_map(static fn (string $file): string => $fileHelper->normalizePath($file), $allConfigFiles);
$deduplicated = array_unique($normalized);
if (count($normalized) <= count($deduplicated)) {
return;
}
$duplicateFiles = array_unique(array_diff_key($normalized, $deduplicated));
$format = "<error>These files are included multiple times:</error>\n- %s";
if (count($duplicateFiles) === 1) {
$format = "<error>This file is included multiple times:</error>\n- %s";
}
$output->writeLineFormatted(sprintf($format, implode("\n- ", $duplicateFiles)));
if (class_exists('PHPStan\ExtensionInstaller\GeneratedConfig')) {
$output->writeLineFormatted('');
$output->writeLineFormatted('It can lead to unexpected results. If you\'re using phpstan/extension-installer, make sure you have removed corresponding neon files from your project config file.');
}
throw new InceptionNotSuccessfulException();
}
/**
* @param array<string, string> $loaderParameters
* @return string[]
*/
private static function getConfigFiles(
FileHelper $fileHelper,
NeonAdapter $neonAdapter,
PhpAdapter $phpAdapter,
string $configFile,
array $loaderParameters,
?string $generateBaselineFile,
): array
{
if ($generateBaselineFile === $fileHelper->normalizePath($configFile)) {
return [];
}
if (!is_file($configFile) || !is_readable($configFile)) {
return [];
}
if (str_ends_with($configFile, '.php')) {
$data = $phpAdapter->load($configFile);
} else {
$data = $neonAdapter->load($configFile);
}
$allConfigFiles = [$configFile];
if (isset($data['includes'])) {
Validators::assert($data['includes'], 'list', sprintf("section 'includes' in file '%s'", $configFile));
$includes = Helpers::expand($data['includes'], $loaderParameters);
foreach ($includes as $include) {
$include = self::expandIncludedFile($include, $configFile);
$allConfigFiles = array_merge($allConfigFiles, self::getConfigFiles($fileHelper, $neonAdapter, $phpAdapter, $include, $loaderParameters, $generateBaselineFile));
}
}
return $allConfigFiles;
}
private static function expandIncludedFile(string $includedFile, string $mainFile): string
{
return Strings::match($includedFile, '#([a-z]+:)?[/\\\\]#Ai') !== null // is absolute
? $includedFile
: dirname($mainFile) . '/' . $includedFile;
}
}