diff --git a/composer.json b/composer.json index e251132..c587371 100644 --- a/composer.json +++ b/composer.json @@ -2,24 +2,30 @@ "name": "bowphp/soauth", "description": "The social authentification package for Bow Framework", "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Franck DAKIA", + "email": "dakiafranck@gmail.com", + "role": "Principal Maintainer" + } + ], "require": { - "league/oauth2-client": "^2.4.1" + "league/oauth2-client": "^2.4.1", + "php": "^8" }, "require-dev": { - "phpunit/phpunit": "^7" + "phpunit/phpunit": "^8", + "squizlabs/php_codesniffer": "^3.7" }, "autoload": { "psr-4": { "Bow\\Soauth\\": "src/" } }, - "license": "MIT", - "authors": [ - { - "name": "Franck DAKIA", - "email": "dakiafranck@gmail.com", - "role": "Lead Developer" - } - ], - "minimum-stability": "stable" + "scripts": { + "phpcbf": "phpcbf --standard=psr12 --severity=4 --tab-width=4 src tests", + "phpcs": "phpcs --standard=psr12 --severity=4 --tab-width=4 src", + "test": "phpunit --configuration phpunit.dist.xml" + } } diff --git a/docs/en.md b/docs/en.md index cbc0ff2..1772acd 100644 --- a/docs/en.md +++ b/docs/en.md @@ -110,7 +110,10 @@ $app->get('/oauth/:provider/callback', 'SoauthController::handle'); **Franck DAKIA** is a Full Stack developer based in Africa, Ivory Coast. Passionate about code and collaborative development, speaker, trainer and member of several developer communities and many collaborators. -Contact: [dakiafranck@gmail.com](mailto:dakiafranck@gmail.com) - [@franck_dakia](https://twitter.com/franck_dakia) +Contact: + +- [Franck DAKIA](https://github.com/papac) +- [Thank's collaborators](https://github.com/bowphp/docs/graphs/contributors) **Please, if there is a bug on the project please contact me by email or leave me a message on the [slack](https://bowphp.slack.com).** diff --git a/docs/fr.md b/docs/fr.md index e1d6500..b3b4f82 100644 --- a/docs/fr.md +++ b/docs/fr.md @@ -110,7 +110,10 @@ $app->get('/oauth/:provider/callback', 'SoauthController::handle'); **Franck DAKIA** est un développeur Full Stack basé actuellement en Afrique, Côte d'ivoire, Abidjan. Passioné de code, et développement collaboratif, Speaker, Formateur et Membre de plusieurs communautés de développeurs. -Contact: [dakiafranck@gmail.com](mailto:dakiafranck@gmail.com) - [@franck_dakia](https://twitter.com/franck_dakia) +Contact: + +- [Franck DAKIA](https://github.com/papac) +- [Thank's collaborators](https://github.com/bowphp/docs/graphs/contributors) **SVP s'il y a un bogue sur le projet veuillez me contacter par email ou laissez moi un message sur le [slack](https://bowphp.slack.com).** diff --git a/readme.md b/readme.md index 8b5c52e..776e19f 100644 --- a/readme.md +++ b/readme.md @@ -32,6 +32,6 @@ Thank you for considering contributing to Bow Framework! The contribution guide ## Contact -[papac@bowphp.com](mailto:papac@bowphp.com) - [@franck_dakia](https://twitter.com/franck_dakia) +[papac@bowphp.com](mailto:papac@bowphp.com) - [@papacdev](https://twitter.com/papacdev) Buy Me A Coffee diff --git a/src/Exception/SoauthException.php b/src/Exception/SoauthException.php index 7c662c3..4ae2a84 100644 --- a/src/Exception/SoauthException.php +++ b/src/Exception/SoauthException.php @@ -4,5 +4,4 @@ class SoauthException extends \Exception { - } diff --git a/src/Provider/AbstractProvider.php b/src/Provider/AbstractProvider.php index 40a5f82..0a45e5f 100644 --- a/src/Provider/AbstractProvider.php +++ b/src/Provider/AbstractProvider.php @@ -13,7 +13,7 @@ abstract class AbstractProvider * * @var LeagueOAuth2ClientProvider */ - private $provider; + private LeagueOAuth2ClientProvider $provider; /** * AbstractProvider constructor @@ -21,7 +21,7 @@ abstract class AbstractProvider * @param array $config * @return void */ - public function __construct($config) + public function __construct(array $config) { $this->provider = new LeagueOAuth2ClientProvider([ 'clientId' => $config['client_id'], @@ -33,9 +33,10 @@ public function __construct($config) /** * Get redirect url * + * @param array $scope * @return string */ - public function redirect($scope = []) + public function redirect(array $scope = []) { // We get the redirect url generate for you $authorization_url = $this->provider->getAuthorizationUrl( @@ -54,7 +55,7 @@ public function redirect($scope = []) * * @return UserResource */ - public function process() + public function process(): UserResource { // Check request state and saved state if ($this->request->get('state') !== session()->get('oauth2_state')) { @@ -74,7 +75,8 @@ public function process() /** * Get the user resource * + * @param string $access_token * @return UserResource */ - abstract public function getResource($access_token); + abstract public function getResource(string $access_token): UserResource; } diff --git a/src/Provider/FacebookProvider.php b/src/Provider/FacebookProvider.php index 8e206fd..2c4844b 100644 --- a/src/Provider/FacebookProvider.php +++ b/src/Provider/FacebookProvider.php @@ -12,7 +12,7 @@ class FacebookProvider extends AbstractProvider * @param string $access_token * @return UserResource */ - public function getResource($access_token) + public function getResource(string $access_token): UserResource { $resource = $this->provider ->getResourceOwner($access_token); diff --git a/src/Provider/GithubProvider.php b/src/Provider/GithubProvider.php index d014875..7165144 100644 --- a/src/Provider/GithubProvider.php +++ b/src/Provider/GithubProvider.php @@ -8,11 +8,11 @@ class GithubProvider extends AbstractProvider { /** * Get the user resource - * + * * @param string $access_token * @return UserResource */ - public function getResource($access_token) + public function getResource(string $access_token): UserResource { $resource = $this->provider ->getResourceOwner($access_token); diff --git a/src/Provider/GitlabProvider.php b/src/Provider/GitlabProvider.php index a2ec269..c397cc1 100644 --- a/src/Provider/GitlabProvider.php +++ b/src/Provider/GitlabProvider.php @@ -12,7 +12,7 @@ class GitlabProvider extends AbstractProvider * @param string $access_token * @return UserResource */ - public function getResource($access_token) + public function getResource(string $access_token): UserResource { $resource = $this->provider ->getResourceOwner($access_token); diff --git a/src/Soauth.php b/src/Soauth.php index cf6d11b..9ec77cd 100644 --- a/src/Soauth.php +++ b/src/Soauth.php @@ -11,7 +11,7 @@ class Soauth * * @var array */ - const PROVIDERS = [ + private const PROVIDERS = [ 'facebook' => \Bow\Soauth\Provider\FacebookProvider::class, 'gitlab' => \Bow\Soauth\Provider\GitlabProvider::class, 'github' => \Bow\Soauth\Provider\GithubProvider::class @@ -22,15 +22,15 @@ class Soauth * * @var array */ - private static $config; + private static array $config; /** * Make Soauth configuration * * @param array $config - * @return Soauth + * @return void */ - public static function configure($config) + public static function configure(array $config) { static::$config = $config; } @@ -42,7 +42,7 @@ public static function configure($config) * @param array $scope * @return string */ - public static function redirect($provider, $scope = []) + public static function redirect(string $provider, array $scope = []): string { return static::provider($provider)->redirect($scope); } @@ -53,7 +53,7 @@ public static function redirect($provider, $scope = []) * @param string $provider * @return UserResource */ - public static function resource(string $provider) + public static function resource(string $provider): UserResource { return static::provider($provider)->process(); } @@ -62,12 +62,17 @@ public static function resource(string $provider) * Make provider * * @param string $provider - * @return ProviderConfiguration + * @return AbstractProvider */ - private static function provider(string $name) + private static function provider(string $name): AbstractProvider { - $config = static::$config[$name]; - $provider = Soauth::PROVIDERS[$name]; + $config = static::$config[$name] ?? null; + + if (!$config) { + throw new SoauthException("Configuration not exists for the provider $name"); + } + + $provider = static::PROVIDERS[$name]; return new $provider($config); } diff --git a/src/SoauthConfiguration.php b/src/SoauthConfiguration.php index f19b524..abc89b1 100644 --- a/src/SoauthConfiguration.php +++ b/src/SoauthConfiguration.php @@ -11,14 +11,14 @@ class SoauthConfiguration extends Configuration * Create the configuration * * @param Loader $config - * @return mixed + * @return void */ - public function create(Loader $config) + public function create(Loader $config): void { $soauth = (array) $config['soauth']; $soauth = array_merge( - require __DIR__.'/../config/soauth.php', + require __DIR__ . '/../config/soauth.php', $soauth ); @@ -34,8 +34,8 @@ public function create(Loader $config) * * @return mixed */ - public function run() + public function run(): void { - return $this->container->make('soauth'); + $this->container->make('soauth'); } }