Skip to content

Commit c8cc059

Browse files
committed
Add wrapper to code lineter
1 parent 6b1e3de commit c8cc059

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/AI/AIErrorAnalyzer.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff 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 = [];

0 commit comments

Comments
 (0)