@@ -81,6 +81,19 @@ public function generatePhpFile(array $functions, string $path): void
8181 }
8282 }
8383
84+ /**
85+ * @param Method[] $functions
86+ * @return string[]
87+ */
88+ private function getFunctionsNameList (array $ functions ): array
89+ {
90+ $ functionNames = array_map (function (Method $ function ) {
91+ return $ function ->getFunctionName ();
92+ }, $ functions );
93+ $ specialCases = require __DIR__ .'/../config/specialCasesFunctions.php ' ;
94+ return array_merge ($ functionNames , $ specialCases );
95+ }
96+
8497
8598 /**
8699 * This function generate a PHP file containing the list of functions we can handle.
@@ -90,11 +103,7 @@ public function generatePhpFile(array $functions, string $path): void
90103 */
91104 public function generateFunctionsList (array $ functions , string $ path ): void
92105 {
93- $ functionNames = array_map (function (Method $ function ) {
94- return $ function ->getFunctionName ();
95- }, $ functions );
96- $ specialCases = require __DIR__ .'/../config/specialCasesFunctions.php ' ;
97- $ functionNames = array_merge ($ functionNames , $ specialCases );
106+ $ functionNames = $ this ->getFunctionsNameList ($ functions );
98107 $ stream = fopen ($ path , 'w ' );
99108 if ($ stream === false ) {
100109 throw new \RuntimeException ('Unable to write to ' .$ path );
@@ -108,6 +117,30 @@ public function generateFunctionsList(array $functions, string $path): void
108117 fclose ($ stream );
109118 }
110119
120+ /**
121+ * This function generate a rector yml file containing a replacer for all functions
122+ *
123+ * @param Method[] $functions
124+ * @param string $path
125+ */
126+ public function generateRectorFile (array $ functions , string $ path ): void
127+ {
128+ $ functionNames = $ this ->getFunctionsNameList ($ functions );
129+ $ stream = fopen ($ path , 'w ' );
130+ if ($ stream === false ) {
131+ throw new \RuntimeException ('Unable to write to ' .$ path );
132+ }
133+ fwrite ($ stream , "# This rector file is replacing all core PHP functions with the equivalent \"safe \" functions
134+ services:
135+ Rector\Rector\Function_\FunctionReplaceRector:
136+ \$oldFunctionToNewFunction:
137+ " );
138+ foreach ($ functionNames as $ functionName ) {
139+ fwrite ($ stream , ' ' .$ functionName .": 'Safe \\" .$ functionName ."' \n" );
140+ }
141+ fclose ($ stream );
142+ }
143+
111144
112145 public function createExceptionFile (string $ moduleName ): void
113146 {
0 commit comments