@@ -81,6 +81,19 @@ public function generatePhpFile(array $functions, string $path): void
81
81
}
82
82
}
83
83
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
+
84
97
85
98
/**
86
99
* 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
90
103
*/
91
104
public function generateFunctionsList (array $ functions , string $ path ): void
92
105
{
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 );
98
107
$ stream = fopen ($ path , 'w ' );
99
108
if ($ stream === false ) {
100
109
throw new \RuntimeException ('Unable to write to ' .$ path );
@@ -108,6 +117,30 @@ public function generateFunctionsList(array $functions, string $path): void
108
117
fclose ($ stream );
109
118
}
110
119
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
+
111
144
112
145
public function createExceptionFile (string $ moduleName ): void
113
146
{
0 commit comments