BackupJobFactory::createDbDumpers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Backup\Tasks\Backup;
4
5
use Illuminate\Support\Collection;
6
use Spatie\Backup\BackupDestination\BackupDestinationFactory;
7
8
class BackupJobFactory
9
{
10
    public static function createFromArray(array $config): BackupJob
11
    {
12
        return (new BackupJob())
13
            ->setFileSelection(static::createFileSelection($config['backup']['source']['files']))
14
            ->setDbDumpers(static::createDbDumpers($config['backup']['source']['databases']))
15
            ->setBackupDestinations(BackupDestinationFactory::createFromArray($config['backup']));
16
    }
17
18
    protected static function createFileSelection(array $sourceFiles): FileSelection
19
    {
20
        return FileSelection::create($sourceFiles['include'])
21
            ->excludeFilesFrom($sourceFiles['exclude'])
22
            ->shouldFollowLinks(isset($sourceFiles['follow_links']) && $sourceFiles['follow_links']);
23
    }
24
25
    protected static function createDbDumpers(array $dbConnectionNames): Collection
26
    {
27
        return collect($dbConnectionNames)->mapWithKeys(function (string $dbConnectionName) {
28
            return [$dbConnectionName=>DbDumperFactory::createFromConnection($dbConnectionName)];
29
        });
30
    }
31
}
32