Completed
Push — master ( 6d76b9...ae9e08 )
by Jan
04:18 queued 01:39
created

SizeDriverFactory::getInitializationExceptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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