From b2f527dbe2fa2aa06840432bdaec30090c3148e1 Mon Sep 17 00:00:00 2001 From: Rizky Sugiharto Date: Thu, 23 Oct 2025 13:25:30 +0700 Subject: [PATCH 1/2] style: add comment/type-hint to each functions on Gdrive class for better developing --- src/Gdrive.php | 105 ++++++++++++++++------------- src/Helpers/GdriveFile.php | 13 ++++ src/Helpers/GdriveFileInfo.php | 12 ++++ src/interfaces/GdriveInterface.php | 71 +++++++++++-------- 4 files changed, 129 insertions(+), 72 deletions(-) create mode 100644 src/Helpers/GdriveFile.php create mode 100644 src/Helpers/GdriveFileInfo.php diff --git a/src/Gdrive.php b/src/Gdrive.php index fe11d88..38b6135 100644 --- a/src/Gdrive.php +++ b/src/Gdrive.php @@ -5,82 +5,92 @@ use File; use Illuminate\Support\Facades\Storage; use Yaza\LaravelGoogleDriveStorage\interfaces\GdriveInterface; +use Yaza\LaravelGoogleDriveStorage\Helpers\GdriveFile; +use Yaza\LaravelGoogleDriveStorage\Helpers\GdriveFileInfo; +use \League\Flysystem\DirectoryListing; +use \League\Flysystem\StorageAttributes; class Gdrive implements GdriveInterface { /** - * get file from gdrive + * Get file from gdrive * - * @return mixed + * @param string $file_path + * @return GdriveFile */ - public static function get($file_path) + public static function get(string $file_path): GdriveFile { $fileinfo = self::getFileInfo($file_path); $rawData = Storage::disk('google')->get($fileinfo->path); - return (object) [ - 'file' => $rawData, - 'ext' => $fileinfo->ext, - 'filename' => $fileinfo->filename, - ]; + return new GdriveFile( + file: $rawData, + ext: $fileinfo->ext, + filename: $fileinfo->filename, + path: $fileinfo->path + ); } /** - * read file to stream + * Read file to stream * - * @return mixed|object + * @param string $filepath + * @return GdriveFile */ - public static function readStream($filepath) + public static function readStream(string $filepath): GdriveFile { $fileinfo = self::getFileInfo($filepath); $readStream = Storage::disk('google')->getDriver()->readStream($fileinfo->path); - return (object) [ - 'file' => $readStream, - 'ext' => $fileinfo->ext, - 'filename' => $fileinfo->filename, - ]; + return new GdriveFile( + file: $readStream, + ext: $fileinfo->ext, + filename: $fileinfo->filename, + path: $fileinfo->path + ); } /** - * put file + * Put file * - * @param $location - * @param bool $random_file_name - * @return mixed|void + * @param string $path + * @param string $file + * @return void */ - public static function put($path, $file) + public static function put(string $path, string $file): void { Storage::disk('google')->put($path, File::get($file)); } /** - * get file info + * Get file info * - * @return mixed|object + * @param string $file_path + * @return GdriveFileInfo */ - public static function getFileInfo($file_path) + public static function getFileInfo(string $file_path): GdriveFileInfo { $path = str_replace('\\', '/', $file_path); $arr = explode('/', $path); $file_name = end($arr); $ext = pathinfo($file_name, PATHINFO_EXTENSION); - return (object) [ - 'filename' => $file_name, - 'ext' => $ext, - 'path' => $path, - ]; + return new GdriveFileInfo( + filename: $file_name, + ext: $ext, + path: $path, + ); } /** - * delete file + * Delete file * - * @return mixed|void + * @param string $path + * @return void */ - public static function delete($path) + public static function delete(string $path): void { $fileinfo = self::getFileInfo($path); @@ -88,42 +98,47 @@ public static function delete($path) } /** - * make directory + * Make directory * - * @return mixed|void + * @param string $dirname + * @return void */ - public static function makeDir($dirname) + public static function makeDir(string $dirname): void { Storage::disk('google')->makeDirectory($dirname); } /** - * delete directory + * Delete directory * - * @return mixed|void + * @param string $dirpath + * @return void */ - public static function deleteDir($dirpath) + public static function deleteDir(string $dirpath): void { Storage::disk('google')->deleteDirectory($dirpath); } /** - * rename directory + * Rename directory * - * @return mixed|void + * @param string $dirpath + * @param string $newdirname + * @return void */ - public static function renameDir($dirpath, $newdirname) + public static function renameDir(string $dirpath, string $newdirname): void { Storage::disk('google')->move($dirpath, $newdirname); } /** - * all folder + * All folder * - * @param bool $recursive - * @return mixed + * @param string $path + * @param bool $recursive + * @return DirectoryListing */ - public static function all($path, $recursive = true) + public static function all(string $path, bool $recursive = true) { $contents = collect(Storage::disk('google')->listContents($path, $recursive)); diff --git a/src/Helpers/GdriveFile.php b/src/Helpers/GdriveFile.php new file mode 100644 index 0000000..d375c67 --- /dev/null +++ b/src/Helpers/GdriveFile.php @@ -0,0 +1,13 @@ + */ - public static function all($path, $recursive); + public static function all(string $path, bool $recursive); } From 00ec942bee35c263467c86c4620ccbab446b1473 Mon Sep 17 00:00:00 2001 From: Rizky Sugiharto Date: Wed, 5 Nov 2025 23:37:26 +0700 Subject: [PATCH 2/2] refactor: rename Helpers dir into typings dir and its namespace" --- src/Gdrive.php | 4 ++-- src/interfaces/GdriveInterface.php | 4 ++-- src/{Helpers => typings}/GdriveFile.php | 2 +- src/{Helpers => typings}/GdriveFileInfo.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename src/{Helpers => typings}/GdriveFile.php (80%) rename src/{Helpers => typings}/GdriveFileInfo.php (77%) diff --git a/src/Gdrive.php b/src/Gdrive.php index 38b6135..7b709a9 100644 --- a/src/Gdrive.php +++ b/src/Gdrive.php @@ -5,8 +5,8 @@ use File; use Illuminate\Support\Facades\Storage; use Yaza\LaravelGoogleDriveStorage\interfaces\GdriveInterface; -use Yaza\LaravelGoogleDriveStorage\Helpers\GdriveFile; -use Yaza\LaravelGoogleDriveStorage\Helpers\GdriveFileInfo; +use Yaza\LaravelGoogleDriveStorage\typings\GdriveFile; +use Yaza\LaravelGoogleDriveStorage\typings\GdriveFileInfo; use \League\Flysystem\DirectoryListing; use \League\Flysystem\StorageAttributes; diff --git a/src/interfaces/GdriveInterface.php b/src/interfaces/GdriveInterface.php index 442e9a2..a89bcb2 100644 --- a/src/interfaces/GdriveInterface.php +++ b/src/interfaces/GdriveInterface.php @@ -2,8 +2,8 @@ namespace Yaza\LaravelGoogleDriveStorage\interfaces; -use Yaza\LaravelGoogleDriveStorage\Helpers\GdriveFile; -use Yaza\LaravelGoogleDriveStorage\Helpers\GdriveFileInfo; +use Yaza\LaravelGoogleDriveStorage\typings\GdriveFile; +use Yaza\LaravelGoogleDriveStorage\typings\GdriveFileInfo; use \League\Flysystem\DirectoryListing; use \League\Flysystem\StorageAttributes; diff --git a/src/Helpers/GdriveFile.php b/src/typings/GdriveFile.php similarity index 80% rename from src/Helpers/GdriveFile.php rename to src/typings/GdriveFile.php index d375c67..da6bde5 100644 --- a/src/Helpers/GdriveFile.php +++ b/src/typings/GdriveFile.php @@ -1,6 +1,6 @@