1 | <?php namespace Simondubois\UnsplashDownloader; |
||
10 | class Task |
||
11 | { |
||
12 | |||
13 | // |
||
14 | // Constants |
||
15 | // |
||
16 | |||
17 | /** |
||
18 | * Notification types |
||
19 | */ |
||
20 | const NOTIFY_INFO = 'info'; |
||
21 | const NOTIFY_COMMENT = 'comment'; |
||
22 | const NOTIFY_ERROR = 'error'; |
||
23 | |||
24 | /** |
||
25 | * Download status |
||
26 | */ |
||
27 | const DOWNLOAD_SUCCESS = 0; |
||
28 | const DOWNLOAD_SKIPPED = 1; |
||
29 | const DOWNLOAD_FAILED = 2; |
||
30 | |||
31 | |||
32 | |||
33 | // |
||
34 | // Attributes |
||
35 | // |
||
36 | |||
37 | /** |
||
38 | * History proxy |
||
39 | * @var History |
||
40 | */ |
||
41 | private $history; |
||
42 | |||
43 | /** |
||
44 | * Callback to call when notification arised : function ($message, $level = null) {}; |
||
45 | * @var callable |
||
46 | */ |
||
47 | private $notificationCallback; |
||
48 | |||
49 | /** |
||
50 | * Path where to download photos |
||
51 | * @var string |
||
52 | */ |
||
53 | private $destination; |
||
54 | |||
55 | /** |
||
56 | * Number of photos to download |
||
57 | * @var int |
||
58 | */ |
||
59 | private $quantity; |
||
60 | |||
61 | /** |
||
62 | * Category ID |
||
63 | * @var int |
||
64 | */ |
||
65 | private $category; |
||
66 | |||
67 | /** |
||
68 | * True if the task should only download featured photos |
||
69 | * @var bool |
||
70 | */ |
||
71 | private $featured; |
||
72 | |||
73 | |||
74 | |||
75 | // |
||
76 | // Getters |
||
77 | // |
||
78 | |||
79 | /** |
||
80 | * Get history proxy attribute. Instantiate it if null |
||
81 | * @return History Instance |
||
82 | */ |
||
83 | 18 | public function getHistoryInstance() |
|
91 | |||
92 | /** |
||
93 | * Get notification callback attribute |
||
94 | * @return callable function ($message, $level = null) {} |
||
95 | */ |
||
96 | 1 | public function getNotificationCallback() |
|
100 | |||
101 | /** |
||
102 | * Get destination attribute |
||
103 | * @return string Path to folder |
||
104 | */ |
||
105 | 1 | public function getDestination() |
|
109 | |||
110 | /** |
||
111 | * Get quantity attribute |
||
112 | * @return int Number of photos to download |
||
113 | */ |
||
114 | 1 | public function getQuantity() |
|
118 | |||
119 | /** |
||
120 | * Get category attribute |
||
121 | * @return int Category ID |
||
122 | */ |
||
123 | 1 | public function getCategory() |
|
127 | |||
128 | /** |
||
129 | * Get featured attribute |
||
130 | * @return bool True if the task should only download featured photos |
||
131 | */ |
||
132 | 2 | public function getFeatured() |
|
136 | |||
137 | /** |
||
138 | * Get history path attribute |
||
139 | * @return string Path to file |
||
140 | */ |
||
141 | 1 | public function getHistory() |
|
145 | |||
146 | |||
147 | |||
148 | // |
||
149 | // Setters |
||
150 | // |
||
151 | |||
152 | /** |
||
153 | * Task constructor (set non scalar attributes) |
||
154 | */ |
||
155 | 22 | public function __construct() |
|
160 | |||
161 | /** |
||
162 | * Set notification callback attribute |
||
163 | * @param callable $notificationCallback function ($message, $level = null) {} |
||
164 | */ |
||
165 | 3 | public function setNotificationCallback($notificationCallback) |
|
169 | |||
170 | /** |
||
171 | * Set destination attribute |
||
172 | * @param string $destination Path to folder |
||
173 | */ |
||
174 | 3 | public function setDestination($destination) |
|
178 | |||
179 | /** |
||
180 | * Set quantity attribute |
||
181 | * @param int $quantity Number of photos to download |
||
182 | */ |
||
183 | 6 | public function setQuantity($quantity) |
|
187 | |||
188 | /** |
||
189 | * Set category attribute |
||
190 | * @param int $category Number of photos to download |
||
191 | */ |
||
192 | 2 | public function setCategory($category) |
|
196 | |||
197 | /** |
||
198 | * Set featured attribute |
||
199 | * @param bool $featured True if the task should only download featured photos |
||
200 | */ |
||
201 | 2 | public function setFeatured($featured) |
|
205 | |||
206 | /** |
||
207 | * Set path attribute in history instance |
||
208 | * @param string $history Path to file |
||
209 | */ |
||
210 | 1 | public function setHistory($history) |
|
214 | |||
215 | |||
216 | |||
217 | // |
||
218 | // Notification |
||
219 | // |
||
220 | |||
221 | /** |
||
222 | * Call the notification callback when a notification arised |
||
223 | * @param string $message Message text |
||
224 | * @param string|null $level Message context |
||
225 | */ |
||
226 | 1 | public function notify($message, $level = null) |
|
231 | |||
232 | |||
233 | |||
234 | // |
||
235 | // Execution |
||
236 | // |
||
237 | |||
238 | /** |
||
239 | * Find photos and download them |
||
240 | * @return bool True if the execution is successful |
||
241 | */ |
||
242 | 1 | public function download() |
|
252 | |||
253 | /** |
||
254 | * List categories |
||
255 | * @return bool True if the execution is successful |
||
256 | */ |
||
257 | 1 | public function categories() |
|
263 | |||
264 | /** |
||
265 | * Request APi to get photos to downloads |
||
266 | * @param Unsplash $unsplash Proxy to Unsplash API |
||
267 | * @return string[] Photo download links indexed by ID |
||
268 | */ |
||
269 | 3 | public function getPhotos(Unsplash $unsplash) { |
|
283 | |||
284 | /** |
||
285 | * Download all photos |
||
286 | * @param string[] $photos Photo download links indexed by ID |
||
287 | * @return boolean True if all downloads are successful |
||
288 | */ |
||
289 | 2 | public function downloadAllPhotos($photos) |
|
301 | |||
302 | /** |
||
303 | * Download one photo |
||
304 | * @param string $id Photo id |
||
305 | * @param string $source Photo downlaod url |
||
306 | */ |
||
307 | 3 | public function downloadOnePhoto($id, $source) |
|
329 | |||
330 | /** |
||
331 | * List all categories returned by API |
||
332 | * @param Unsplash $unsplash Proxy to Unsplash API |
||
333 | * @return boolean True on success |
||
334 | */ |
||
335 | 1 | public function listCategories(Unsplash $unsplash) |
|
346 | |||
347 | /** |
||
348 | * Download file from source to destination |
||
349 | * @param string $source URL to download the file from |
||
350 | * @param string $destination Path to download the file to |
||
351 | * @return bool True if the copy is successful |
||
352 | * @codeCoverageIgnore |
||
353 | */ |
||
354 | public function copyFile($source, $destination) { |
||
357 | |||
358 | } |
||
359 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.