Passed
Branch scrutinizer (56240a)
by Wanderson
01:48
created

Image::includeLibrary()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Win\File;
4
5
/**
6
 * Arquivos de Imagem
7
 *
8
 */
9
class Image extends File {
10
11
	protected static $validExtensions = ['jpg', 'jpeg', 'gif', 'png'];
12
13
	/* @overwrite */
14
15
	public function upload($newName = '') {
16
		$error = parent::upload($newName);
17
		if ($this->uploadPrepared && is_null($error)) {
18
			$error = $this->saveThumb();
19
		}
20
		return $error;
21
	}
22
23
	public function saveThumb() {
24
		return false;
25
	}
26
27
	public function __toString() {
28
		if ($this->getName() != '') {
29
			return parent::__toString();
30
		} else {
31
			return $this->getFullName();
32
		}
33
	}
34
35
	public function getFullName() {
36
		if ($this->getName() != '') {
37
			return parent::getFullName();
38
		} else {
39
			return $this->getDirectory() . 'default.png';
40
		}
41
	}
42
43
	public function removeOld() {
44
		$this->clearCache($this->getOldName());
45
		parent::removeOld();
46
	}
47
48
	public function remove() {
49
		$this->clearCache($this->getFullName());
50
		parent::remove();
51
	}
52
53
	/** Limpa imagens em cache */
54
	public function clearCache($name) {
55
		if ($this->exists()) {
56
			$dir = 'data/cache/thumb/*/*/';
57
			File::removeRegExp($dir . $name);
58
		}
59
	}
60
61
}
62