SizeDriverFactory   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 54
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 18 5
A addDriver() 0 3 1
A getInitializedDrivers() 0 4 1
A getInitializationExceptions() 0 4 1
1
<?php
2
3
namespace BigFileTools\Driver;
4
5
class SizeDriverFactory
6
{
7
	/**
8
	 * @var ISizeDriver[]
9
	 */
10
	private $drivers = [];
11
12
	/**
13
	 * @var Exception[]
14
	 */
15
	private $exceptions = [];
16
17
	/**
18
	 * @param string[]|callable[] $drivers names of classes to build
19
	 */
20
	public function __construct(array $drivers)
21
	{
22
		foreach($drivers as $driver) {
23
			try{
24
				if(is_callable($driver)) {
25
					$this->addDriver($driver());
26
27
				} else if(class_exists($driver)) {
28
					$this->addDriver(new $driver());
29
30
				} else {
31
					throw new Exception("Driver $driver cannot be initialized.");
32
				}
33
			} catch (Exception $driverException) {
34
				$this->exceptions[] = $driverException;
35
			}
36
		}
37
	}
38
39
	private function addDriver(ISizeDriver $driver) {
40
		$this->drivers[] = $driver;
41
	}
42
43
	/**
44
	 * @return ISizeDriver[]
45
	 */
46
	public function getInitializedDrivers()
47
	{
48
		return $this->drivers;
49
	}
50
51
	/**
52
	 * @return Exception[]
53
	 */
54
	public function getInitializationExceptions()
55
	{
56
		return $this->exceptions;
57
	}
58
}
59