Database   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 36
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 12 2
A __construct() 0 9 1
1
<?php declare(strict_types=1);
2
3
namespace PmgDev\DatabaseReplicator\Source;
4
5
use PmgDev\DatabaseReplicator\Command;
6
use PmgDev\DatabaseReplicator\Database as PDDatabase;
7
8
class Database
9
{
10
	/** @var PDDatabase\Prefix */
11
	private $prefix;
12
13
	/** @var Hash */
14
	private $sourceHash;
15
16
	/** @var Command */
17
	private $command;
18
19
20
	public function __construct(
21
		PDDatabase\Prefix $prefix,
22
		Hash $sourceHash,
23
		Command $command
24
	)
25
	{
26
		$this->prefix = $prefix;
27
		$this->sourceHash = $sourceHash;
28
		$this->command = $command;
29
	}
30
31
32
	public function build(): bool
33
	{
34
		$this->sourceHash->begin();
35
		$config = $this->prefix->config();
36
		if ($this->command->existsDatabase($config->database)) {
37
			$this->sourceHash->commit();
38
			return TRUE;
39
		}
40
		$this->command->create($config);
41
		$this->command->importFiles($this->sourceHash->getFiles(), $config);
42
		$this->sourceHash->commit();
43
		return FALSE;
44
	}
45
46
}
47