Test Setup Failed
Push — master ( 9b017d...5cb4e7 )
by Milan
02:16
created

LocalFilesystem   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 38
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A save() 0 4 1
A createURI() 0 7 2
A isFileExists() 0 4 1
A createName() 0 4 1
A remove() 0 4 1
1
<?php
2
3
namespace h4kuna\Upload\Driver;
4
5
use h4kuna\Upload,
6
	Nette\Http;
7
8
class LocalFilesystem implements Upload\IDriver
9
{
10
	/** @var string */
11
	private $destinationDir;
12
13
	public function __construct($destinationDir)
14
	{
15
		$this->destinationDir = $destinationDir;
16
	}
17
18
	public function save(Http\FileUpload $fileUpload, $relativePath)
19
	{
20
		$fileUpload->move($this->createURI($relativePath));
21
	}
22
23
	public function createURI($relativePath)
24
	{
25
		if ($relativePath instanceof Upload\IStoreFile) {
26
			$relativePath = $relativePath->getRelativePath();
27
		}
28
		return $this->destinationDir . DIRECTORY_SEPARATOR . $relativePath;
29
	}
30
31
	public function isFileExists($relativePath)
32
	{
33
		return is_file($this->createURI($relativePath));
34
	}
35
36
	public function createName(Http\FileUpload $fileUpload)
37
	{
38
		return NULL;
39
	}
40
41
	public function remove($relativePath)
42
	{
43
		return @unlink($this->createURI($relativePath));
44
	}
45
}