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

daycry / maintenancemode / 25548350420

08 May 2026 09:28AM UTC coverage: 77.17% (+1.7%) from 75.492%
25548350420

push

github

daycry
docs: full docs/ tree and modernised README

README rewritten as a tight landing page (~115 lines, was 511):
- Three badge sections (Package / Quality / Community) matching the
  daycry/* convention, including per-workflow status badges for PHPUnit,
  PHPStan, Psalm, Rector, Code Style, CodeQL plus Coveralls.
- Highlights, install, quick start, plus a "Quality bar" table linking to
  each workflow file. Everything else is one click away in docs/.

New docs/ tree (16 files):
- README.md (index), installation, configuration, commands, bypass,
  filters-and-events, storage-drivers, architecture, security,
  troubleshooting, faq, upgrade, roadmap.
- examples/: basic-maintenance, scheduled-window, api-json-response,
  webhook-notifications (all functional today), multi-tenant and
  cdn-cloudflare (planned, with workarounds).

The previous README's misleading content has been removed:
- "v2.0.0 Latest" claim and the v1/v2 changelog block (superseded by
  CHANGELOG.md).
- setcookie('maintenance_bypass', 'your-secret-key', ...) snippet (the
  legacy cookie-bypass logic was effectively broken; v3 uses a 32-byte
  random cookie_value compared with hash_equals).
- mm:migrate --to=cache flag that never existed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

649 of 841 relevant lines covered (77.17%)

31.49 hits per line

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

36.0
/src/Libraries/MaintenanceStorage.php
1
<?php
2

3
namespace Daycry\Maintenance\Libraries;
4

5
use Daycry\Maintenance\Config\Maintenance as MaintenanceConfig;
6
use Daycry\Maintenance\DTO\MaintenanceData;
7
use Daycry\Maintenance\Storage\CacheStorage;
8
use Daycry\Maintenance\Storage\FileStorage;
9
use Daycry\Maintenance\Storage\StorageFactory;
10

11
/**
12
 * Backwards-compatible facade over the new Storage drivers.
13
 *
14
 * Existing callers (Controllers, Commands, tests) keep working unchanged:
15
 *   isActive(), getData(), save(array), remove(), clearAll(), migrateToCache()
16
 *
17
 * Internally this delegates to the right StorageInterface implementation
18
 * picked from $config (driver / useCache).
19
 */
20
class MaintenanceStorage
21
{
22
    private MaintenanceConfig $config;
23

24
    public function __construct(?MaintenanceConfig $config = null)
25
    {
26
        $this->config = $config ?? new MaintenanceConfig();
130✔
27
    }
28

29
    public function isActive(): bool
30
    {
31
        return StorageFactory::make($this->config)->isActive();
74✔
32
    }
33

34
    /**
35
     * Returns the maintenance window as a stdClass-style object so legacy
36
     * callers (e.g. Controllers/Maintenance.php) can keep using
37
     * `$data->cookie_name` etc. unchanged.
38
     */
39
    public function getData(): ?object
40
    {
41
        $data = StorageFactory::make($this->config)->getData();
68✔
42

43
        return $data === null ? null : (object) $data->toArray();
68✔
44
    }
45

46
    /**
47
     * @param array<string, mixed> $data
48
     */
49
    public function save(array $data): bool
50
    {
51
        return StorageFactory::make($this->config)->save(MaintenanceData::fromArray($data));
113✔
52
    }
53

54
    public function remove(): bool
55
    {
56
        return StorageFactory::make($this->config)->remove();
38✔
57
    }
58

59
    /**
60
     * Clear state from BOTH backends — useful when migrating between drivers
61
     * or when tests swap config mid-run.
62
     */
63
    public function clearAll(): bool
64
    {
65
        $cacheCleared = (new CacheStorage($this->config))->clearAll();
80✔
66
        $fileCleared  = (new FileStorage($this->config))->clearAll();
80✔
67

68
        return $cacheCleared && $fileCleared;
29✔
69
    }
70

71
    /**
72
     * Read maintenance data from FILE storage and write it to CACHE storage.
73
     * Returns false if the file does not exist or is corrupt.
74
     */
75
    public function migrateToCache(): bool
76
    {
77
        if (! $this->config->useCache) {
×
78
            return false;
×
79
        }
80

81
        $file = new FileStorage($this->config);
×
82
        $data = $file->getData();
×
83

84
        if ($data === null) {
×
85
            return file_exists($this->filePath()) === false;
×
86
        }
87

88
        $cache = new CacheStorage($this->config);
×
89
        if (! $cache->save($data)) {
×
90
            return false;
×
91
        }
92

93
        $file->remove();
×
94

95
        if ($this->config->enableLogging) {
×
96
            log_message('info', 'Maintenance data migrated from file to cache');
×
97
        }
98

99
        return true;
×
100
    }
101

102
    private function filePath(): string
103
    {
104
        helper('setting');
×
105

106
        return (setting('Maintenance.filePath') ?? $this->config->filePath)
×
107
            . (setting('Maintenance.fileName') ?? $this->config->fileName);
×
108
    }
109
}
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