Skip to content

Commit e18b3b4

Browse files
committed
PHAR - rename file extensions of PhpStorm stubs
1 parent 4f51382 commit e18b3b4

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

compiler/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"nette/neon": "^3.0.0",
99
"symfony/console": "^4.1",
1010
"symfony/process": "^4.1",
11-
"symfony/filesystem": "^4.1"
11+
"symfony/filesystem": "^4.1",
12+
"symfony/finder": "^5.0"
1213
},
1314
"autoload": {
1415
"psr-4": {

compiler/src/Console/CompileCommand.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4848
$this->processFactory->setOutput($output);
4949

5050
$this->fixComposerJson($this->buildDir);
51+
$this->renamePhpStormStubs();
5152
$this->processFactory->create(['composer', 'update', '--no-dev', '--classmap-authoritative'], $this->buildDir);
5253

5354
$this->processFactory->create(['php', 'box.phar', 'compile', '--no-parallel'], $this->dataDir);
@@ -76,4 +77,41 @@ private function fixComposerJson(string $buildDir): void
7677
$this->filesystem->write($buildDir . '/composer.json', $encodedJson);
7778
}
7879

80+
private function renamePhpStormStubs(): void
81+
{
82+
$directory = $this->buildDir . '/vendor/jetbrains/phpstorm-stubs';
83+
if (!is_dir($directory)) {
84+
return;
85+
}
86+
87+
$stubFinder = \Symfony\Component\Finder\Finder::create();
88+
$stubsMapPath = $directory . '/PhpStormStubsMap.php';
89+
foreach ($stubFinder->files()->name('*.php')->in($directory) as $stubFile) {
90+
$path = $stubFile->getPathname();
91+
if ($path === $stubsMapPath) {
92+
continue;
93+
}
94+
95+
$renameSuccess = rename(
96+
$path,
97+
dirname($path) . '/' . $stubFile->getBasename('.php') . '.stub'
98+
);
99+
if ($renameSuccess === false) {
100+
throw new \PHPStan\ShouldNotHappenException(sprintf('Could not rename %s', $path));
101+
}
102+
}
103+
104+
$stubsMapContents = file_get_contents($stubsMapPath);
105+
if ($stubsMapContents === false) {
106+
throw new \PHPStan\ShouldNotHappenException(sprintf('Could not read %s', $stubsMapPath));
107+
}
108+
109+
$stubsMapContents = str_replace('.php\',', '.stub\',', $stubsMapContents);
110+
111+
$putSuccess = file_put_contents($directory . '/PhpStormStubsMap.php', $stubsMapContents);
112+
if ($putSuccess === false) {
113+
throw new \PHPStan\ShouldNotHappenException(sprintf('Could not write %s', $stubsMapPath));
114+
}
115+
}
116+
79117
}

0 commit comments

Comments
 (0)