diff --git a/src/MakesHttpRequests.php b/src/MakesHttpRequests.php deleted file mode 100644 index 5959113..0000000 --- a/src/MakesHttpRequests.php +++ /dev/null @@ -1,48 +0,0 @@ - true, - CURLOPT_CUSTOMREQUEST => $method, - CURLOPT_POSTFIELDS => ($method === 'POST') ? http_build_query($data) : null, - CURLOPT_HTTPHEADER => $headers, - ]); - - $response = curl_exec($ch); - $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - - curl_close($ch); - - if ($statusCode >= 200 && $statusCode < 300) { - return json_decode($response, true); - } - - throw new \RuntimeException('HTTP Request Failed with status code: ' . $statusCode); - } - - /** - * @return [type] - */ - public function getCode() - { - return app()->request->get('code') ?? null; - } -} diff --git a/src/Socialite.php b/src/Socialite.php index 7455b23..424b23e 100644 --- a/src/Socialite.php +++ b/src/Socialite.php @@ -6,7 +6,7 @@ class Socialite { /** - * @var [type] + * @var object */ private static $instance; @@ -27,7 +27,7 @@ private function __construct() } /** - * @return [type] + * Define a static method to get an instance of the class */ public static function make() { @@ -52,15 +52,17 @@ public function getProvider(string $name): object $provider = sprintf('Axm\\Socialite\\Providers\\%sProvider', ucfirst($name)); if (!class_exists($provider)) { - throw new \InvalidArgumentException("Provider $provider not supported."); + throw new \InvalidArgumentException(sprintf('Provider [ %s ] not supported.', $provider)); } return new $provider($config); } /** - * @param string $provider - * @return [type] + * Return an instance of the specified provider's driver. + * + * @param string $provider The name of the provider to return the driver for. + * @return object The driver instance for the specified provider. */ public static function driver(string $provider): object { @@ -69,7 +71,8 @@ public static function driver(string $provider): object } /** - * @return array + * Returns the configuration array for the specified provider. + * @return array The configuration array for the specified provider. */ public function getProviderConfig(): array { @@ -78,13 +81,16 @@ public function getProviderConfig(): array } /** - * @return [type] + * Opens and returns the configuration array for the specified provider. + * + * @return array The configuration array for the specified provider. + * @throws \InvalidArgumentException If the configuration file does not exist. */ public function openConfig(): array { $file = __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; if (!is_file($file)) { - throw new \InvalidArgumentException("The configuration file $file does not exist."); + throw new \InvalidArgumentException(sprintf('The configuration file [ %s ] does not exist.', $file)); } $config = require($file); diff --git a/src/providers/GoogleProvider.php b/src/providers/GoogleProvider.php index d81cd8a..e2ddf65 100644 --- a/src/providers/GoogleProvider.php +++ b/src/providers/GoogleProvider.php @@ -77,7 +77,6 @@ public function user() $code = $this->getCode(); if (!empty($code)) { try { - $params = $this->getParams($code); $curl = new Curl(); @@ -98,6 +97,10 @@ public function user() } /** + * This method is used to retrieve the parameters required for the token request. + * It takes in a $code parameter which is the authorization code received from the authorization server. + * + * @param string $code The authorization code received from the authorization server * @return array */ public function getParams($code): array @@ -114,6 +117,7 @@ public function getParams($code): array } /** + * Define a method to retrieve the 'code' parameter from the request * @return mixed */ public function getCode() @@ -124,10 +128,10 @@ public function getCode() } /** - * @param string $url - * @return [type] + * Perform a redirect to the given URL + * @param string $url The redirect location */ - public function makeRedirect(string $url) + protected function makeRedirect(string $url) { if (!headers_sent()) app()