diff --git a/src/Libraries/Storage/Adapters/Dropbox/DropboxApp.php b/src/Libraries/Storage/Adapters/Dropbox/DropboxApp.php index 5ce6292a..81810d49 100644 --- a/src/Libraries/Storage/Adapters/Dropbox/DropboxApp.php +++ b/src/Libraries/Storage/Adapters/Dropbox/DropboxApp.php @@ -96,17 +96,17 @@ class DropboxApp /** * @var string */ - private $appKey = null; + private $appKey; /** * @var string */ - private $appSecret = null; + private $appSecret; /** * @var TokenServiceInterface */ - private $tokenService = null; + private $tokenService; /** * DropboxApp constructor @@ -125,8 +125,11 @@ public function __construct(string $appKey, string $appSecret, TokenServiceInter /** * Gets the auth URL - * @throws CryptorException + * @param string $redirectUrl + * @param string $tokenAccessType + * @return string * @throws AppException + * @throws CryptorException * @throws DatabaseException */ public function getAuthUrl(string $redirectUrl, string $tokenAccessType = 'offline'): string diff --git a/src/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveApp.php b/src/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveApp.php index 5a338978..02eb125c 100644 --- a/src/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveApp.php +++ b/src/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveApp.php @@ -2,8 +2,10 @@ namespace Quantum\Libraries\Storage\Adapters\GoogleDrive; +use Quantum\Exceptions\AppException; +use Quantum\Exceptions\CryptorException; +use Quantum\Exceptions\DatabaseException; use Quantum\Libraries\Curl\HttpClient; -use Quantum\Http\Response; use Exception; class GoogleDriveApp @@ -56,17 +58,17 @@ class GoogleDriveApp /** * @var string */ - private $appKey = null; + private $appKey; /** * @var string */ - private $appSecret = null; + private $appSecret; /** * @var TokenServiceInterface */ - private $tokenService = null; + private $tokenService; /** * GoogleDriveApp constructor @@ -83,7 +85,16 @@ public function __construct(string $appKey, string $appSecret, TokenServiceInter $this->httpClient = $httpClient; } - public function getAuthUrl($redirectUrl, $accessType = "offline"): string + /** + * Gets Auth URL + * @param string $redirectUrl + * @param string $accessType + * @return object|null + * @throws AppException + * @throws CryptorException + * @throws DatabaseException + */ + public function getAuthUrl(string $redirectUrl, string $accessType = "offline"): string { $params = [ 'client_id' => $this->appKey, @@ -97,7 +108,15 @@ public function getAuthUrl($redirectUrl, $accessType = "offline"): string return self::AUTH_URL . '?' . http_build_query($params, '', '&'); } - public function fetchTokens($code, $redirectUrl = '', $byRefresh = false): ?object + /** + * Fetch tokens + * @param string $code + * @param string $redirectUrl + * @param bool $byRefresh + * @return object|null + * @throws Exception + */ + public function fetchTokens(string $code, string $redirectUrl = '', bool $byRefresh = false): ?object { $codeKey = $byRefresh ? 'refresh_token' : 'code'; @@ -112,16 +131,23 @@ public function fetchTokens($code, $redirectUrl = '', $byRefresh = false): ?obje $params['redirect_uri'] = $redirectUrl; } - $tokenUrl = self::AUTH_TOKEN_URL; - - $response = $this->sendRequest($tokenUrl, $params); + $response = $this->sendRequest(self::AUTH_TOKEN_URL, $params); $this->tokenService->saveTokens($response->access_token, !$byRefresh ? $response->refresh_token : null); return $response; } - public function sendRequest(string $uri, $data = null, array $headers = [], $method = 'POST') + /** + * Sends rpc request + * @param string $uri + * @param null $data + * @param array $headers + * @param string $method + * @return mixed|null + * @throws Exception + */ + public function sendRequest(string $uri, $data = null, array $headers = [], string $method = 'POST') { $this->httpClient ->createRequest($uri) @@ -130,11 +156,9 @@ public function sendRequest(string $uri, $data = null, array $headers = [], $met ->setHeaders($headers) ->start(); - - $errors = $this->httpClient->getErrors(); $responseBody = $this->httpClient->getResponseBody(); - if ($errors) { + if ($errors = $this->httpClient->getErrors()) { $code = $errors['code']; if ($code == self::INVALID_TOKEN_ERROR_CODE) { @@ -167,7 +191,7 @@ public function sendRequest(string $uri, $data = null, array $headers = [], $met * @return mixed|null * @throws Exception */ - public function rpcRequest(string $url, $params = [], $method = 'POST', $contentType = 'application/json') + public function rpcRequest(string $url, $params = [], string $method = 'POST', string $contentType = 'application/json') { try { $headers = [ @@ -184,11 +208,11 @@ public function rpcRequest(string $url, $params = [], $method = 'POST', $content * Gets file information * @param string $fileId * @param bool $media - * @param mixed $params + * @param array $params * @return mixed|null * @throws Exception */ - public function getFileInfo(string $fileId, $media = false, $params = []){ + public function getFileInfo(string $fileId, bool $media = false, array $params = []){ $queryParam = $media ? '?alt=media' : '?fields=*'; return $this->rpcRequest(GoogleDriveApp::FILE_METADATA_URL . '/' . $fileId . $queryParam, $params, 'GET'); } diff --git a/src/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapter.php b/src/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapter.php index 02edbfba..6d82efb9 100644 --- a/src/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapter.php +++ b/src/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapter.php @@ -13,6 +13,9 @@ class GoogleDriveFileSystemAdapter implements FilesystemAdapterInterface */ private static $instance = null; + /** + * @var GoogleDriveApp + */ private $googleDriveApp; /** @@ -38,6 +41,9 @@ public static function getInstance(GoogleDriveApp $googleDriveApp): GoogleDriveF return self::$instance; } + /** + * @inheritDoc + */ public function makeDirectory(string $dirname, ?string $parentId = null): bool { try{ diff --git a/tests/unit/Libraries/Storage/Adapters/Dropbox/DropboxAppTest.php b/tests/unit/Libraries/Storage/Adapters/Dropbox/DropboxAppTest.php index 4d6b0a14..be7a0e72 100644 --- a/tests/unit/Libraries/Storage/Adapters/Dropbox/DropboxAppTest.php +++ b/tests/unit/Libraries/Storage/Adapters/Dropbox/DropboxAppTest.php @@ -12,16 +12,34 @@ class DropboxAppTest extends AppTestCase use DropboxTokenServiceTestCase; use HttpClientTestCase; + /** + * @var DropboxApp + */ private $dropboxApp; + /** + * @var string + */ private $appKey = 'x0hwm8wy63rrynm'; + /** + * @var string + */ private $appSecret = 'xxx123yyy'; + /** + * @var string + */ private $authCode = 'd4k29ovC7-UAAAAAAAA3Q45go2mLgjMhJSeJNBOo-EA'; + /** + * @var string + */ private $redirectUrl = 'http://localhost/confirm'; + /** + * @var array + */ private $tokensGrantResponse = [ "access_token" => "sl.BYEQ1_VadTz6nBU36WPBBVwokc3zWVMXGjcOKxV4Tadms8ZlEPM85aHVFa_k1sfjilCWOnl79RUncPZzJ3GhrqhLGIBFFRCH0rKMa_ZtcqkerJn-f5lu10Ki5PSw4fxYM80V4PL_", "token_type" => "bearer", @@ -32,6 +50,9 @@ class DropboxAppTest extends AppTestCase "account_id" => "dbid:AAC9tDKbzTQlyNms0ZcB_iH3wLv7yNn-iyE" ]; + /** + * @var array + */ private $profileDataResponse = [ "account_id" => "dbid:AAH4f99T0taONIb-OurWxbNQ6ywGRopQngc", "disabled" => false, @@ -48,6 +69,9 @@ class DropboxAppTest extends AppTestCase "profile_photo_url" => "https://dl-web.dropbox.com/account_photo/get/69330102&size=128x128" ]; + /** + * @var array + */ private $errorResponse = [ "error" => [ ".tag" => "no_account" @@ -55,6 +79,9 @@ class DropboxAppTest extends AppTestCase "error_summary" => "no_account/..." ]; + /** + * @var string + */ private $fileContentResponse = 'Some plain text!'; public function setUp(): void diff --git a/tests/unit/Libraries/Storage/Adapters/Dropbox/DropboxFileSystemAdapterTest.php b/tests/unit/Libraries/Storage/Adapters/Dropbox/DropboxFileSystemAdapterTest.php index 3eb2fb47..02457446 100644 --- a/tests/unit/Libraries/Storage/Adapters/Dropbox/DropboxFileSystemAdapterTest.php +++ b/tests/unit/Libraries/Storage/Adapters/Dropbox/DropboxFileSystemAdapterTest.php @@ -9,10 +9,30 @@ class DropboxFileSystemAdapterTest extends AppTestCase { + + /** + * @var DropboxFileSystemAdapter + */ private $fs; + + /** + * @var string + */ private $dirname = 'common'; + + /** + * @var string + */ private $filename = 'sample.txt'; + + /** + * @var string + */ private $content = 'This file was created via dropbox api'; + + /** + * @var array + */ private static $response = []; public function setUp(): void diff --git a/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveAppTest.php b/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveAppTest.php index 27ac0dc0..63fde36d 100644 --- a/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveAppTest.php +++ b/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveAppTest.php @@ -12,21 +12,42 @@ class GoogleDriveAppTest extends AppTestCase use GoogleDriveTokenServiceTestCase; use HttpClientTestCase; + /** + * @var GoogleDriveApp + */ private $googleDriveApp; - private $appKey = 'x0hwm8wy63rrynm'; + /** + * @var string + */ + private $appKey = 'x0hwm8wy63rrynm'; + /** + * @var string + */ private $appSecret = 'xxx123yyy'; + /** + * @var string + */ private $authCode = 'd4k29ovC7-UAAAAAAAA3Q45go2mLgjMhJSeJNBOo-EA'; + /** + * @var string + */ private $redirectUrl = 'http://localhost/confirm'; + /** + * @var array + */ private $tokensGrantResponse = [ "access_token" => "sl.BYEQ1_VadTz6nBU36WPBBVwokc3zWVMXGjcOKxV4Tadms8ZlEPM85aHVFa_k1sfjilCWOnl79RUncPZzJ3GhrqhLGIBFFRCH0rKMa_ZtcqkerJn-f5lu10Ki5PSw4fxYM80V4PL_", "refresh_token" => "-3S067m3M5kAAAAAAAAAAcQF8zVqFUuhK-PFkFqiOfFTgiazWj5NyU-1EGWIh0ZS" ]; + /** + * @var array + */ private $fileMetadataResponse = [ "id" => "file1", "kind" => GoogleDriveApp::DRIVE_FILE_KIND, @@ -34,7 +55,14 @@ class GoogleDriveAppTest extends AppTestCase "mimeType" => "text/plain" ]; + /** + * @var string + */ private $fileContentResponse = 'Some plain text!'; + + /** + * @var string + */ private $errorResponse = [ 'code' => GoogleDriveApp::INVALID_TOKEN_ERROR_CODE, 'message' => 'Invalid access token', diff --git a/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapterTest.php b/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapterTest.php index 28ab71f0..0c6f905f 100644 --- a/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapterTest.php +++ b/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapterTest.php @@ -9,10 +9,35 @@ class GoogleDriveFileSystemAdapterTest extends AppTestCase { + + /** + * @var GoogleDriveFileSystemAdapter + */ private $fs; + + /** + * @var string + */ private $dirname = 'common'; + + /** + * @var string + */ private $filename = 'sample.txt'; + + /** + * @var string + */ + private $newFilename = 'new_name.txt'; + + /** + * @var string + */ private $content = 'This file was created via dropbox api'; + + /** + * @var array + */ private static $response = []; public function setUp(): void @@ -96,40 +121,36 @@ public function testGoogleDriveFileRename() { $this->fs->put($this->filename, $this->content); - $newFilename = 'new_name.txt'; - - $this->assertFalse($this->fs->exists($newFilename)); + $this->assertFalse($this->fs->exists($this->newFilename)); self::$response['kind'] = GoogleDriveApp::DRIVE_FILE_KIND; self::$response['mimeType'] = 'text/plain'; - $this->fs->rename($this->filename, $newFilename); + $this->fs->rename($this->filename, $this->newFilename); - $this->assertTrue($this->fs->exists($newFilename)); + $this->assertTrue($this->fs->exists($this->newFilename)); - $this->fs->remove($newFilename); + $this->fs->remove($this->newFilename); } public function testGoogleDriveFileCopy() { - $dirName = 'testing'; - - $this->fs->makeDirectory($dirName); + $this->fs->makeDirectory($this->dirname); $this->fs->put($this->filename, $this->content); - $this->assertFalse($this->fs->exists($dirName . '/' . $this->filename)); + $this->assertFalse($this->fs->exists($this->dirname . '/' . $this->filename)); self::$response['kind'] = GoogleDriveApp::DRIVE_FILE_KIND; self::$response['mimeType'] = 'text/plain'; - $this->fs->copy($this->filename, $dirName . '/' . $this->filename); + $this->fs->copy($this->filename, $this->dirname . '/' . $this->filename); - $this->assertTrue($this->fs->exists($dirName . '/' . $this->filename)); + $this->assertTrue($this->fs->exists($this->dirname . '/' . $this->filename)); - $this->fs->remove($dirName . '/' . $this->filename); + $this->fs->remove($this->dirname . '/' . $this->filename); - $this->fs->removeDirectory($dirName); + $this->fs->removeDirectory($this->dirname); } public function testGoogleDriveFileSize() diff --git a/tests/unit/Libraries/Storage/Adapters/Local/LocalFileSystemAdapterTest.php b/tests/unit/Libraries/Storage/Adapters/Local/LocalFileSystemAdapterTest.php index 367f07a6..00aa3ce3 100644 --- a/tests/unit/Libraries/Storage/Adapters/Local/LocalFileSystemAdapterTest.php +++ b/tests/unit/Libraries/Storage/Adapters/Local/LocalFileSystemAdapterTest.php @@ -8,9 +8,24 @@ class LocalFileSystemAdapterTest extends AppTestCase { + /** + * @var LocalFileSystemAdapter + */ private $fs; + + /** + * @var string + */ private $dirname; + + /** + * @var string + */ private $filename; + + /** + * @var string + */ private $content = 'Hello world'; public function setUp(): void