1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Goose\Images; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Locally Stored Images |
7
|
|
|
* |
8
|
|
|
* @package Goose\Images |
9
|
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 |
10
|
|
|
*/ |
11
|
|
|
class LocallyStoredImage { |
12
|
|
|
/** |
13
|
|
|
* @param mixed[] $options |
14
|
|
|
*/ |
15
|
|
View Code Duplication |
public function __construct($options = []) { |
|
|
|
|
16
|
|
|
foreach ($options as $key => $value) { |
17
|
|
|
$method = 'set' . ucfirst($key); |
18
|
|
|
|
19
|
|
|
if (method_exists($this, $method)) { |
20
|
|
|
call_user_func([$this, $method], $value); |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* remove unnecessary tmp image files |
27
|
|
|
*/ |
28
|
|
|
public function __destruct() { |
29
|
|
|
unlink($this->getLocalFileName()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** @var string */ |
33
|
|
|
private $imgSrc = ''; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $imgSrc |
37
|
|
|
*/ |
38
|
|
|
public function setImgSrc($imgSrc) { |
39
|
|
|
$this->imgSrc = $imgSrc; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
public function getImgSrc() { |
46
|
|
|
return $this->imgSrc; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** @var string */ |
50
|
|
|
private $localFileName = ''; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $localFileName |
54
|
|
|
*/ |
55
|
|
|
public function setLocalFileName($localFileName) { |
56
|
|
|
$this->localFileName = $localFileName; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
public function getLocalFileName() { |
63
|
|
|
return $this->localFileName; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** @var string */ |
67
|
|
|
private $linkhash = ''; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $linkhash |
71
|
|
|
*/ |
72
|
|
|
public function setLinkhash($linkhash) { |
73
|
|
|
$this->linkhash = $linkhash; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function getLinkhash() { |
80
|
|
|
return $this->linkhash; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** @var int */ |
84
|
|
|
private $bytes = 0; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param int $bytes |
88
|
|
|
*/ |
89
|
|
|
public function setBytes($bytes) { |
90
|
|
|
$this->bytes = $bytes; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return int |
95
|
|
|
*/ |
96
|
|
|
public function getBytes() { |
97
|
|
|
return $this->bytes; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** @var string */ |
101
|
|
|
private $fileExtension = ''; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param string $fileExtension |
105
|
|
|
*/ |
106
|
|
|
public function setFileExtension($fileExtension) { |
107
|
|
|
$this->fileExtension = $fileExtension; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function getFileExtension() { |
114
|
|
|
return $this->fileExtension; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** @var int */ |
118
|
|
|
private $height = 0; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param int $height |
122
|
|
|
*/ |
123
|
|
|
public function setHeight($height) { |
124
|
|
|
$this->height = $height; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return int |
129
|
|
|
*/ |
130
|
|
|
public function getHeight() { |
131
|
|
|
return $this->height; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** @var int */ |
135
|
|
|
private $width = 0; |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param int $width |
139
|
|
|
*/ |
140
|
|
|
public function setWidth($width) { |
141
|
|
|
$this->width = $width; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return int |
146
|
|
|
*/ |
147
|
|
|
public function getWidth() { |
148
|
|
|
return $this->width; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.