@@ -77,7 +77,7 @@ public function enterNode(Node $node)
7777 $ metadata = require __DIR__ . '/functionMetadata_original.php ' ;
7878 foreach ($ visitor ->functions as $ functionName ) {
7979 if (array_key_exists ($ functionName , $ metadata )) {
80- if ($ metadata [$ functionName ]['hasSideEffects ' ]) {
80+ if (isset ( $ metadata [ $ functionName ][ ' hasSideEffects ' ]) && $ metadata [$ functionName ]['hasSideEffects ' ]) {
8181 if (in_array ($ functionName , [
8282 'mt_rand ' ,
8383 'rand ' ,
@@ -91,6 +91,14 @@ public function enterNode(Node $node)
9191 }
9292 throw new ShouldNotHappenException ($ functionName );
9393 }
94+
95+ if (isset ($ metadata [$ functionName ]['pureUnlessCallableIsImpureParameters ' ])) {
96+ $ metadata [$ functionName ] = [
97+ 'pureUnlessCallableIsImpureParameters ' => $ metadata [$ functionName ]['pureUnlessCallableIsImpureParameters ' ],
98+ ];
99+
100+ continue ;
101+ }
94102 }
95103 $ metadata [$ functionName ] = ['hasSideEffects ' => false ];
96104 }
@@ -128,12 +136,29 @@ public function enterNode(Node $node)
128136];
129137php;
130138 $ content = '' ;
139+ $ escape = fn (mixed $ value ): string => var_export ($ value , true );
140+ $ encodeHasSideEffects = fn (array $ meta ) => [$ escape ('hasSideEffects ' ), $ escape ($ meta ['hasSideEffects ' ])];
141+ $ encodePureUnlessCallableIsImpureParameters = fn (array $ meta ) => [
142+ $ escape ('pureUnlessCallableIsImpureParameters ' ),
143+ sprintf (
144+ '[%s] ' ,
145+ implode (' , ' , array_map (
146+ fn ($ key , $ param ) => sprintf ('%s => %s ' , $ escape ($ key ), $ escape ($ param )),
147+ array_keys ($ meta ['pureUnlessCallableIsImpureParameters ' ]),
148+ $ meta ['pureUnlessCallableIsImpureParameters ' ]),
149+ ),
150+ ),
151+ ];
152+
131153 foreach ($ metadata as $ name => $ meta ) {
132154 $ content .= sprintf (
133155 "\t%s => [%s => %s], \n" ,
134156 var_export ($ name , true ),
135- var_export ('hasSideEffects ' , true ),
136- var_export ($ meta ['hasSideEffects ' ], true ),
157+ ...match (true ) {
158+ isset ($ meta ['hasSideEffects ' ]) => $ encodeHasSideEffects ($ meta ),
159+ isset ($ meta ['pureUnlessCallableIsImpureParameters ' ]) => $ encodePureUnlessCallableIsImpureParameters ($ meta ),
160+ default => throw new ShouldNotHappenException ($ escape ($ meta )),
161+ },
137162 );
138163 }
139164
0 commit comments