0)) { $isFirstLine = false; if (\stripos($line, ' function ') !== false) { $scopeStart = true; } if ($scopeStart) { $scopeCounter += \substr_count($line, '{'); $scopeCounter -= \substr_count($line, '}'); if ($scopeCounter === 0) { $scopeStart = false; } } $lines .= $line; } if ($isFirstLine && empty($lines)) { return false; } return $lines; }; foreach ($globs as $glob) { $files = \glob($glob); foreach ($files as $file) { if (\stripos($file, 'Test.php')) { continue; } GptHelper::handleFile($file, $file, $behaviour, $fileReader); } } // implement test $globs = [ __DIR__ . '/../../phpOMS/**.php', __DIR__ . '/../../Modules/*/Models/*.php', ]; $behaviour = << 0)) { $isFirstLine = false; if (\stripos($line, 'public function ') !== false || \stripos($line, 'public static function ') !== false) { // Check if a test exists for this function $testFile = \str_replace('.php', 'Test.php', $filename); $testFile = \str_replace('/phpOMS/', '/phpOMS/tests/', $filename); if (\stripos($testFile, '../Modules/') !== false) { $subdirectory = "tests/"; $position = strrpos($testFile, "/../"); if ($position !== false) { $position = \stripos($testFile, '/', $position + 4) + 1; $position = \stripos($testFile, '/', $position) + 1; $testFile = \substr_replace($testFile, $subdirectory, $position, 0); } } if (\file_exists($testFile)) { $scopeStart = true; $testContent = \file_get_contents($testFile); // Parse functio name $pattern = '/\bfunction\b\s+(\w+)\s*\(/'; \preg_match($pattern, $line, $matches); if (\stripos($testContent, $matches[1] ?? '~~~') !== false) { // Test already exists $scopeStart = false; } } $scopeStart = true; } // Not in a function / not relevant if (!$scopeStart) { continue; } if ($scopeStart) { $scopeCounter += \substr_count($line, '{'); $scopeCounter -= \substr_count($line, '}'); if ($scopeCounter === 0) { $scopeStart = false; } } $lines .= $line; } if ($isFirstLine && empty($lines)) { return false; } return $lines; }; foreach ($globs as $glob) { $files = \glob($glob); foreach ($files as $file) { if (\stripos($file, 'Test.php')) { continue; } $response = GptHelper::handleFile($file, 'php://memory', $behaviour, $fileReader); echo $response , \PHP_EOL , \PHP_EOL; } } // complete and improve test $globs = [ __DIR__ . '/../../phpOMS/**.php', __DIR__ . '/../../Modules/*/Models/*.php', ]; $behaviour = << 0)) { $isFirstLine = false; if (\stripos($line, 'public function ') !== false || \stripos($line, 'public static function ') !== false) { // Check if a test exists for this function $testFile = \str_replace('.php', 'Test.php', $filename); $testFile = \str_replace('/phpOMS/', '/phpOMS/tests/', $filename); if (\stripos($testFile, '../Modules/') !== false) { $subdirectory = "tests/"; $position = strrpos($testFile, "/../"); if ($position !== false) { $position = \stripos($testFile, '/', $position + 4) + 1; $position = \stripos($testFile, '/', $position) + 1; $testFile = \substr_replace($testFile, $subdirectory, $position, 0); } } if (\file_exists($testFile)) { $scopeStart = true; $testContent = \file_get_contents($testFile); // Parse functio name $pattern = '/\bfunction\b\s+(\w+)\s*\(/'; \preg_match($pattern, $line, $matches); if (\stripos($testContent, $matches[1] ?? '~~~') !== false) { // Test already exists $scopeStart = false; } $scopeStart = true; } else { $scopeStart = false; } } // Not in a function / not relevant if (!$scopeStart) { continue; } if ($scopeStart) { $scopeCounter += \substr_count($line, '{'); $scopeCounter -= \substr_count($line, '}'); if ($scopeCounter === 0) { $scopeStart = false; } } $lines .= $line; } if ($isFirstLine && empty($lines)) { return false; } return $lines; }; foreach ($globs as $glob) { $files = \glob($glob); foreach ($files as $file) { if (\stripos($file, 'Test.php')) { continue; } $response = GptHelper::handleFile($file, 'php://memory', $behaviour, $fileReader); echo $response , \PHP_EOL , \PHP_EOL; } }