diff --git a/composer.json b/composer.json index 34694f12..559033d1 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "wp-coding-standards/wpcs": "^3.0", "humbug/php-scoper": "^0.18.1", "skaut/wordpress-stubs": "^2.1", - "phpstan/phpstan": "^1.6", + "phpstan/phpstan": "^2.0", "dealerdirect/phpcodesniffer-composer-installer": "^1.0" } } diff --git a/composer.lock b/composer.lock index 59ba97b7..55f79f39 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c832e8ef6a5dac31452470f3d155538a", + "content-hash": "0dbfec5be1437061e51e3fc6c6e0dcfc", "packages": [ { "name": "skautis/skautis", @@ -1726,20 +1726,20 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.8", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "f6a60a4d66142b8156c9da923f1972657bc4748c" + "reference": "6c98c7600fc717b2c78c11ef60040d5b1e359c82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/f6a60a4d66142b8156c9da923f1972657bc4748c", - "reference": "f6a60a4d66142b8156c9da923f1972657bc4748c", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/6c98c7600fc717b2c78c11ef60040d5b1e359c82", + "reference": "6c98c7600fc717b2c78c11ef60040d5b1e359c82", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": "^7.4|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -1780,7 +1780,7 @@ "type": "github" } ], - "time": "2024-11-06T19:06:49+00:00" + "time": "2024-11-17T14:17:00+00:00" }, { "name": "psr/container", diff --git a/src/php/class-skautis-integration.php b/src/php/class-skautis-integration.php index 4620f16c..5283ec95 100644 --- a/src/php/class-skautis-integration.php +++ b/src/php/class-skautis-integration.php @@ -128,10 +128,12 @@ protected static function is_compatible_version_of_wp() { * @return bool Whether the current version of PHP is supported. */ protected static function is_compatible_version_of_php() { + // @phpstan-ignore if.alwaysTrue if ( version_compare( PHP_VERSION, '7.4', '>=' ) ) { return true; } + // @phpstan-ignore deadCode.unreachable return false; } diff --git a/src/php/src/admin/class-admin.php b/src/php/src/admin/class-admin.php index 85684329..143e365d 100644 --- a/src/php/src/admin/class-admin.php +++ b/src/php/src/admin/class-admin.php @@ -118,22 +118,13 @@ public function add_logout_link_to_admin_bar( \WP_Admin_Bar $wp_admin_bar ) { if ( ! is_admin_bar_showing() ) { return; } - - if ( method_exists( $wp_admin_bar, 'get_node' ) ) { - if ( ! is_null( $wp_admin_bar->get_node( 'user-actions' ) ) ) { - $parent = 'user-actions'; - } else { - return; - } - } elseif ( 1 === get_option( 'show_avatars' ) ) { - $parent = 'my-account-with-avatar'; - } else { - $parent = 'my-account'; + if ( is_null( $wp_admin_bar->get_node( 'user-actions' ) ) ) { + return; } $wp_admin_bar->add_menu( array( - 'parent' => $parent, + 'parent' => 'user-actions', 'id' => SKAUTIS_INTEGRATION_NAME . '_adminBar_logout', 'title' => esc_html__( 'Log Out (too from skautIS)', 'skautis-integration' ), 'href' => $this->wp_login_logout->get_logout_url(), diff --git a/src/php/src/auth/class-connect-and-disconnect-wp-account.php b/src/php/src/auth/class-connect-and-disconnect-wp-account.php index a2e5a0cf..45b06752 100644 --- a/src/php/src/auth/class-connect-and-disconnect-wp-account.php +++ b/src/php/src/auth/class-connect-and-disconnect-wp-account.php @@ -51,7 +51,7 @@ public function __construct( Skautis_Gateway $skautis_gateway, Skautis_Login $sk * * @return void * - * @SuppressWarnings(PHPMD.ExitExpression) + * @SuppressWarnings("PHPMD.ExitExpression") */ private function set_skautis_user_id_to_wp_account( int $wp_user_id, int $skautis_user_id ) { $return_url = Helpers::get_return_url(); @@ -110,7 +110,7 @@ class="button">' . esc_html__( 'Propojit tento účet se skautISem', 'skautis-in * * @return void * - * @SuppressWarnings(PHPMD.ExitExpression) + * @SuppressWarnings("PHPMD.ExitExpression") */ public function connect() { if ( ! $this->skautis_login->is_user_logged_in_skautis() ) { @@ -186,7 +186,7 @@ public function get_connect_wp_user_to_skautis_url(): string { * * @return void * - * @SuppressWarnings(PHPMD.ExitExpression) + * @SuppressWarnings("PHPMD.ExitExpression") */ public function disconnect() { if ( is_user_logged_in() ) { @@ -199,10 +199,11 @@ public function disconnect() { } elseif ( ( strpos( $return_url, 'user-edit_php' ) !== false || strpos( $return_url, 'user-edit.php' ) !== false ) && strpos( $return_url, 'user_id=' ) !== false ) { + $result = array(); if ( 1 !== preg_match( '~user_id=(\d+)~', $return_url, $result ) ) { return; } - if ( is_array( $result ) && $result[1] > 0 ) { + if ( $result[1] > 0 ) { $user_id = absint( $result[1] ); if ( Helpers::user_is_skautis_manager() ) { delete_user_meta( $user_id, 'skautisUserId_' . $this->skautis_gateway->get_env() ); diff --git a/src/php/src/auth/class-skautis-gateway.php b/src/php/src/auth/class-skautis-gateway.php index 1f96382f..cb7f8484 100644 --- a/src/php/src/auth/class-skautis-gateway.php +++ b/src/php/src/auth/class-skautis-gateway.php @@ -95,7 +95,7 @@ public function get_env(): string { /** * Returns the raw SkauIS library instance * - * @SuppressWarnings(PHPMD.ExitExpression) + * @SuppressWarnings("PHPMD.ExitExpression") */ public function get_skautis_instance(): Skautis\Skautis { if ( ! ( $this->skautis instanceof Skautis\Skautis ) ) { diff --git a/src/php/src/auth/class-skautis-login.php b/src/php/src/auth/class-skautis-login.php index ae6000dc..c45d48eb 100644 --- a/src/php/src/auth/class-skautis-login.php +++ b/src/php/src/auth/class-skautis-login.php @@ -86,7 +86,7 @@ public function set_login_data_to_local_skautis_instance( array $data = array() * * @return void * - * @SuppressWarnings(PHPMD.ExitExpression) + * @SuppressWarnings("PHPMD.ExitExpression") */ public function login() { $return_url = Helpers::get_login_logout_redirect(); @@ -115,7 +115,7 @@ public function login() { * * @return void * - * @SuppressWarnings(PHPMD.ExitExpression) + * @SuppressWarnings("PHPMD.ExitExpression") */ public function login_confirm() { $return_url = Helpers::get_return_url(); diff --git a/src/php/src/auth/class-wp-login-logout.php b/src/php/src/auth/class-wp-login-logout.php index 0d98d6a2..b8b9bd91 100644 --- a/src/php/src/auth/class-wp-login-logout.php +++ b/src/php/src/auth/class-wp-login-logout.php @@ -43,7 +43,7 @@ public function __construct( Skautis_Gateway $skautis_gateway ) { * * @return false * - * @SuppressWarnings(PHPMD.ExitExpression) + * @SuppressWarnings("PHPMD.ExitExpression") */ private function login_wp_user_by_skautis_user_id( int $skautis_user_id, $dont_die_on_error = false ) { $return_url = Helpers::get_return_url(); @@ -196,7 +196,7 @@ public function try_to_login_to_wp() { * * @return void * - * @SuppressWarnings(PHPMD.ExitExpression) + * @SuppressWarnings("PHPMD.ExitExpression") */ public function logout() { $this->skautis_gateway->logout(); diff --git a/src/php/src/frontend/class-frontend.php b/src/php/src/frontend/class-frontend.php index d5d6cda4..e1853f51 100644 --- a/src/php/src/frontend/class-frontend.php +++ b/src/php/src/frontend/class-frontend.php @@ -145,22 +145,13 @@ public function add_logout_link_to_admin_bar( \WP_Admin_Bar $wp_admin_bar ) { if ( ! is_admin_bar_showing() ) { return; } - - if ( method_exists( $wp_admin_bar, 'get_node' ) ) { - if ( ! is_null( $wp_admin_bar->get_node( 'user-actions' ) ) ) { - $parent = 'user-actions'; - } else { - return; - } - } elseif ( 1 === get_option( 'show_avatars' ) ) { - $parent = 'my-account-with-avatar'; - } else { - $parent = 'my-account'; + if ( is_null( $wp_admin_bar->get_node( 'user-actions' ) ) ) { + return; } $wp_admin_bar->add_menu( array( - 'parent' => $parent, + 'parent' => 'user-actions', 'id' => SKAUTIS_INTEGRATION_NAME . '_adminBar_logout', 'title' => esc_html__( 'Odhlásit se (i ze skautISu)', 'skautis-integration' ), 'href' => $this->wp_login_logout->get_logout_url(), diff --git a/src/php/src/general/class-actions.php b/src/php/src/general/class-actions.php index f560be4a..1a163cc6 100644 --- a/src/php/src/general/class-actions.php +++ b/src/php/src/general/class-actions.php @@ -169,7 +169,7 @@ public function auth_in_process() { * * @param \WP_Query $wp_query The request query. * - * @SuppressWarnings(PHPMD.ExitExpression) + * @SuppressWarnings("PHPMD.ExitExpression") * * @return \WP_Query|void */ diff --git a/src/php/src/modules/Register/class-register.php b/src/php/src/modules/Register/class-register.php index 1ec9f53e..32ef4058 100644 --- a/src/php/src/modules/Register/class-register.php +++ b/src/php/src/modules/Register/class-register.php @@ -123,7 +123,7 @@ private function init_hooks() { * * @return void * - * @SuppressWarnings(PHPMD.ExitExpression) + * @SuppressWarnings("PHPMD.ExitExpression") */ private function loginUserAfterRegistration() { $return_url = Helpers::get_login_logout_redirect(); @@ -216,7 +216,7 @@ public function getRulesManager(): Rules_Manager { * * @return void * - * @SuppressWarnings(PHPMD.ExitExpression) + * @SuppressWarnings("PHPMD.ExitExpression") */ public function register() { if ( ! $this->skautis_login->is_user_logged_in_skautis() ) { @@ -269,7 +269,7 @@ public function registerUser() { * * @return void * - * @SuppressWarnings(PHPMD.ExitExpression) + * @SuppressWarnings("PHPMD.ExitExpression") */ public function registerUserManually() { $return_url = Helpers::get_return_url(); diff --git a/src/php/src/modules/Register/class-wp-register.php b/src/php/src/modules/Register/class-wp-register.php index 807a3db4..74c6bed4 100644 --- a/src/php/src/modules/Register/class-wp-register.php +++ b/src/php/src/modules/Register/class-wp-register.php @@ -53,7 +53,7 @@ public function __construct( Skautis_Gateway $skautis_gateway, UsersRepository $ * * @return int The ID of the new user. * - * @SuppressWarnings(PHPMD.ExitExpression) + * @SuppressWarnings("PHPMD.ExitExpression") */ private static function resolve_notifications_and_register_user_to_wp( string $user_login, string $user_email ) { remove_action( 'register_new_user', 'wp_send_new_user_notifications' ); @@ -171,7 +171,7 @@ private function process_wp_user_registration( array $user, string $wp_role ): b $user_id = self::resolve_notifications_and_register_user_to_wp( $username, $user['email'] ); - if ( 0 === $user_id || ! is_int( $user_id ) ) { + if ( 0 === $user_id ) { return false; } diff --git a/src/php/src/repository/class-users.php b/src/php/src/repository/class-users.php index 8c5c2618..80af4ca9 100644 --- a/src/php/src/repository/class-users.php +++ b/src/php/src/repository/class-users.php @@ -214,7 +214,7 @@ static function ( $participant ) { if ( isset( $participant->PersonEmail ) && ! empty( $participant->PersonEmail ) ) { $emails = preg_split( '~(?=\,)~x', $participant->PersonEmail ); - if ( ! empty( $emails ) && isset( $emails[0] ) ) { + if ( isset( $emails[0] ) ) { $user->email = $emails[0]; } } else { diff --git a/src/php/src/rules/Rule/class-func.php b/src/php/src/rules/Rule/class-func.php index e0aecc6f..4735c10a 100644 --- a/src/php/src/rules/Rule/class-func.php +++ b/src/php/src/rules/Rule/class-func.php @@ -272,7 +272,7 @@ public function is_rule_passed( string $funcs_operator, $data ): bool { } } - if ( is_int( $user_pass ) && $user_pass > 0 ) { + if ( $user_pass > 0 ) { return true; } diff --git a/src/php/src/rules/Rule/class-membership.php b/src/php/src/rules/Rule/class-membership.php index 35ca782e..d50f5484 100644 --- a/src/php/src/rules/Rule/class-membership.php +++ b/src/php/src/rules/Rule/class-membership.php @@ -294,7 +294,7 @@ public function is_rule_passed( string $operator, $data ): bool { } } - if ( is_int( $user_pass ) && $user_pass > 0 ) { + if ( $user_pass > 0 ) { return true; } diff --git a/src/php/src/rules/Rule/class-qualification.php b/src/php/src/rules/Rule/class-qualification.php index f758ee6d..068a89d6 100644 --- a/src/php/src/rules/Rule/class-qualification.php +++ b/src/php/src/rules/Rule/class-qualification.php @@ -209,7 +209,7 @@ public function is_rule_passed( string $operator, $data ): bool { } } - if ( is_int( $user_pass ) && $user_pass > 0 ) { + if ( $user_pass > 0 ) { return true; } diff --git a/src/php/src/rules/Rule/class-role.php b/src/php/src/rules/Rule/class-role.php index a4298528..5fd0807e 100644 --- a/src/php/src/rules/Rule/class-role.php +++ b/src/php/src/rules/Rule/class-role.php @@ -273,7 +273,7 @@ public function is_rule_passed( string $roles_operator, $data ): bool { } } - if ( is_int( $user_pass ) && $user_pass > 0 ) { + if ( $user_pass > 0 ) { return true; } diff --git a/src/php/src/rules/class-revisions.php b/src/php/src/rules/class-revisions.php index fbcd12a2..6aa8bb8f 100644 --- a/src/php/src/rules/class-revisions.php +++ b/src/php/src/rules/class-revisions.php @@ -115,7 +115,7 @@ public static function delete_meta( int $post_id ) { * * @return string The field value. * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @SuppressWarnings("PHPMD.UnusedFormalParameter") */ public static function field( $value, $field, $revision ) { $revision_id = $revision->ID; diff --git a/src/php/src/utils/class-helpers.php b/src/php/src/utils/class-helpers.php index c7ade9c1..de9d1eba 100644 --- a/src/php/src/utils/class-helpers.php +++ b/src/php/src/utils/class-helpers.php @@ -195,7 +195,7 @@ public static function get_variable_from_url( string $url, string $variable_name $result = array(); $url = esc_url_raw( $url ); if ( 1 === preg_match( '~' . $variable_name . '=([^\&,\s,\/,\#,\%,\?]*)~', $url, $result ) ) { - if ( is_array( $result ) && isset( $result[1] ) && '' !== $result[1] ) { + if ( isset( $result[1] ) && '' !== $result[1] ) { return sanitize_text_field( $result[1] ); } }