Passed
Branch tests1.5 (81ba23)
by Wanderson
01:11
created

Uploader::prepare()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Win\File;
4
5
/**
6
 * Auxilia fazer upload de Arquivos
7
 */
8
class Uploader {
9
10
	/** @var Directory */
11
	protected $directory;
12
13
	/** @var File */
14
	protected $file;
15
16
	/** @var File */
17
	protected $temp;
18
19
	public function __construct(Directory $directory) {
20
		$this->directory = $directory;
21
	}
22
23
	/** @return File */
24
	public function getFile() {
25
		return $this->file;
26
	}
27
28
	public function prepare($file) {
29
		$success = false;
30
		$this->temp = null;
31
		if (isset($_FILES[$file]) && isset($_FILES[$file]['name'])) {
32
			$success = true;
33
			$this->temp = new File($_FILES[$file]['tmp_name']);
34
		}
35
		return $success;
36
	}
37
38
	public function upload($newName = null) {
39
		$success = false;
40
		$this->file = null;
41
		if (!is_null($this->temp) && $this->temp->exists()) {
42
			$success = true;
43
			$this->temp->move($this->directory);
44
			$this->file = clone $this->temp;
45
			if ($newName) {
46
				$this->file->rename($newName);
47
				var_dump($this->file->getPath());
0 ignored issues
show
Security Debugging Code introduced by
var_dump($this->file->getPath()) looks like debug code. Are you sure you do not want to remove it?
Loading history...
48
			}
49
		}
50
		return $success;
51
	}
52
53
}
54