BackupJobFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromArray() 0 7 1
A createFileSelection() 0 6 2
A createDbDumpers() 0 6 1
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