File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -385,9 +385,25 @@ private function validateSyntax($code) {
385385 return ['valid ' => true , 'errors ' => null ]; // Skip validation
386386 }
387387
388+ // Detect if code is a method (needs class wrapper) or standalone code
389+ $ trimmedCode = trim ($ code );
390+ $ isMethod = preg_match ('/^\s*(public|protected|private|function)\s+/ ' , $ trimmedCode );
391+
392+ // Wrap code appropriately
393+ if ($ isMethod ) {
394+ // Wrap method in a dummy class for validation
395+ $ validationCode = '<?php ' . PHP_EOL .
396+ 'class DummyValidationClass { ' . PHP_EOL .
397+ $ code . PHP_EOL .
398+ '} ' ;
399+ } else {
400+ // Standalone code - just prepend <?php
401+ $ validationCode = '<?php ' . PHP_EOL . $ code ;
402+ }
403+
388404 // Create temporary file
389405 $ tmpFile = tempnam (sys_get_temp_dir (), 'kyte_ai_fix_ ' );
390- file_put_contents ($ tmpFile , ' <?php ' . PHP_EOL . $ code );
406+ file_put_contents ($ tmpFile , $ validationCode );
391407
392408 // Run php -l
393409 $ output = [];
You can’t perform that action at this time.
0 commit comments