Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
SystemStatusService
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 2
72
0.00% covered (danger)
0.00%
0 / 1
 getSystemStatus
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
56
 canProcessArticles
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Services;
4
5use App\Models\Feed;
6use App\Models\Route;
7use App\Models\PlatformChannel;
8use App\Models\Setting;
9
10class SystemStatusService
11{
12    /**
13     * @return array{is_enabled: bool, status: string, status_class: string, reasons: array<int, string>}
14     */
15    public function getSystemStatus(): array
16    {
17        $reasons = [];
18        $isEnabled = true;
19
20        if (!Setting::isArticleProcessingEnabled()) {
21            $isEnabled = false;
22            $reasons[] = 'Manually disabled by user';
23        }
24
25        if (!Feed::where('is_active', true)->exists()) {
26            $isEnabled = false;
27            $reasons[] = 'No active feeds configured';
28        }
29
30        if (!PlatformChannel::where('is_active', true)->exists()) {
31            $isEnabled = false;
32            $reasons[] = 'No active platform channels configured';
33        }
34
35        if (!Route::where('is_active', true)->exists()) {
36            $isEnabled = false;
37            $reasons[] = 'No active feed-to-channel routes configured';
38        }
39
40        return [
41            'is_enabled' => $isEnabled,
42            'status' => $isEnabled ? 'Enabled' : 'Disabled',
43            'status_class' => $isEnabled ? 'text-green-600' : 'text-red-600',
44            'reasons' => $reasons,
45        ];
46    }
47
48    public function canProcessArticles(): bool
49    {
50        return $this->getSystemStatus()['is_enabled'];
51    }
52}