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

LibreSign / libresign / 29262909935

13 Jul 2026 03:35PM UTC coverage: 67.478%. First build
29262909935

Pull #7893

github

web-flow
Merge 31bfcae04 into 57a067f6b
Pull Request #7893: fix: avoid stale autoload misses during upgrades

17 of 21 new or added lines in 1 file covered. (80.95%)

16115 of 23882 relevant lines covered (67.48%)

10.93 hits per line

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

80.95
/lib/Bootstrap/UpgradeSafeAutoloader.php
1
<?php
2

3
declare(strict_types=1);
4
/**
5
 * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
6
 * SPDX-License-Identifier: AGPL-3.0-or-later
7
 */
8

9
namespace OCA\Libresign\Bootstrap;
10

11
use Composer\Autoload\ClassLoader;
12

13
final class UpgradeSafeAutoloader {
14
        private const MIGRATION_NAMESPACE = 'OCA\\Libresign\\Migration\\';
15
        private const MIGRATION_GLOB = '/lib/Migration/Version*.php';
16

17
        /**
18
         * @var array<string, true>
19
         */
20
        private static array $registeredRoots = [];
21

22
        private function __construct() {
NEW
23
        }
×
24

25
        public static function register(ClassLoader $loader, string $appRoot): void {
26
                $normalizedRoot = rtrim($appRoot, DIRECTORY_SEPARATOR);
5✔
27
                if ($normalizedRoot === '' || isset(self::$registeredRoots[$normalizedRoot])) {
5✔
NEW
28
                        return;
×
29
                }
30

31
                $classMap = self::buildMigrationClassMap($normalizedRoot);
5✔
32
                if ($classMap !== []) {
5✔
33
                        $loader->addClassMap($classMap);
4✔
34
                }
35

36
                self::$registeredRoots[$normalizedRoot] = true;
5✔
37
        }
38

39
        public static function registerCurrentAppLoader(string $appRoot): void {
40
                $loader = self::findRegisteredLoader(rtrim($appRoot, DIRECTORY_SEPARATOR));
3✔
41
                if (!$loader instanceof ClassLoader) {
3✔
NEW
42
                        return;
×
43
                }
44

45
                self::register($loader, $appRoot);
3✔
46
        }
47

48
        /**
49
         * @return array<string, string>
50
         */
51
        private static function buildMigrationClassMap(string $appRoot): array {
52
                $migrationFiles = glob($appRoot . self::MIGRATION_GLOB);
5✔
53
                if (!is_array($migrationFiles)) {
5✔
NEW
54
                        return [];
×
55
                }
56

57
                $classMap = [];
5✔
58
                foreach ($migrationFiles as $migrationFile) {
5✔
59
                        $classMap[self::MIGRATION_NAMESPACE . basename($migrationFile, '.php')] = $migrationFile;
4✔
60
                }
61

62
                return $classMap;
5✔
63
        }
64

65
        private static function findRegisteredLoader(string $appRoot): ?ClassLoader {
66
                $vendorDir = $appRoot . '/vendor';
3✔
67

68
                return ClassLoader::getRegisteredLoaders()[$vendorDir] ?? null;
3✔
69
        }
70
}
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