22
33namespace PlatformCommunity \Flysystem \BunnyCDN ;
44
5+ use Exception ;
56use League \Flysystem \Config ;
67use League \Flysystem \DirectoryAttributes ;
78use League \Flysystem \DirectoryListing ;
@@ -113,15 +114,15 @@ public function listContents(string $path = '', bool $deep = false): iterable
113114 // @codeCoverageIgnoreEnd
114115
115116 foreach ($ entries as $ item ) {
116- yield $ this ->normalizeObject ($ item );
117- }
118-
119- // return new DirectoryListing($contents, $deep);
120- // return array_map(function($item) {
121- // return $this->normalizeObject($item);
122- // }, $entries);
117+ $ content = $ this ->normalizeObject ($ item );
118+ yield $ content ;
123119
124- // return $entries;
120+ if ($ deep && $ content instanceof DirectoryAttributes) {
121+ foreach ($ this ->listContents ($ content ->path (), $ deep ) as $ deepItem ) {
122+ yield $ deepItem ;
123+ }
124+ }
125+ }
125126 }
126127
127128 /**
@@ -184,9 +185,6 @@ private function extractExtraMetadata(array $bunny_file_array): array
184185 *
185186 * @param string $path
186187 * @return string
187- *
188- * @throws Exceptions\BunnyCDNException
189- * @throws Exceptions\NotFoundException
190188 */
191189 public function detectMimeType (string $ path ): string
192190 {
@@ -199,7 +197,7 @@ public function detectMimeType(string $path): string
199197 }
200198
201199 return $ mimeType ;
202- } catch (\ Exception $ e ) {
200+ } catch (Exception ) {
203201 return '' ;
204202 }
205203 }
@@ -219,12 +217,17 @@ public function writeStream($path, $contents, Config $config): void
219217 * @param $path
220218 * @return resource
221219 *
222- * @throws Exceptions\BunnyCDNException
223- * @throws Exceptions\NotFoundException
220+ * @throws UnableToReadFile
224221 */
225222 public function readStream ($ path )
226223 {
227- return $ this ->client ->stream ($ path );
224+ try {
225+ return $ this ->client ->stream ($ path );
226+ // @codeCoverageIgnoreStart
227+ } catch (Exceptions \BunnyCDNException |Exceptions \NotFoundException $ e ) {
228+ throw UnableToReadFile::fromLocation ($ path , $ e ->getMessage ());
229+ }
230+ // @codeCoverageIgnoreEnd
228231 }
229232
230233 /**
@@ -279,19 +282,15 @@ public function visibility(string $path): FileAttributes
279282 {
280283 try {
281284 return new FileAttributes ($ this ->getObject ($ path )->path (), null , $ this ->pullzone_url ? 'public ' : 'private ' );
282- } catch (UnableToReadFile $ e ) {
285+ } catch (UnableToReadFile | TypeError $ e ) {
283286 throw new UnableToRetrieveMetadata ($ e ->getMessage ());
284- } catch (TypeError $ e ) {
285- throw new UnableToRetrieveMetadata ('Cannot retrieve visibility of folder ' );
286287 }
287288 }
288289
289290 /**
290291 * @param string $path
291292 * @return FileAttributes
292293 *
293- * @throws Exceptions\BunnyCDNException
294- * @throws Exceptions\NotFoundException
295294 * @codeCoverageIgnore
296295 */
297296 public function mimeType (string $ path ): FileAttributes
@@ -323,13 +322,13 @@ public function mimeType(string $path): FileAttributes
323322 return $ object ;
324323 } catch (UnableToReadFile $ e ) {
325324 throw new UnableToRetrieveMetadata ($ e ->getMessage ());
326- } catch (TypeError $ e ) {
325+ } catch (TypeError ) {
327326 throw new UnableToRetrieveMetadata ('Cannot retrieve mimeType of folder ' );
328327 }
329328 }
330329
331330 /**
332- * @param $path
331+ * @param string $path
333332 * @return mixed
334333 */
335334 protected function getObject (string $ path = '' ): StorageAttributes
@@ -342,13 +341,15 @@ protected function getObject(string $path = ''): StorageAttributes
342341
343342 if (count ($ list ) === 1 ) {
344343 return $ list [0 ];
345- } elseif (count ($ list ) > 1 ) {
344+ }
345+
346+ if (count ($ list ) > 1 ) {
346347 // @codeCoverageIgnoreStart
347348 throw UnableToReadFile::fromLocation ($ path , 'More than one file was returned for path:" ' .$ path .'", contact package author. ' );
348- // @codeCoverageIgnoreEnd
349- } else {
350- throw UnableToReadFile::fromLocation ($ path , 'Error 404:" ' .$ path .'" ' );
349+ // @codeCoverageIgnoreEnd
351350 }
351+
352+ throw UnableToReadFile::fromLocation ($ path , 'Error 404:" ' .$ path .'" ' );
352353 }
353354
354355 /**
@@ -361,7 +362,7 @@ public function lastModified(string $path): FileAttributes
361362 return $ this ->getObject ($ path );
362363 } catch (UnableToReadFile $ e ) {
363364 throw new UnableToRetrieveMetadata ($ e ->getMessage ());
364- } catch (TypeError $ e ) {
365+ } catch (TypeError ) {
365366 throw new UnableToRetrieveMetadata ('Last Modified only accepts files as parameters, not directories ' );
366367 }
367368 }
@@ -376,7 +377,7 @@ public function fileSize(string $path): FileAttributes
376377 return $ this ->getObject ($ path );
377378 } catch (UnableToReadFile $ e ) {
378379 throw new UnableToRetrieveMetadata ($ e ->getMessage ());
379- } catch (TypeError $ e ) {
380+ } catch (TypeError ) {
380381 throw new UnableToRetrieveMetadata ('Cannot retrieve size of folder ' );
381382 }
382383 }
@@ -443,6 +444,7 @@ public function fileExists(string $path): bool
443444 * @param string $path
444445 * @return string
445446 * @codeCoverageIgnore
447+ * @noinspection PhpUnused
446448 */
447449 public function getUrl (string $ path ): string
448450 {
0 commit comments