Skip to content

Commit 55b1eb7

Browse files
authored
Merge pull request #6 from moufmouf/phpstorm_performance
Indexing performance of PHPStorm: Splitting functions in several files (one per PHP module)
2 parents 52686e4 + da7f084 commit 55b1eb7

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

src/FileCreator.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,33 @@ public function generateXlsFile(array $protoFunctions, string $path): void
4848
/**
4949
* This function generate an improved php lib function in a php file
5050
*
51-
* @param string[] $phpFunctions
51+
* @param Method[] $functions
5252
* @param string $path
5353
*/
54-
public function generatePhpFile(array $phpFunctions, string $path): void
54+
public function generatePhpFile(array $functions, string $path): void
5555
{
56-
$stream = \fopen($path, 'w');
57-
if ($stream === false) {
58-
throw new \RuntimeException('Unable to write to '.$path);
56+
$path = rtrim($path, '/').'/';
57+
$phpFunctionsByModule = [];
58+
foreach ($functions as $function) {
59+
$writePhpFunction = new WritePhpFunction($function);
60+
$phpFunctionsByModule[$function->getModuleName()][] = $writePhpFunction->getPhpFunctionalFunction();
5961
}
60-
\fwrite($stream, "<?php\n
62+
63+
foreach ($phpFunctionsByModule as $module => $phpFunctions) {
64+
$module = \lcfirst($module);
65+
$stream = \fopen($path.$module.'.php', 'w');
66+
if ($stream === false) {
67+
throw new \RuntimeException('Unable to write to '.$path);
68+
}
69+
\fwrite($stream, "<?php\n
6170
namespace Safe;
6271
6372
");
64-
foreach ($phpFunctions as $phpFunction) {
65-
\fwrite($stream, $phpFunction."\n");
73+
foreach ($phpFunctions as $phpFunction) {
74+
\fwrite($stream, $phpFunction."\n");
75+
}
76+
\fclose($stream);
6677
}
67-
\fclose($stream);
6878
}
6979

7080

src/GenerateCommand.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
3535

3636
$output->writeln('These functions have been ignored and must be dealt with manually: '.\implode(', ', $overloadedFunctions));
3737

38-
$phpFunctions = [];
39-
foreach ($functions as $function) {
40-
$writePhpFunction = new WritePhpFunction($function);
41-
$phpFunctions[] = $writePhpFunction->getPhpFunctionalFunction();
42-
}
43-
4438
$fileCreator = new FileCreator();
4539
//$fileCreator->generateXlsFile($protoFunctions, __DIR__ . '/../generated/lib.xls');
46-
$fileCreator->generatePhpFile($phpFunctions, __DIR__ . '/../generated/lib.php');
40+
$fileCreator->generatePhpFile($functions, __DIR__ . '/../generated/');
4741
$fileCreator->generateFunctionsList($functions, __DIR__ . '/../generated/functionsList.php');
4842

4943

@@ -57,7 +51,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
5751
}
5852

5953
// Finally, let's require the generated file to check there is no error.
60-
require __DIR__.'/../generated/lib.php';
54+
$files = \glob(__DIR__.'/../generated/*.php');
55+
56+
foreach ($files as $file) {
57+
require($file);
58+
}
6159
}
6260

6361
private function rmGenerated(): void
@@ -68,9 +66,12 @@ private function rmGenerated(): void
6866
\unlink($exception);
6967
}
7068

71-
if (\file_exists(__DIR__.'/../generated/lib.php')) {
72-
\unlink(__DIR__.'/../generated/lib.php');
69+
$files = \glob(__DIR__.'/../generated/*.php');
70+
71+
foreach ($files as $file) {
72+
\unlink($file);
7373
}
74+
7475
if (\file_exists(__DIR__.'/../doc/entities/generated.ent')) {
7576
\unlink(__DIR__.'/../doc/entities/generated.ent');
7677
}

0 commit comments

Comments
 (0)