• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

visavi / rotor / 26541133708

27 May 2026 09:56PM UTC coverage: 14.548% (-0.04%) from 14.587%
26541133708

push

github

visavi
Поправил обновление модуля, добавил ошибки при конфликте модулей, обновление рееста и скачивание файла

0 of 29 new or added lines in 3 files covered. (0.0%)

8 existing lines in 2 files now uncovered.

872 of 5994 relevant lines covered (14.55%)

1.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/Models/ModuleRegistry.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Models;
6

7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Support\Facades\Http;
9

10
/**
11
 * @property int                 $id
12
 * @property string              $url
13
 * @property string              $name
14
 * @property bool                $active
15
 * @property array               $cached_data
16
 * @property \Carbon\Carbon|null $cached_at
17
 * @property \Carbon\Carbon      $created_at
18
 * @property \Carbon\Carbon      $updated_at
19
 */
20
class ModuleRegistry extends Model
21
{
22
    protected $guarded = [];
23

24
    protected function casts(): array
×
25
    {
26
        return [
×
27
            'active'      => 'bool',
×
28
            'cached_data' => 'array',
×
29
            'cached_at'   => 'datetime',
×
30
        ];
×
31
    }
32

33
    /**
34
     * Fetches the data from the registry.
35
     */
36
    public bool $fetchFailed = false;
37

UNCOV
38
    public function fetch(bool $force = false): array
×
39
    {
40
        $ttl = 3600;
×
41

42
        if (! $force && $this->cached_data && $this->cached_at?->gt(now()->subSeconds($ttl))) {
×
43
            return $this->cached_data;
×
44
        }
45

46
        try {
47
            $response = Http::timeout(10)->get($this->url);
×
48

49
            if (! $response->ok()) {
×
NEW
50
                $this->fetchFailed = true;
×
51

UNCOV
52
                return $this->cached_data ?? [];
×
53
            }
54

55
            $data = $response->json();
×
56

57
            if (! is_array($data)) {
×
NEW
58
                $this->fetchFailed = true;
×
59

UNCOV
60
                return $this->cached_data ?? [];
×
61
            }
62

63
            $this->update([
×
64
                'name'        => $data['name'] ?? $this->name,
×
65
                'cached_data' => $data,
×
66
                'cached_at'   => now(),
×
67
            ]);
×
68

69
            return $data;
×
70
        } catch (\Exception) {
×
NEW
71
            $this->fetchFailed = true;
×
72

UNCOV
73
            return $this->cached_data ?? [];
×
74
        }
75
    }
76

77
    /**
78
     * Returns an array of available modules.
79
     */
80
    public static function getAvailableModules(bool $force = false): array
×
81
    {
82
        $registries = self::query()->where('active', true)->get();
×
83
        $modules = [];
×
84

85
        foreach ($registries as $registry) {
×
86
            $data = $registry->fetch($force);
×
NEW
87
            $registryLabel = $registry->name ?: $registry->url;
×
88

89
            foreach ($data['modules'] ?? [] as $module) {
×
90
                if (! isset($module['module'])) {
×
91
                    continue;
×
92
                }
93

94
                $name = $module['module'];
×
95

NEW
96
                if (isset($modules[$name])) {
×
NEW
97
                    $modules[$name]['conflict'][] = $registryLabel;
×
NEW
98
                    continue;
×
99
                }
100

101
                $versions = $module['versions'] ?? [];
×
102
                $best = self::bestCompatibleVersion($versions);
×
103
                $latest = $versions[0] ?? [];
×
104
                $version = $best ?? $latest;
×
105

NEW
106
                $extra = ['registry' => $registryLabel, 'conflict' => []];
×
107

108
                if ($best && isset($latest['version']) && version_compare($latest['version'], $best['version'], '>')) {
×
109
                    $extra['latest_version'] = $latest['version'];
×
110
                    $extra['latest_requires'] = $latest['requires'] ?? null;
×
111
                }
112

113
                $modules[$name] = array_merge(
×
114
                    array_diff_key($module, ['versions' => true]),
×
115
                    $version,
×
116
                    $extra,
×
117
                );
×
118
            }
119
        }
120

121
        return $modules;
×
122
    }
123

124
    /**
125
     * Returns the best compatible version of a module.
126
     */
127
    private static function bestCompatibleVersion(array $versions): ?array
×
128
    {
129
        $compatible = array_filter(
×
130
            $versions,
×
131
            static fn (array $v) => empty($v['requires']) || version_compare(ROTOR_VERSION, $v['requires'], '>='),
×
132
        );
×
133

134
        if (empty($compatible)) {
×
135
            return null;
×
136
        }
137

138
        usort($compatible, static fn ($a, $b) => version_compare($b['version'], $a['version']));
×
139

140
        return $compatible[0];
×
141
    }
142
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc