Completed
Push — master ( 326b3e...061c53 )
by Freek
09:13
created

BackupJobFactory::getDbDumpers()   C

Complexity

Conditions 13
Paths 1

Size

Total Lines 54
Code Lines 37

Duplication

Lines 38
Ratio 70.37 %

Importance

Changes 0
Metric Value
cc 13
eloc 37
nc 1
nop 1
dl 38
loc 54
rs 6.7593
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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['followLinks']) && $sourceFiles['followLinks']);
23
    }
24
25
    protected static function createDbDumpers(array $dbConnectionNames): Collection
26
    {
27
        return collect($dbConnectionNames)->map(function (string $dbConnectionName) {
28
            return DbDumperFactory::createFromConnection($dbConnectionName);
29
        });
30
    }
31
}
32