Completed
Push — master ( c291b9...165178 )
by Ron
01:19
created

SqliteBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setMethodInvoker() 0 4 1
A build() 0 5 1
1
<?php
2
namespace Kir\Services\Cmd\Dispatcher\Builder;
3
4
use Ioc\MethodInvoker;
5
use Kir\Services\Cmd\Dispatcher\AttributeRepositories\SqliteAttributeRepository;
6
use Kir\Services\Cmd\Dispatcher\Dispatchers\DefaultDispatcher;
7
use PDO;
8
9
class SqliteBuilder {
10
	/** @var string */
11
	private $filename;
12
	/** @var MethodInvoker|null */
13
	private $methodInvoker;
14
	
15
	/**
16
	 * @param string $filename
17
	 */
18
	public function __construct(string $filename) {
19
		$this->filename = $filename;
20
	}
21
	
22
	/**
23
	 * This can be used to enable automatic provisioning of DI objects when service methods are called. (Autowiring)
24
	 *
25
	 * @param MethodInvoker|null $methodInvoker
26
	 * @return $this
27
	 */
28
	public function setMethodInvoker(MethodInvoker $methodInvoker = null): self {
29
		$this->methodInvoker = $methodInvoker;
30
		return $this;
31
	}
32
	
33
	/**
34
	 * @return DefaultDispatcher
35
	 */
36
	public function build(): DefaultDispatcher {
37
		$pdo = new PDO(sprintf('sqlite:%s', $this->filename));
38
		$repos = new SqliteAttributeRepository($pdo);
39
		return new DefaultDispatcher($repos, $this->methodInvoker);
40
	}
41
}