DBCleanerConfigFactory::prepareQueriesConfig()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 17
ccs 10
cts 10
cp 1
crap 4
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\Cleaner\DB\Config;
6
7
class DBCleanerConfigFactory
8
{
9 10
    public static function create(array $config): DBCleanerConfig
10
    {
11
        $params = [
12 10
            'transactional' => $config['transactional'] ?? true,
13
        ];
14
15 10
        if (isset($config['query'])) {
16 4
            $params['queries'] = static::prepareQueriesConfig([$config]);
17
        } else {
18 6
            $params['queries'] = static::prepareQueriesConfig($config['queries'] ?? []);
19
        }
20
21 9
        return new DBCleanerConfig($params);
22
    }
23
24
    /**
25
     * @param array $configList
26
     *
27
     * @return QueryConfig[]
28
     */
29 10
    private static function prepareQueriesConfig(array $configList): array
30
    {
31 10
        $result = [];
32
33 10
        foreach ($configList as $item) {
34 10
            if (!isset($item['query']) || !is_string($item['query'])) {
35 1
                throw new \InvalidArgumentException('Not found query for DB cleaner config');
36
            }
37
38 9
            $result[] = new QueryConfig(
39 9
                $item['query'],
40 9
                $item['parameters'] ?? [],
41 9
                $item['types'] ?? []
42
            );
43
        }
44
45 9
        return $result;
46
    }
47
}
48