Completed
Push — master ( 981a91...dd2c56 )
by Wanderson
01:47
created

Image::includeLibrary()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A Image::getFullName() 0 7 2
1
<?php
2
3
namespace Win\File;
4
5
use PhpThumbFactory;
6
7
/**
8
 * Arquivos de Imagem
9
 *
10
 */
11
class Image extends File {
12
13
	const QUALITY = 70;
14
	const MAX_HEIGHT = 900;
15
	const MAX_WIDTH = 1200;
16
17
	protected static $validExtensions = ['jpg', 'jpeg', 'gif', 'png'];
18
19
	/* @overwrite */
20
21
	function upload($newName = '') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
22
		$error = parent::upload($newName);
23
		if ($this->uploadPrepared and is_null($error)) {
24
			$error = $this->saveThumb(self::MAX_WIDTH, self::MAX_HEIGHT);
0 ignored issues
show
Unused Code introduced by
The call to Image::saveThumb() has too many arguments starting with self::MAX_WIDTH.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
25
		}
26
		return $error;
27
	}
28
29
	/**
30
	 * Gera a miniatura
31
	 * @return string Retorna o caminho da thumb
32
	 * @param int $width largura
33
	 * @param int $height altura
34
	 * @param boolean $mode modo de corte
35
	 */
36
	function showThumb($width = 100, $height = 100, $mode = 'normal') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
37
		return "lib/thumb/" . $mode . '/' . $width . '/' . $height . '/' . $this->__toString();
38
	}
39
40
	/**
41
	 * Cria uma miniatura da imagem 
42
	 * @return string
43
	 */
44
	function saveThumb() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
45
		if (file_exists($this->getTempName())) {
46
			$thumb = PhpThumbFactory::create($this->getFullName());
47
			$thumb->resize(self::MAX_WIDTH, self::MAX_HEIGHT);
48
			$this->remove();
49
			$thumb->save($this->getFullName());
50
		}
51
		return null;
52
	}
53
54
	public function __toString() {
55
		if ($this->getName() != '') {
56
			return parent::__toString();
57
		} else {
58
			return $this->getFullName();
59
		}
60
	}
61
62
	public function getFullName() {
63
		if ($this->getName() != '') {
64
			return parent::getFullName();
65
		} else {
66
			return $this->getDirectory() . 'default.png';
67
		}
68
	}
69
70
	public function removeOld() {
71
		$this->clearCache($this->getOldName());
72
		parent::removeOld();
73
	}
74
75
	public function remove() {
76
		$this->clearCache($this->getFullName());
77
		parent::remove();
78
	}
79
80
	/** Limpa imagens em cache */
81
	public function clearCache($name) {
82
		if ($this->exists()) {
83
			$dir = 'data/cache/thumb/*/*/';
84
			File::removeRegExp($dir . $name);
85
		}
86
	}
87
88
}
89