diff --git a/Config/rector.php b/Config/rector.php new file mode 100644 index 0000000..6b3671a --- /dev/null +++ b/Config/rector.php @@ -0,0 +1,42 @@ +paths([ + __DIR__ . '/Model', + __DIR__ . '/Modules', + __DIR__ . '/phpOMS', + ]); + + // register a single rule + $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); + + $rectorConfig->sets([ + SetList::CODE_QUALITY, + ]); + + $rectorConfig->skip([ + SimplifyEmptyCheckOnEmptyArrayRector::class, + FlipTypeControlToUseExclusiveTypeRector::class, + UnusedForeachValueToArrayKeysRector::class, + ReturnBinaryAndToEarlyReturnRector::class, + SimplifyRegexPatternRector::class, + RemoveAlwaysElseRector::class, + OptionalParametersAfterRequiredRector::class, + RemoveExtraParametersRector::class, + CompleteDynamicPropertiesRector::class, + ]); +}; diff --git a/Helper/install.sh b/Helper/install.sh index bc8664e..37130b3 100755 --- a/Helper/install.sh +++ b/Helper/install.sh @@ -13,7 +13,7 @@ add-apt-repository ppa:ondrej/php apt-get update -apt-get install npm git composer cmake php8.1 php8.1-dev php8.1-cli php8.1-common php8.1-mysql php8.1-pgsql php8.1-xdebug php8.1-opcache php8.1-pdo php8.1-sqlite php8.1-mbstring php8.1-curl php8.1-imap php8.1-bcmath php8.1-zip php8.1-dom php8.1-xml php8.1-phar php8.1-gd php-pear apache2 mysql-server postgresql postgresql-contrib pcov +apt-get install npm git composer cmake php8.1 php8.1-dev php8.1-cli php8.1-common php8.1-mysql php8.1-pgsql php8.1-xdebug php8.1-opcache php8.1-pdo php8.1-sqlite php8.1-mbstring php8.1-curl php8.1-imap php8.1-bcmath php8.1-zip php8.1-dom php8.1-xml php8.1-phar php8.1-gd php-pear apache2 mysql-server postgresql postgresql-contrib pcov xvfb cutycapt # USE mysql; # mysql < 5.7 diff --git a/Tools/AutoGpt/GptHelper.php b/Tools/AutoGpt/GptHelper.php index b134c75..fc1f11d 100644 --- a/Tools/AutoGpt/GptHelper.php +++ b/Tools/AutoGpt/GptHelper.php @@ -9,7 +9,7 @@ use phpOMS\Uri\HttpUri; class GptHelper { private const ENDPOINT = 'https://api.openai.com/v1/chat/completions'; - private const APIKEY = ''; + private const APIKEY = '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'; private const MODEL = 'gpt-3.5-turbo'; private const TEMPERATUR = 0.9; private const MAX_TOKENS = 1700; @@ -66,7 +66,7 @@ class GptHelper || \stripos($response->getBody(), '503 Service') !== false ); - return \str_replace('```', '', $response->getBody()); + return $response->getBody(); } public static function handleFile(string $inPath, string $outPath, string $behavior, \Closure $fileReader, bool $bulk = true) : string @@ -94,6 +94,10 @@ class GptHelper continue; } + if(\stripos($outPath, '.php') !== false) { + $response = \str_replace('```', '', $response); + } + $json = \json_decode($response, true); \fwrite($out, $json[5][0]['message']['content']); \fwrite($out, "\n"); @@ -110,6 +114,10 @@ class GptHelper $response = self::aiRequest($behavior, $lines); if ($response !== '' && $response !== false) { + if(\stripos($outPath, '.php') !== false) { + $response = \str_replace('```', '', $response); + } + $json = \json_decode($response, true); \fwrite($out, $json[5][0]['message']['content']); \fwrite($out, "\n"); diff --git a/Tools/AutoGpt/autoDevDoc.php b/Tools/AutoGpt/autoDevDoc.php new file mode 100644 index 0000000..93600bc --- /dev/null +++ b/Tools/AutoGpt/autoDevDoc.php @@ -0,0 +1,60 @@ + 1300) { + return false; + } + + $lines = ''; + $isFirstLine = true; + + while (($line = \fgets($in)) !== false) { + $isFirstLine = false; + $lines .= $line; + } + + if ($isFirstLine && empty($lines)) { + return false; + } + + return $lines; +}; + +$output = __DIR__ . '/../../../doc.md'; +$md = \fopen($output, 'w'); + +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); + + if (\trim($response) !== '') { + \fwrite($md, $file . ":\n"); + \fwrite($md, $response); + \fwrite($md, "\n\n"); + } + } +} + +\fclose($md); \ No newline at end of file diff --git a/Tools/AutoGpt/autoGpt.php b/Tools/AutoGpt/autoGpt.php deleted file mode 100644 index c96e175..0000000 --- a/Tools/AutoGpt/autoGpt.php +++ /dev/null @@ -1,268 +0,0 @@ - 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, false); - 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; - } -} \ No newline at end of file