Completed
Push — master ( c7b167...faaa80 )
by Wanderson
02:08
created

Directory   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 0
dl 0
loc 79
rs 10
c 0
b 0
f 0

8 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 create() 0 9 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
/**
6
 * Diretorio de arquivos
7
 */
8
class Directory {
9
10
	private $path;
11
12
	public function __construct($path) {
13
		$this->path = str_replace(['///', '//'], ['/', '/'], $path . '/');
14
	}
15
16
	public function __toString() {
17
		return $this->path;
18
	}
19
20
	public function getPath() {
21
		return $this->path;
22
	}
23
24
	public function setPath($path) {
25
		$this->path = $path;
26
	}
27
28
	/**
29
	 * Cria o diretorio para salvar a imagem
30
	 * @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...
31
	 * @param int $chmod permissões deste diretório
32
	 * @return boolean Retora TRUE caso obtenha algum sucesso
33
	 */
34
	public function create($chmod = '0755') {
35
		if (file_exists($this->path)) {
36
			return false;
37
		} elseif (!@mkdir($this->path, $chmod)) {
38
			return false;
39
		} else {
40
			return true;
41
		}
42
	}
43
44
	/**
45
	 * Renomeia o diretorio
46
	 * @param string $newName Caminho para o novo diretorio
47
	 * @return boolean
48
	 */
49
	public function rename($newName) {
50
		if ($this->path != $newName) {
51
			rename($this->path, $newName);
52
			return true;
53
		}
54
		return false;
55
	}
56
57
	/**
58
	 * Exclui o diretorio, e os arquivos dentro dele
59
	 * @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...
60
	 * @return boolean
61
	 */
62
	public function remove() {
63
		$path = str_replace('//', '/', $this->path);
64
		if (is_dir($path)):
65
			$this->removeAllFiles();
66
			return rmdir($path);
67
		else:
68
			return false;
69
		endif;
70
	}
71
72
	/** Exclui os arquivos deste diretorio */
73
	protected function removeAllFiles() {
74
		$path = str_replace('//', '/', $this->path);
75
		$files = array_diff(scandir($path), ['.', '..']);
76
		foreach ($files as $file) {
77
			if (is_dir("$path/$file")) {
78
				$subDirectory = new Directory("$path/$file");
79
				$subDirectory->remove();
80
			} else {
81
				unlink("$path/$file");
82
			}
83
		}
84
	}
85
86
}
87