From 0fd1e4b5b0b028404427d86f1fd54438e10a3101 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Thu, 10 Nov 2022 16:12:36 +0330 Subject: [PATCH 01/17] docs: fix phpstan error from `Config/ShieldOAuthConfig.php` --- src/Config/ShieldOAuthConfig.php | 78 ++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 25 deletions(-) diff --git a/src/Config/ShieldOAuthConfig.php b/src/Config/ShieldOAuthConfig.php index fbf5e6c..9fa3d2d 100644 --- a/src/Config/ShieldOAuthConfig.php +++ b/src/Config/ShieldOAuthConfig.php @@ -17,6 +17,20 @@ class ShieldOAuthConfig extends BaseConfig { + /** + * -------------------------------------------------------------------------- + * OAuth Configs + * -------------------------------------------------------------------------- + * + * Set keys and active any OAuth + * + * Here you can set the keys received from any OAuth servers. + * for more information on getting keys: + * + * @see https://github.com/datamweb/shield-oauth/blob/develop/docs/get_keys.md + * + * @var array> + */ public array $oauthConfigs = [ 'github' => [ 'client_id' => 'Get it from GitHub', @@ -38,38 +52,52 @@ class ShieldOAuthConfig extends BaseConfig // ], ]; - /* - * If you use different names for the columns in the users table, use the following settings. - - * Data of Table "users": - * +----+----------+--------+...+------------+-----------+--------+ - * | id | username | status |...| first_name | last_name | avatar | - * +----+----------+--------+...+------------+-----------+--------+ - * In fact, you set in which column the information received from the services should be recorded. - * For example, the first name received from OAuth should be recorded in column 'first_name' of the 'users' table shield. - * - * NOTE : - * This is suitable for those who have already installed the shield and created their own columns. - * In this case, there is no need to execute `php spark migrate -n Datamweb\ShieldOAuth`. - * Just set the following values with your table columns. - */ + /** + * -------------------------------------------------------------------------- + * Users Columns Name + * -------------------------------------------------------------------------- + * If you use different names for the columns in the users table, use the following settings. + * + * Data of Table "users": + * +----+----------+--------+...+------------+-----------+--------+ + * | id | username | status |...| first_name | last_name | avatar | + * +----+----------+--------+...+------------+-----------+--------+ + * In fact, you set in which column the information received from the OAuth services should be recorded. + * For example, the first name received from OAuth should be recorded in column 'first_name' of the 'users' table shield. + * NOTE : + * This is suitable for those who have already installed the shield and created their own columns. + * In this case, there is no need to execute `php spark migrate -n Datamweb\ShieldOAuth`. + * Just set the following values with your table columns. + * + * @var array + */ public array $usersColumnsName = [ 'first_name' => 'first_name', 'last_name' => 'last_name', 'avatar' => 'avatar', ]; - /* - * If the user is already registered, by default when trying to login, he/she information will be synchronized. - * if you want to cancel it, set false. - */ + /** + * -------------------------------------------------------------------------- + * Syncing User Info + * -------------------------------------------------------------------------- + * Turn ON/OFF user data update + * + * If the user is already registered, by default when trying to login, he/she information will be synchronized. + * if you want to cancel it, set false. + */ public bool $syncingUserInfo = true; - /* - * When the user login with his profile, the OAuth server directs him to the following path. - * So change this value only when you need to make an order. - * By default it returns to the following path: - * http:\\localhost:8080\oauth\call-back - */ + /** + * -------------------------------------------------------------------------- + * Call Back Route + * -------------------------------------------------------------------------- + * Set your custom call-back name + * + * When the user login with his profile, the OAuth server directs him to the following path. + * So change this value only when you need to make an customez. + * By default it returns to the following path: + * http:\\localhost:8080\oauth\call-back + */ public string $call_back_route = 'call-back'; } From 73b861fd34f5461216e7a4c0f1bee76c1bc01ba4 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Thu, 10 Nov 2022 18:54:39 +0330 Subject: [PATCH 02/17] docs: fix phpstan error from `Config/Registrar.php` --- src/Config/Registrar.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Config/Registrar.php b/src/Config/Registrar.php index 93fec7e..5beaf68 100644 --- a/src/Config/Registrar.php +++ b/src/Config/Registrar.php @@ -18,9 +18,16 @@ class Registrar { /** + * -------------------------------------------------------------------------- + * Shield OAuth Decorator + * -------------------------------------------------------------------------- * Register the ShieldOAuth decorator. + * + * @see https://codeigniter.com/user_guide/outgoing/view_decorators.html + * + * @return array> */ - public static function View(): array + public static function View() { return [ 'decorators' => [ From 33505f312f17a8417d47bb68d06f81185a3c0d4d Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Sat, 12 Nov 2022 00:30:21 +0330 Subject: [PATCH 03/17] docs: fix phpstan error from `Config/Services.php` --- src/Config/Services.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Config/Services.php b/src/Config/Services.php index a36f3cb..42f8c2d 100644 --- a/src/Config/Services.php +++ b/src/Config/Services.php @@ -18,12 +18,24 @@ class Services extends BaseService { + /** + * ------------------------------------------------------- + * Service Configuration file + * ------------------------------------------------------- + * Create and share new class instances + * + * More Info @see https://codeigniter.com/user_guide/concepts/services.html + * + * @param mixed $getShared + * + * @return mixed|ShieldOAuth + */ public static function ShieldOAuth($getShared = true) { if ($getShared) { return static::getSharedInstance('ShieldOAuth'); } - return new ShieldOAuth(new ShieldOAuthConfig()); + return new ShieldOAuth(); } } From f4590042dbad1ce3870245a8f6cfb3ff923128f8 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Fri, 11 Nov 2022 17:51:12 +0330 Subject: [PATCH 04/17] fix: update for use `list` Co-authored-by: MGatner docs: fix phpstan error from `Config/Services.php` --- src/Config/Registrar.php | 2 +- src/Config/Services.php | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Config/Registrar.php b/src/Config/Registrar.php index 5beaf68..b2309b8 100644 --- a/src/Config/Registrar.php +++ b/src/Config/Registrar.php @@ -25,7 +25,7 @@ class Registrar * * @see https://codeigniter.com/user_guide/outgoing/view_decorators.html * - * @return array> + * @return array> */ public static function View() { diff --git a/src/Config/Services.php b/src/Config/Services.php index 42f8c2d..6445752 100644 --- a/src/Config/Services.php +++ b/src/Config/Services.php @@ -26,11 +26,9 @@ class Services extends BaseService * * More Info @see https://codeigniter.com/user_guide/concepts/services.html * - * @param mixed $getShared - * * @return mixed|ShieldOAuth */ - public static function ShieldOAuth($getShared = true) + public static function ShieldOAuth(bool $getShared = true) { if ($getShared) { return static::getSharedInstance('ShieldOAuth'); From 15257bc1d73e00c041896aae698eca39d3c8de6f Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Sun, 13 Nov 2022 18:27:49 +0330 Subject: [PATCH 05/17] docs: fix phpstan error from `Config/Routes.php` --- src/Config/Routes.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Config/Routes.php b/src/Config/Routes.php index 783e3ac..c7134d0 100644 --- a/src/Config/Routes.php +++ b/src/Config/Routes.php @@ -11,9 +11,18 @@ * the LICENSE file that was distributed with this source code. */ +/** + * @var CodeIgniter\Router\RouteCollection $routes + */ $routes->group('oauth', ['namespace' => '\Datamweb\ShieldOAuth\Controllers'], static function ($routes): void { - $routes->addPlaceholder('allOAuthList', service('ShieldOAuth')->allOAuth()); + /** @var \Datamweb\ShieldOAuth\Libraries\Basic\ShieldOAuth $shieldOAuthLib */ + $shieldOAuthLib = service('ShieldOAuth'); + + $routes->addPlaceholder('allOAuthList', $shieldOAuthLib->allOAuth()); $routes->get('(:allOAuthList)', 'OAuthController::redirectOAuth/$1'); - $routes->get(config('ShieldOAuthConfig')->call_back_route, 'OAuthController::callBack'); + /** @var \Datamweb\ShieldOAuth\Config\ShieldOAuthConfig $config */ + $config = config('ShieldOAuthConfig'); + + $routes->get($config->call_back_route, 'OAuthController::callBack'); }); From 29f9b5221ced7ac9dce3a0f84935e60735db25e3 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Sun, 13 Nov 2022 22:56:07 +0330 Subject: [PATCH 06/17] docs: fix phpstan error from `Models/ShieldOAuthModel.php` --- src/Models/ShieldOAuthModel.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Models/ShieldOAuthModel.php b/src/Models/ShieldOAuthModel.php index d6ada63..c8e46fd 100644 --- a/src/Models/ShieldOAuthModel.php +++ b/src/Models/ShieldOAuthModel.php @@ -14,17 +14,22 @@ namespace Datamweb\ShieldOAuth\Models; use CodeIgniter\Shield\Models\UserModel; +use Datamweb\ShieldOAuth\Config\ShieldOAuthConfig; class ShieldOAuthModel extends UserModel { protected function initialize(): void { parent::initialize(); + + /** @var ShieldOAuthConfig $config */ + $config = config(ShieldOAuthConfig::class); + // Merge properties with parent $this->allowedFields = array_merge($this->allowedFields, [ - config('ShieldOAuthConfig')->usersColumnsName['first_name'], - config('ShieldOAuthConfig')->usersColumnsName['last_name'], - config('ShieldOAuthConfig')->usersColumnsName['avatar'], + $config->usersColumnsName['first_name'], + $config->usersColumnsName['last_name'], + $config->usersColumnsName['avatar'], ]); } } From 4844eb08a56091f0e34c972fbb5e73f4d22c9555 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Sun, 13 Nov 2022 23:44:50 +0330 Subject: [PATCH 07/17] docs: fix phpstan error from `Migrations\2022-10-20-182737_ShieldOAuth.php` --- .../Migrations/2022-10-20-182737_ShieldOAuth.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Database/Migrations/2022-10-20-182737_ShieldOAuth.php b/src/Database/Migrations/2022-10-20-182737_ShieldOAuth.php index 5a5422b..bacb90d 100644 --- a/src/Database/Migrations/2022-10-20-182737_ShieldOAuth.php +++ b/src/Database/Migrations/2022-10-20-182737_ShieldOAuth.php @@ -14,16 +14,23 @@ namespace Datamweb\ShieldOAuth\Database\Migrations; use CodeIgniter\Database\Migration; +use Datamweb\ShieldOAuth\Config\ShieldOAuthConfig; class ShieldOAuth extends Migration { + private string $first_name; + private string $last_name; + private string $avatar; + public function __construct() { parent::__construct(); - $this->first_name = config('ShieldOAuthConfig')->usersColumnsName['first_name']; - $this->last_name = config('ShieldOAuthConfig')->usersColumnsName['last_name']; - $this->avatar = config('ShieldOAuthConfig')->usersColumnsName['avatar']; + /** @var ShieldOAuthConfig $config */ + $config = config(ShieldOAuthConfig::class); + $this->first_name = $config->usersColumnsName['first_name']; + $this->last_name = $config->usersColumnsName['last_name']; + $this->avatar = $config->usersColumnsName['avatar']; } public function up(): void From 54e85f1e28ef7a50c90ce48477c3309e7685d94b Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Mon, 14 Nov 2022 20:42:00 +0330 Subject: [PATCH 08/17] docs: fix phpstan error from `Basic/ControllersInterface.php` --- src/Libraries/Basic/ControllersInterface.php | 26 ++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Libraries/Basic/ControllersInterface.php b/src/Libraries/Basic/ControllersInterface.php index f7d2a32..e5fcd62 100644 --- a/src/Libraries/Basic/ControllersInterface.php +++ b/src/Libraries/Basic/ControllersInterface.php @@ -13,9 +13,31 @@ namespace Datamweb\ShieldOAuth\Libraries\Basic; +use CodeIgniter\HTTP\RedirectResponse; + interface ControllersInterface { - public function redirectOAuth(string $oauthName); + /** + * ------------------------------------------------------------------------------------------- + * Users Redirected to Request Their OAuth Identity + * ------------------------------------------------------------------------------------------- + * + * The user is redirected to the specified URL for login to any OAuth service with credentials. + * Each OAuth service provides how to create a link for validation based on its instructions. + * For example, Github is explained here. + * + * @see https://docs.github.com/en/developers/apps/building-oauth-apps/authorizing-oauth-apps#1-request-a-users-github-identity + */ + public function redirectOAuth(string $oauthName): RedirectResponse; - public function callBack(); + /** + * ------------------------------------------------------------------------------------------- + * Call Back From Every OAuth Service + * ------------------------------------------------------------------------------------------- + * + * User return after credentials are valid or invalid in each OAuth service + * If the user is valid in OAuth Service, the new user is registered or login if there is one in shield user table. + * Otherwise, error messages will be displayed. + */ + public function callBack(): RedirectResponse; } From 62d17ed5096043004ba4c23e5bb9a783a012cda6 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Tue, 15 Nov 2022 01:18:30 +0330 Subject: [PATCH 09/17] docs: fix phpstan error from `Basic/ShieldOAuth.php` --- src/Libraries/Basic/ShieldOAuth.php | 63 +++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/src/Libraries/Basic/ShieldOAuth.php b/src/Libraries/Basic/ShieldOAuth.php index c3653d0..bcd2302 100644 --- a/src/Libraries/Basic/ShieldOAuth.php +++ b/src/Libraries/Basic/ShieldOAuth.php @@ -15,37 +15,52 @@ use CodeIgniter\Config\Factories; use CodeIgniter\Files\FileCollection; +use Config\Autoload; class ShieldOAuth { + /** + * -------------------------------------------------------------------- + * Set OAuth + * -------------------------------------------------------------------- + * This function creating instances of OAuth class chosen by the user + * + * This function has the ability to identify classes in two Paths: + * + * - \App\Libraries\ShieldOAuth\ for load any OAuth custom class created by the user + * - \Datamweb\ShieldOAuth\Libraries\ for load GithubOAuth or GoogleOAuth class + */ public static function setOAuth(string $serviceName): object { $serviceName = ucfirst($serviceName); $className = '\Datamweb\ShieldOAuth\Libraries\\' . $serviceName . 'OAuth'; - // For to detect custom OAuth + // For detect custom OAuth if (file_exists(APPPATH . 'Libraries/ShieldOAuth' . DIRECTORY_SEPARATOR . $serviceName . 'OAuth.php')) { - $className = 'App\Libraries\ShieldOAuth\\' . $serviceName . 'OAuth'; + $className = '\App\Libraries\ShieldOAuth\\' . $serviceName . 'OAuth'; } - return $oauthClass = Factories::loadOAuth($className); + return Factories::loadOAuth($className); // @phpstan-ignore-line } /** * -------------------------------------------------------------------- - * Names of all supported services + * Names of all supported OAuth services * -------------------------------------------------------------------- - * Here we have recorded the list of all the services with which it is possible to login. + * List of all the OAuth services * - * Returns the names of all supported services for use in routes - * e.g. 'github|google|yahoo|...' - * Note: @see https://codeigniter.com/user_guide/incoming/routing.html#custom-placeholders + * Identifies all OAuth classes and generates a string according to the file name of the classes as follows. + * e.g. 'github|google|yahoo' ... */ public function allOAuth(): string { $files = new FileCollection(); + + /** @var Autoload $autoload */ + $autoload = config(Autoload::class); + // Checking if it is installed manually - if (array_key_exists('Datamweb\ShieldOAuth', Config('Autoload')->psr4)) { + if (array_key_exists('Datamweb\ShieldOAuth', $autoload->psr4)) { // Adds all Libraries files $files = $files->add(APPPATH . 'ThirdParty/shield-oauth/src/Libraries', false); } else { @@ -59,23 +74,45 @@ public function allOAuth(): string // show only all *OAuth.php files $files = $files->retainPattern('*OAuth.php'); - $allAllowedRoutes = ''; + $allOAuth = ''; foreach ($files as $file) { // make string github|google and ... from class name - $allAllowedRoutes .= strtolower(str_replace($search = 'OAuth.php', $replace = '|', $subject = $file->getBasename())); + $allOAuth .= strtolower(str_replace('OAuth.php', '|', $file->getBasename())); } - return mb_substr($allAllowedRoutes, 0, -1); + return mb_substr($allOAuth, 0, -1); } - private function otherOAuth(): array + /** + * -------------------------------------------------------------------- + * Names of all Custom OAuth + * -------------------------------------------------------------------- + * List of all just CustomOAuth services + * + * Returns array of all Custom OAuth classes file name + * e.g. ['yahoo'] + * + * @return array + */ + private function otherOAuth() { $pieces = explode('|', $this->allOAuth()); return array_diff($pieces, ['github', 'google']); } + /** + * -------------------------------------------------------------------- + * Make OAuth Button + * -------------------------------------------------------------------- + * Creates OAuth buttons based on existing OAuth classes + * + * Group a series of buttons together on a single line by bootstrap 5.0 + * + * @see https://getbootstrap.com/docs/5.0/components/button-group/#nesting + * @see https://getbootstrap.com/docs/5.0/components/button-group/#basic-example + */ public function makeOAuthButton(string $forPage = 'login'): string { $active_by = lang('ShieldOAuthLang.login_by'); From 5050969b9b3374df157e451a052959f7df0c3390 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 23 Aug 2023 15:01:43 +0900 Subject: [PATCH 10/17] refactor: fix file path --- src/Libraries/Basic/ShieldOAuth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libraries/Basic/ShieldOAuth.php b/src/Libraries/Basic/ShieldOAuth.php index bcd2302..a016fda 100644 --- a/src/Libraries/Basic/ShieldOAuth.php +++ b/src/Libraries/Basic/ShieldOAuth.php @@ -65,7 +65,7 @@ public function allOAuth(): string $files = $files->add(APPPATH . 'ThirdParty/shield-oauth/src/Libraries', false); } else { // Adds all Libraries files if install via composer - $files = $files->add(VENDORPATH . 'datamweb/shield-oauth/src/Libraries', false); + $files = $files->add(__DIR__ . '/..', false); } // For to detect custom OAuth if (is_dir(APPPATH . 'Libraries/ShieldOAuth')) { From b766d903c7f55b2fdf4242025bbd56f192075d07 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 23 Aug 2023 15:24:57 +0900 Subject: [PATCH 11/17] fix: add missing return types --- src/Controllers/OAuthController.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Controllers/OAuthController.php b/src/Controllers/OAuthController.php index c975433..ea78ddc 100644 --- a/src/Controllers/OAuthController.php +++ b/src/Controllers/OAuthController.php @@ -14,12 +14,13 @@ namespace Datamweb\ShieldOAuth\Controllers; use App\Controllers\BaseController; +use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\Shield\Entities\User; use Datamweb\ShieldOAuth\Libraries\Basic\ControllersInterface; class OAuthController extends BaseController implements ControllersInterface { - public function redirectOAuth(string $oauthName) + public function redirectOAuth(string $oauthName): RedirectResponse { // if user login if (auth()->loggedIn()) { @@ -45,7 +46,7 @@ public function redirectOAuth(string $oauthName) return redirect()->to($redirectLink); } - public function callBack() + public function callBack(): RedirectResponse { // if user after callback request url if (! session('oauth_name')) { From 5b07d109bb9c079a50f21adda0d36ca606927a9c Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 23 Aug 2023 15:02:13 +0900 Subject: [PATCH 12/17] chore: add phpstan.neon.dist --- phpstan.neon.dist | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 phpstan.neon.dist diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..6de2545 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,21 @@ +parameters: + tmpDir: build/phpstan + level: 6 + paths: + - src/ + bootstrapFiles: + - vendor/codeigniter4/framework/system/Test/bootstrap.php + excludePaths: + - app/Config/Routes.php + - app/Views/* + ignoreErrors: + universalObjectCratesClasses: + - CodeIgniter\Entity + - CodeIgniter\Entity\Entity + - Faker\Generator + scanDirectories: + - vendor/codeigniter4/framework/system/Helpers + dynamicConstantNames: + - APP_NAMESPACE + - CI_DEBUG + - ENVIRONMENT From d0f71618c4b848372d22fae1e62a9dd381e4850e Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 23 Aug 2023 15:04:21 +0900 Subject: [PATCH 13/17] chore: add baseline for PHPStan vendor/bin/phpstan analyse -b phpstan-baseline.php --- phpstan-baseline.php | 188 +++++++++++++++++++++++++++++++++++++++++++ phpstan.neon.dist | 2 + 2 files changed, 190 insertions(+) create mode 100644 phpstan-baseline.php diff --git a/phpstan-baseline.php b/phpstan-baseline.php new file mode 100644 index 0000000..33beca3 --- /dev/null +++ b/phpstan-baseline.php @@ -0,0 +1,188 @@ + '#^Method Datamweb\\\\ShieldOAuth\\\\Commands\\\\OAuthSetup\\:\\:copyAndReplace\\(\\) has parameter \\$replaces with no value type specified in iterable type array\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Commands/OAuthSetup.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Commands\\\\OAuthSetup\\:\\:\\$arguments type has no value type specified in iterable type array\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Commands/OAuthSetup.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Commands\\\\OAuthSetup\\:\\:\\$distPath has no type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Commands/OAuthSetup.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Datamweb\\\\ShieldOAuth\\\\Config\\\\Registrar\\:\\:Generators\\(\\) return type has no value type specified in iterable type array\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Config/Registrar.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Call to deprecated function random_string\\(\\)\\: +The type \'basic\', \'md5\', and \'sha1\' are deprecated\\. They are not cryptographically secure\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Controllers/OAuthController.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Class Datamweb\\\\ShieldOAuth\\\\Controllers\\\\LoginModel not found\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Controllers/OAuthController.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Datamweb\\\\ShieldOAuth\\\\Controllers\\\\OAuthController\\:\\:checkExistenceUser\\(\\) has parameter \\$find with no value type specified in iterable type array\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Controllers/OAuthController.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Datamweb\\\\ShieldOAuth\\\\Controllers\\\\OAuthController\\:\\:syncingUserInfo\\(\\) has parameter \\$find with no value type specified in iterable type array\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Controllers/OAuthController.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Datamweb\\\\ShieldOAuth\\\\Controllers\\\\OAuthController\\:\\:syncingUserInfo\\(\\) has parameter \\$updateFildes with no value type specified in iterable type array\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Controllers/OAuthController.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Access to an undefined property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\Basic\\\\AbstractOAuth\\:\\:\\$token\\.$#', + 'count' => 2, + 'path' => __DIR__ . '/src/Libraries/Basic/AbstractOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Datamweb\\\\ShieldOAuth\\\\Libraries\\\\Basic\\\\AbstractOAuth\\:\\:fetchAccessTokenWithAuthCode\\(\\) has parameter \\$allGet with no value type specified in iterable type array\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/Basic/AbstractOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Datamweb\\\\ShieldOAuth\\\\Libraries\\\\Basic\\\\AbstractOAuth\\:\\:getColumnsName\\(\\) return type has no value type specified in iterable type array\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/Basic/AbstractOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Datamweb\\\\ShieldOAuth\\\\Libraries\\\\Basic\\\\AbstractOAuth\\:\\:getUserInfo\\(\\) has parameter \\$allGet with no value type specified in iterable type array\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/Basic/AbstractOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Datamweb\\\\ShieldOAuth\\\\Libraries\\\\Basic\\\\AbstractOAuth\\:\\:setColumnsName\\(\\) return type has no value type specified in iterable type array\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/Basic/AbstractOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Call to deprecated function random_string\\(\\)\\: +The type \'basic\', \'md5\', and \'sha1\' are deprecated\\. They are not cryptographically secure\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GithubOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GithubOAuth\\:\\:fetchAccessTokenWithAuthCode\\(\\) has parameter \\$allGet with no value type specified in iterable type array\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GithubOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GithubOAuth\\:\\:setColumnsName\\(\\) has parameter \\$userInfo with no type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GithubOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GithubOAuth\\:\\:setColumnsName\\(\\) return type has no value type specified in iterable type array\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GithubOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GithubOAuth\\:\\:\\$API_CODE_URL has no type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GithubOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GithubOAuth\\:\\:\\$API_TOKEN_URL has no type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GithubOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GithubOAuth\\:\\:\\$API_USER_INFO_URL has no type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GithubOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GithubOAuth\\:\\:\\$APPLICATION_NAME has no type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GithubOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GithubOAuth\\:\\:\\$client has no type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GithubOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GithubOAuth\\:\\:\\$config has no type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GithubOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Variable \\$usersColumnsName might not be defined\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GithubOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Call to deprecated function random_string\\(\\)\\: +The type \'basic\', \'md5\', and \'sha1\' are deprecated\\. They are not cryptographically secure\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GoogleOAuth\\:\\:fetchAccessTokenWithAuthCode\\(\\) has parameter \\$allGet with no value type specified in iterable type array\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GoogleOAuth\\:\\:setColumnsName\\(\\) has parameter \\$userInfo with no type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GoogleOAuth\\:\\:setColumnsName\\(\\) return type has no value type specified in iterable type array\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GoogleOAuth\\:\\:\\$API_CODE_URL has no type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GoogleOAuth\\:\\:\\$API_TOKEN_URL has no type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GoogleOAuth\\:\\:\\$API_USER_INFO_URL has no type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GoogleOAuth\\:\\:\\$APPLICATION_NAME has no type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GoogleOAuth\\:\\:\\$client has no type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GoogleOAuth\\:\\:\\$config has no type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Variable \\$usersColumnsName might not be defined\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php', +]; + +return ['parameters' => ['ignoreErrors' => $ignoreErrors]]; diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 6de2545..a0a60eb 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,3 +1,5 @@ +includes: + - phpstan-baseline.php parameters: tmpDir: build/phpstan level: 6 From 92683879d2c9d00c2cfc5375f0d811fb27cd902b Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 23 Aug 2023 15:33:20 +0900 Subject: [PATCH 14/17] refactor: add missing return type --- src/Config/Registrar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Config/Registrar.php b/src/Config/Registrar.php index b2309b8..bc2459b 100644 --- a/src/Config/Registrar.php +++ b/src/Config/Registrar.php @@ -27,7 +27,7 @@ class Registrar * * @return array> */ - public static function View() + public static function View(): array { return [ 'decorators' => [ From a904cd16fd6e2a677e7190a51912a93c94631dac Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 23 Aug 2023 15:33:57 +0900 Subject: [PATCH 15/17] fix: import undefined LoginModel --- src/Controllers/OAuthController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Controllers/OAuthController.php b/src/Controllers/OAuthController.php index ea78ddc..1b26e9a 100644 --- a/src/Controllers/OAuthController.php +++ b/src/Controllers/OAuthController.php @@ -16,6 +16,7 @@ use App\Controllers\BaseController; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\Shield\Entities\User; +use CodeIgniter\Shield\Models\LoginModel; use Datamweb\ShieldOAuth\Libraries\Basic\ControllersInterface; class OAuthController extends BaseController implements ControllersInterface From b027583743eb05e25d63e496b6b07a1c1dfe4a86 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 23 Aug 2023 15:36:32 +0900 Subject: [PATCH 16/17] refactor: add missing return type --- src/Config/Services.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Config/Services.php b/src/Config/Services.php index 6445752..4d7bf2c 100644 --- a/src/Config/Services.php +++ b/src/Config/Services.php @@ -25,10 +25,8 @@ class Services extends BaseService * Create and share new class instances * * More Info @see https://codeigniter.com/user_guide/concepts/services.html - * - * @return mixed|ShieldOAuth */ - public static function ShieldOAuth(bool $getShared = true) + public static function ShieldOAuth(bool $getShared = true): ShieldOAuth { if ($getShared) { return static::getSharedInstance('ShieldOAuth'); From 0f27698d3524342f0ba8e3c365fabcabd38afb9d Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 23 Aug 2023 15:41:33 +0900 Subject: [PATCH 17/17] docs: fix comments --- src/Config/ShieldOAuthConfig.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Config/ShieldOAuthConfig.php b/src/Config/ShieldOAuthConfig.php index 9fa3d2d..c572160 100644 --- a/src/Config/ShieldOAuthConfig.php +++ b/src/Config/ShieldOAuthConfig.php @@ -83,8 +83,8 @@ class ShieldOAuthConfig extends BaseConfig * -------------------------------------------------------------------------- * Turn ON/OFF user data update * - * If the user is already registered, by default when trying to login, he/she information will be synchronized. - * if you want to cancel it, set false. + * If the user is already registered, by default when trying to login, their + * information will be synchronized. If you want to cancel it, set to false. */ public bool $syncingUserInfo = true; @@ -95,9 +95,9 @@ class ShieldOAuthConfig extends BaseConfig * Set your custom call-back name * * When the user login with his profile, the OAuth server directs him to the following path. - * So change this value only when you need to make an customez. - * By default it returns to the following path: - * http:\\localhost:8080\oauth\call-back + * So change this value only when you need to customize it. + * By default, it returns to the following path: + * http://localhost:8080/oauth/call-back */ public string $call_back_route = 'call-back'; }