瀏覽代碼

chore: improve code quality configuration

- Adjust cyclomatic complexity threshold to 15
- Set CI complexity requirement to 80%
- Fix code style issues (spacing, imports, newlines)
- Clean up migration file formatting
Anankke 3 月之前
父節點
當前提交
a6f2cb2804

+ 1 - 1
.github/workflows/lint.yml

@@ -61,7 +61,7 @@ jobs:
             --no-interaction \
             --format=github-action \
             --min-quality=100 \
-            --min-complexity=100 \
+            --min-complexity=80 \
             --min-architecture=100 \
             --min-style=100
         continue-on-error: ${{ github.event_name == 'pull_request' }}

+ 5 - 5
db/migrations/2025070500-add_telemetry_config.php

@@ -9,21 +9,21 @@ return new class() implements MigrationInterface {
     public function up(): int
     {
         $db = DB::getPdo();
-        
+
         $db->exec("
             INSERT IGNORE INTO `config` (`item`, `value`, `class`, `is_public`, `type`, `default`, `mark`)
             VALUES ('enable_telemetry', '1', 'system', '0', 'bool', '1', '系统遥测统计')
         ");
-        
+
         return 2025070500;
     }
-    
+
     public function down(): int
     {
         $db = DB::getPdo();
 
         $db->exec("DELETE FROM `config` WHERE `item` = 'enable_telemetry'");
-        
+
         return 2024040500;
     }
-};
+};

+ 11 - 2
phpinsights.php

@@ -6,7 +6,6 @@ return [
     'preset' => 'default',
     'remove' => [
         NunoMaduro\PhpInsights\Domain\Sniffs\ForbiddenSetterSniff::class,
-        NunoMaduro\PhpInsights\Domain\Insights\CyclomaticComplexityIsHigh::class,
         NunoMaduro\PhpInsights\Domain\Insights\ForbiddenDefineFunctions::class,
         NunoMaduro\PhpInsights\Domain\Insights\ForbiddenDefineGlobalConstants::class,
         NunoMaduro\PhpInsights\Domain\Insights\ForbiddenGlobals::class,
@@ -31,7 +30,17 @@ return [
         SlevomatCodingStandard\Sniffs\TypeHints\PropertyTypeHintSniff::class,
         SlevomatCodingStandard\Sniffs\Variables\UnusedVariableSniff::class,
     ],
-    'config' => [],
+    'config' => [
+        NunoMaduro\PhpInsights\Domain\Insights\CyclomaticComplexityIsHigh::class => [
+            'maxComplexity' => 15,
+        ],
+        NunoMaduro\PhpInsights\Domain\Insights\ClassMethodAverageCyclomaticComplexityIsHigh::class => [
+            'maxComplexity' => 10,
+        ],
+        NunoMaduro\PhpInsights\Domain\Insights\MethodCyclomaticComplexityIsHigh::class => [
+            'maxComplexity' => 15,
+        ],
+    ],
 
     'exclude' => [
         'storage',

+ 0 - 1
src/Command/Migration.php

@@ -8,7 +8,6 @@ use App\Interfaces\MigrationInterface;
 use App\Models\Config;
 use App\Services\DB;
 use function count;
-use function explode;
 use function is_numeric;
 use function krsort;
 use function ksort;

+ 2 - 2
src/Services/Config/ClientConfig.php

@@ -12,7 +12,7 @@ final class ClientConfig
     {
         if (self::$config === null) {
             $file = BASE_PATH . '/config/client_display.json';
-            if (!is_readable($file)) {
+            if (! is_readable($file)) {
                 throw new \RuntimeException("Client config file not found: {$file}");
             }
 
@@ -49,4 +49,4 @@ final class ClientConfig
 
         return ['clients' => $result, 'icons' => self::$config['icons']];
     }
-}
+}