@@ -28,7 +28,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
2828
2929 private LoggerInterface $ logger ;
3030
31- public function needsPartFile () {
31+ public function needsPartFile (): bool {
3232 return false ;
3333 }
3434
@@ -63,7 +63,7 @@ public function __construct($parameters) {
6363 * @param string $path
6464 * @return string correctly encoded path
6565 */
66- private function normalizePath ($ path ) {
66+ private function normalizePath ($ path ): string {
6767 $ path = trim ($ path , '/ ' );
6868
6969 if (!$ path ) {
@@ -73,24 +73,24 @@ private function normalizePath($path) {
7373 return $ path ;
7474 }
7575
76- private function isRoot ($ path ) {
76+ private function isRoot ($ path ): bool {
7777 return $ path === '. ' ;
7878 }
7979
80- private function cleanKey ($ path ) {
80+ private function cleanKey ($ path ): string {
8181 if ($ this ->isRoot ($ path )) {
8282 return '/ ' ;
8383 }
8484 return $ path ;
8585 }
8686
87- private function clearCache () {
87+ private function clearCache (): void {
8888 $ this ->objectCache = new CappedMemoryCache ();
8989 $ this ->directoryCache = new CappedMemoryCache ();
9090 $ this ->filesCache = new CappedMemoryCache ();
9191 }
9292
93- private function invalidateCache ($ key ) {
93+ private function invalidateCache ($ key ): void {
9494 unset($ this ->objectCache [$ key ]);
9595 $ keys = array_keys ($ this ->objectCache ->getData ());
9696 $ keyLength = strlen ($ key );
@@ -110,10 +110,7 @@ private function invalidateCache($key) {
110110 unset($ this ->directoryCache [$ key ]);
111111 }
112112
113- /**
114- * @return array|false
115- */
116- private function headObject (string $ key ) {
113+ private function headObject (string $ key ): array |false {
117114 if (!isset ($ this ->objectCache [$ key ])) {
118115 try {
119116 $ this ->objectCache [$ key ] = $ this ->getConnection ()->headObject ([
@@ -144,11 +141,9 @@ private function headObject(string $key) {
144141 * Implementation from flysystem-aws-s3-v3:
145142 * https://github.com/thephpleague/flysystem-aws-s3-v3/blob/8241e9cc5b28f981e0d24cdaf9867f14c7498ae4/src/AwsS3Adapter.php#L670-L694
146143 *
147- * @param $path
148- * @return bool
149144 * @throws \Exception
150145 */
151- private function doesDirectoryExist ($ path ) {
146+ private function doesDirectoryExist ($ path ): bool {
152147 if ($ path === '. ' || $ path === '' ) {
153148 return true ;
154149 }
@@ -190,13 +185,7 @@ private function doesDirectoryExist($path) {
190185 return false ;
191186 }
192187
193- /**
194- * Remove a file or folder
195- *
196- * @param string $path
197- * @return bool
198- */
199- protected function remove ($ path ) {
188+ protected function remove ($ path ): bool {
200189 // remember fileType to reduce http calls
201190 $ fileType = $ this ->filetype ($ path );
202191 if ($ fileType === 'dir ' ) {
@@ -208,7 +197,7 @@ protected function remove($path) {
208197 }
209198 }
210199
211- public function mkdir ($ path ) {
200+ public function mkdir ($ path ): bool {
212201 $ path = $ this ->normalizePath ($ path );
213202
214203 if ($ this ->is_dir ($ path )) {
@@ -236,12 +225,12 @@ public function mkdir($path) {
236225 return true ;
237226 }
238227
239- public function file_exists ($ path ) {
228+ public function file_exists ($ path ): bool {
240229 return $ this ->filetype ($ path ) !== false ;
241230 }
242231
243232
244- public function rmdir ($ path ) {
233+ public function rmdir ($ path ): bool {
245234 $ path = $ this ->normalizePath ($ path );
246235
247236 if ($ this ->isRoot ($ path )) {
@@ -256,12 +245,12 @@ public function rmdir($path) {
256245 return $ this ->batchDelete ($ path );
257246 }
258247
259- protected function clearBucket () {
248+ protected function clearBucket (): bool {
260249 $ this ->clearCache ();
261250 return $ this ->batchDelete ();
262251 }
263252
264- private function batchDelete ($ path = null ) {
253+ private function batchDelete ($ path = null ): bool {
265254 // TODO explore using https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.S3.BatchDelete.html
266255 $ params = [
267256 'Bucket ' => $ this ->bucket
@@ -312,7 +301,7 @@ public function opendir($path) {
312301 }
313302 }
314303
315- public function stat ($ path ) {
304+ public function stat ($ path ): array | false {
316305 $ path = $ this ->normalizePath ($ path );
317306
318307 if ($ this ->is_dir ($ path )) {
@@ -334,11 +323,8 @@ public function stat($path) {
334323 *
335324 * When the information is already present (e.g. opendir has been called before)
336325 * this value is return. Otherwise a headObject is emitted.
337- *
338- * @param $path
339- * @return int|mixed
340326 */
341- private function getContentLength ($ path ) {
327+ private function getContentLength ($ path ): int {
342328 if (isset ($ this ->filesCache [$ path ])) {
343329 return (int )$ this ->filesCache [$ path ]['ContentLength ' ];
344330 }
@@ -356,11 +342,8 @@ private function getContentLength($path) {
356342 *
357343 * When the information is already present (e.g. opendir has been called before)
358344 * this value is return. Otherwise a headObject is emitted.
359- *
360- * @param $path
361- * @return mixed|string
362345 */
363- private function getLastModified ($ path ) {
346+ private function getLastModified ($ path ): string {
364347 if (isset ($ this ->filesCache [$ path ])) {
365348 return $ this ->filesCache [$ path ]['LastModified ' ];
366349 }
@@ -373,7 +356,7 @@ private function getLastModified($path) {
373356 return 'now ' ;
374357 }
375358
376- public function is_dir ($ path ) {
359+ public function is_dir ($ path ): bool {
377360 $ path = $ this ->normalizePath ($ path );
378361
379362 if (isset ($ this ->filesCache [$ path ])) {
@@ -391,7 +374,7 @@ public function is_dir($path) {
391374 }
392375 }
393376
394- public function filetype ($ path ) {
377+ public function filetype ($ path ): string | false {
395378 $ path = $ this ->normalizePath ($ path );
396379
397380 if ($ this ->isRoot ($ path )) {
@@ -419,15 +402,15 @@ public function filetype($path) {
419402 return false ;
420403 }
421404
422- public function getPermissions ($ path ) {
405+ public function getPermissions ($ path ): int {
423406 $ type = $ this ->filetype ($ path );
424407 if (!$ type ) {
425408 return 0 ;
426409 }
427410 return $ type === 'dir ' ? Constants::PERMISSION_ALL : Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE ;
428411 }
429412
430- public function unlink ($ path ) {
413+ public function unlink ($ path ): bool {
431414 $ path = $ this ->normalizePath ($ path );
432415
433416 if ($ this ->is_dir ($ path )) {
@@ -506,7 +489,7 @@ public function fopen($path, $mode) {
506489 return false ;
507490 }
508491
509- public function touch ($ path , $ mtime = null ) {
492+ public function touch ($ path , $ mtime = null ): bool {
510493 if (is_null ($ mtime )) {
511494 $ mtime = time ();
512495 }
@@ -541,7 +524,7 @@ public function touch($path, $mtime = null) {
541524 return true ;
542525 }
543526
544- public function copy ($ source , $ target , $ isFile = null ) {
527+ public function copy ($ source , $ target , $ isFile = null ): bool {
545528 $ source = $ this ->normalizePath ($ source );
546529 $ target = $ this ->normalizePath ($ target );
547530
@@ -584,7 +567,7 @@ public function copy($source, $target, $isFile = null) {
584567 return true ;
585568 }
586569
587- public function rename ($ source , $ target ) {
570+ public function rename ($ source , $ target ): bool {
588571 $ source = $ this ->normalizePath ($ source );
589572 $ target = $ this ->normalizePath ($ target );
590573
@@ -611,18 +594,18 @@ public function rename($source, $target) {
611594 return true ;
612595 }
613596
614- public function test () {
597+ public function test (): bool {
615598 $ this ->getConnection ()->headBucket ([
616599 'Bucket ' => $ this ->bucket
617600 ]);
618601 return true ;
619602 }
620603
621- public function getId () {
604+ public function getId (): string {
622605 return $ this ->id ;
623606 }
624607
625- public function writeBack ($ tmpFile , $ path ) {
608+ public function writeBack ($ tmpFile , $ path ): bool {
626609 try {
627610 $ source = fopen ($ tmpFile , 'r ' );
628611 $ this ->writeObject ($ path , $ source , $ this ->mimeDetector ->detectPath ($ path ));
@@ -642,7 +625,7 @@ public function writeBack($tmpFile, $path) {
642625 /**
643626 * check if curl is installed
644627 */
645- public static function checkDependencies () {
628+ public static function checkDependencies (): bool {
646629 return true ;
647630 }
648631
@@ -743,7 +726,7 @@ protected function getVersioningStatusFromBucket(): bool {
743726 }
744727 }
745728
746- public function hasUpdated ($ path , $ time ) {
729+ public function hasUpdated ($ path , $ time ): bool {
747730 // for files we can get the proper mtime
748731 if ($ path !== '' && $ object = $ this ->headObject ($ path )) {
749732 $ stat = $ this ->objectToMetaData ($ object );
0 commit comments