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

tito10047 / migration-backup / 22960036080

11 Mar 2026 03:19PM UTC coverage: 66.667%. First build
22960036080

push

github

web-flow
Merge pull request #1 from tito10047/v2

Create brand new version

108 of 165 new or added lines in 14 files covered. (65.45%)

120 of 180 relevant lines covered (66.67%)

28.58 hits per line

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

42.86
/src/Storage/LocalStorageProvider.php
1
<?php
2

3
namespace Tito10047\MigrationBackup\Storage;
4

5
use Symfony\Component\Filesystem\Filesystem;
6

7
class LocalStorageProvider implements StorageProviderInterface {
8
        public function __construct(
9
                private readonly Filesystem $fs,
10
                private readonly string     $backupPath,
11
        ) {}
42✔
12

13
        public function store(string $sourcePath, string $targetFilename): string {
14
                if (!$this->fs->exists($this->backupPath)) {
42✔
15
                        $this->fs->mkdir($this->backupPath);
42✔
16
                }
17

18
                $targetPath = rtrim($this->backupPath, '/') . '/' . $targetFilename;
42✔
19

20
                if ($sourcePath !== $targetPath) {
42✔
21
                        $this->fs->copy($sourcePath, $targetPath, true);
42✔
22
                }
23

24
                return $targetPath;
42✔
25
        }
26

27
        public function cleanup(string $connectionName, int $keepLastN): void {
28
                if ($keepLastN <= 0) {
21✔
29
                        return;
21✔
30
                }
31

NEW
32
                if (!$this->fs->exists($this->backupPath)) {
×
NEW
33
                        return;
×
34
                }
35

NEW
36
                $pattern = rtrim($this->backupPath, '/') . '/' . $connectionName . '-*';
×
NEW
37
                $files   = glob($pattern);
×
38

NEW
39
                if ($files === false || count($files) <= $keepLastN) {
×
NEW
40
                        return;
×
41
                }
42

43
                // Sort by modification time, newest first
NEW
44
                usort($files, function ($a, $b) {
×
NEW
45
                        return filemtime($b) <=> filemtime($a);
×
NEW
46
                });
×
47

NEW
48
                $filesToDelete = array_slice($files, $keepLastN);
×
49

NEW
50
                foreach ($filesToDelete as $file) {
×
NEW
51
                        $this->fs->remove($file);
×
52
                }
53
        }
54
}
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