Completed
Push — master ( c383ac...a7fbb8 )
by Milan
01:52 queued 01:52
created

DocumentRoot   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A createAbsolutePath() 0 16 4
1
<?php
2
3
namespace h4kuna\Upload;
4
5
class DocumentRoot
6
{
7
8
	/** @var array */
9
	private $destinationDirs;
10
11
	/** @var string */
12
	private $default;
13
14
	public function __construct(array $destinationDirs)
15
	{
16
		$this->destinationDirs = $destinationDirs;
17
		reset($destinationDirs);
18
		$this->default = key($destinationDirs);
19
	}
20
21
	/**
22
	 * @param string|IStoreFile $relativePath
23
	 * @param string|NULL $destinationAlias
24
	 * @return string
25
	 */
26
	public function createAbsolutePath($relativePath, $destinationAlias = NULL)
27
	{
28
		if ($relativePath instanceof IStoreFile) {
29
			$relativePath = $relativePath->getRelativePath();
30
		}
31
32
		if ($destinationAlias === NULL) {
33
			$path = $this->destinationDirs[$this->default];
34
		} elseif (isset($this->destinationDirs[$destinationAlias])) {
35
			$path = $this->destinationDirs[$destinationAlias];
36
		} else {
37
			throw new InvalidArgumentException('Destination alias does not exists "' . $destinationAlias . '".');
38
		}
39
40
		return $path . DIRECTORY_SEPARATOR . $relativePath;
41
	}
42
43
}
44