Passed
Push — master ( 81d966...4376d2 )
by butschster
23:34 queued 15s
created

StorageSnapshotsBootloader   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 13
c 1
b 0
f 0
dl 0
loc 24
ccs 6
cts 9
cp 0.6667
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A storageSnapshot() 0 13 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Bootloader;
6
7
use Spiral\Boot\Bootloader\Bootloader;
8
use Spiral\Boot\EnvironmentInterface;
9
use Spiral\Core\FactoryInterface;
10
use Spiral\Snapshots\SnapshotterInterface;
11
use Spiral\Snapshots\StorageSnapshooter;
12
use Spiral\Snapshots\StorageSnapshot;
13
use Spiral\Storage\Bootloader\StorageBootloader;
14
15
/**
16
 * Depends on environment variables:
17
 * SNAPSHOTS_BUCKET: bucket name
18
 * SNAPSHOTS_DIRECTORY: where snapshots will be stored in the bucket
19
 * SNAPSHOT_VERBOSITY: defaults to {@see \Spiral\Exceptions\Verbosity::VERBOSE} (1)
20
 */
21
final class StorageSnapshotsBootloader extends Bootloader
22
{
23
    protected const DEPENDENCIES = [
24
        StorageBootloader::class,
25
    ];
26
27
    protected const SINGLETONS = [
28
        StorageSnapshot::class => [self::class, 'storageSnapshot'],
29
        SnapshotterInterface::class => StorageSnapshooter::class,
30
    ];
31
32 2
    private function storageSnapshot(EnvironmentInterface $env, FactoryInterface $factory): StorageSnapshot
33
    {
34 2
        $bucket = $env->get('SNAPSHOTS_BUCKET');
35
36 2
        if ($bucket === null) {
37
            throw new \RuntimeException(
38
                'Please, configure a bucket for storing snapshots using the environment variable `SNAPSHOTS_BUCKET`.'
39
            );
40
        }
41
42 2
        return $factory->make(StorageSnapshot::class, [
43 2
            'bucket' => $bucket,
44 2
            'directory' => $env->get('SNAPSHOTS_DIRECTORY', null),
45 2
        ]);
46
    }
47
}
48