Completed
Push — master ( 913d72...675f80 )
by Wanderson
01:41
created

Directory   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 89
rs 10
c 0
b 0
f 0
wmc 15
lcom 1
cbo 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __toString() 0 3 1
A getPath() 0 3 1
A setPath() 0 3 1
A exists() 0 3 1
A create() 0 11 3
A rename() 0 7 2
A remove() 0 9 2
A removeAllFiles() 0 12 3
1
<?php
2
3
namespace Win\File;
4
5
use Win\Request\Server;
6
7
/**
8
 * Diretorio de arquivos
9
 */
10
class Directory {
11
12
	private $path;
13
14
	public function __construct($path) {
15
		$this->path = str_replace(['///', '//'], ['/', '/'], $path . '/');
16
	}
17
18
	public function __toString() {
19
		return $this->path;
20
	}
21
22
	public function getPath() {
23
		return $this->path;
24
	}
25
26
	public function setPath($path) {
27
		$this->path = $path;
28
	}
29
30
	/**
31
	 * Retorna TRUE se é um diretorio
32
	 * @return boolean
33
	 */
34
	public function exists(){
35
		return is_dir($this->path);
36
	}
37
38
	/**
39
	 * Cria o diretorio para salvar a imagem
40
	 * @param string $pathetorio Caminho do novo diretorio
0 ignored issues
show
Bug introduced by
There is no parameter named $pathetorio. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
41
	 * @param int $chmod permissões deste diretório
42
	 * @return boolean Retora TRUE caso obtenha algum sucesso
43
	 */
44
	public function create($chmod = 0755) {
45
		if (Server::isLocalHost()) {
46
			umask(0);
47
			$chmod = 0777;
48
		}
49
		if (!file_exists($this->path)) {
50
			$success = @mkdir($this->path, $chmod, STREAM_MKDIR_RECURSIVE);
51
			return $success;
52
		}
53
		return false;
54
	}
55
56
	/**
57
	 * Renomeia o diretorio
58
	 * @param string $newName Caminho para o novo diretorio
59
	 * @return boolean
60
	 */
61
	public function rename($newName) {
62
		if ($this->path != $newName) {
63
			rename($this->path, $newName);
64
			return true;
65
		}
66
		return false;
67
	}
68
69
	/**
70
	 * Exclui o diretorio, e os arquivos dentro dele
71
	 * @param string $path
0 ignored issues
show
Bug introduced by
There is no parameter named $path. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
72
	 * @return boolean
73
	 */
74
	public function remove() {
75
		$path = str_replace('//', '/', $this->path);
76
		if (is_dir($path)):
77
			$this->removeAllFiles();
78
			return rmdir($path);
79
		else:
80
			return false;
81
		endif;
82
	}
83
84
	/** Exclui os arquivos deste diretorio */
85
	protected function removeAllFiles() {
86
		$path = str_replace('//', '/', $this->path);
87
		$files = array_diff(scandir($path), ['.', '..']);
88
		foreach ($files as $file) {
89
			if (is_dir("$path/$file")) {
90
				$subDirectory = new Directory("$path/$file");
91
				$subDirectory->remove();
92
			} else {
93
				unlink("$path/$file");
94
			}
95
		}
96
	}
97
98
}
99