Skip to content

Commit

Permalink
Fix issues found by Psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team committed Feb 24, 2023
1 parent eeca990 commit 132a4b7
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
4 changes: 1 addition & 3 deletions inc/class-authenticator.php
Expand Up @@ -24,7 +24,6 @@ public function init(): void {
* WP_Error or null otherwise.
* @param string $username Username or email address.
* @return null|WP_User|WP_Error
* @psalm-suppress RedundantCastGivenDocblockType
*/
public function authenticate( $user, $username ) {
if ( ! is_wp_error( $user ) ) {
Expand All @@ -49,8 +48,7 @@ public function authenticate( $user, $username ) {

/**
* @param string $error Login error message.
* @return string
* @psalm-suppress RedundantCastGivenDocblockType
* @return string
*/
public function login_errors( $error ): string {
global $errors;
Expand Down
2 changes: 1 addition & 1 deletion inc/class-ip-api.php
Expand Up @@ -148,7 +148,7 @@ private static function decode_entry( $entry ): ?array {
'as' => $entry['as'] ?? '',
'mobile' => isset( $entry['mobile'] ) ? (bool) $entry['mobile'] : null,
'proxy' => isset( $entry['proxy'] ) ? (bool) $entry['proxy'] : null,
'hosting' => isset( $entry['hosting'] ) ? (bool) $entry['proxy'] : null,
'hosting' => isset( $entry['hosting'] ) ? (bool) $entry['hosting'] : null,
];

$key = self::get_cache_key( $data['ip'] );
Expand Down
2 changes: 1 addition & 1 deletion inc/class-location-watcher.php
Expand Up @@ -61,7 +61,7 @@ public function wp_login( $_user_login, WP_User $user ): void {
}

/**
* @param mixed[] $info
* @param mixed[] $info
* @return mixed[]
*/
public function attach_session_information( array $info ): array {
Expand Down
4 changes: 0 additions & 4 deletions inc/class-login-limiter.php
Expand Up @@ -32,7 +32,6 @@ public function init(): void {
public function wp_login_failed( $username_or_email ): void {
$ip = Utils::get_ip();
if ( $ip ) {
/** @psalm-suppress RedundantCastGivenDocblockType */
list( $key1, $key2 ) = $this->get_cache_keys( (string) $username_or_email, $ip );

wp_cache_add( $key1, 0, self::CACHE_GROUP, 10 * MINUTE_IN_SECONDS );
Expand All @@ -45,7 +44,6 @@ public function wp_login_failed( $username_or_email ): void {

/**
* @param string $username
* @psalm-suppress RedundantCastGivenDocblockType
*/
public function wp_login( $username ): void {
$ip = Utils::get_ip();
Expand All @@ -70,7 +68,6 @@ public function wp_login( $username ): void {
* @param string $username Username or email address.
* @param string $password User password
* @return null|WP_User|WP_Error
* @psalm-suppress RedundantCastGivenDocblockType
*/
public function authenticate( $user, $username, $password ) {
if ( ! empty( $username ) && ! empty( $password ) ) {
Expand All @@ -92,7 +89,6 @@ public function login_form_login(): void {
if ( 'POST' === Utils::get_request_method() && ! empty( $_POST['log'] ) && is_scalar( $_POST['log'] ) ) {
$ip = Utils::get_ip();
if ( $ip ) {
/** @psalm-suppress RedundantCast */
$username = sanitize_user( wp_unslash( (string) $_POST['log'] ) );
$limited = $this->check_limits( $username, $ip );
if ( is_wp_error( $limited ) ) {
Expand Down
7 changes: 2 additions & 5 deletions inc/class-login-logger.php
Expand Up @@ -24,7 +24,6 @@ public function init(): void {
* WP_Error or null otherwise.
* @param string $username Username or email address.
* @return null|WP_User|WP_Error
* @psalm-suppress RedundantCastGivenDocblockType
*/
public function authenticate( $user, $username ) {
$message = sprintf( 'Login attempt: %s', $this->construct_message( (string) $username ) );
Expand All @@ -33,17 +32,15 @@ public function authenticate( $user, $username ) {
}

/**
* @param string $login
* @psalm-suppress RedundantCastGivenDocblockType
* @param string $login
*/
public function wp_login( $login ): void {
$message = sprintf( 'Login successful: %s', $this->construct_message( (string) $login ) );
Utils::log( 'wp-login-logger', LOG_AUTH, LOG_INFO, $message );
}

/**
* @param string $login
* @psalm-suppress RedundantCastGivenDocblockType
* @param string $login
*/
public function wp_login_failed( $login ): void {
$user = Auth_Utils::get_user_by_login_or_email( (string) $login );
Expand Down
9 changes: 9 additions & 0 deletions psalm.xml.dist
Expand Up @@ -4,6 +4,8 @@
resolveFromConfigFile="true"
phpVersion="7.4"
findUnusedPsalmSuppress="true"
findUnusedCode="true"
findUnusedBaselineEntry="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand All @@ -12,6 +14,13 @@
<file name="index.php"/>
<directory name="inc"/>
</projectFiles>
<issueHandlers>
<PossiblyUnusedReturnValue errorLevel="suppress"/>
<PossiblyUnusedMethod errorLevel="suppress"/>
<RedundantCast errorLevel="suppress"/>
<RedundantCastGivenDocblockType errorLevel="suppress"/>
<UnusedClass errorLevel="suppress"/>
</issueHandlers>
<stubs>
<file name="vendor/php-stubs/wordpress-stubs/wordpress-stubs.php"/>
<file name="wordpress.stubs"/>
Expand Down

0 comments on commit 132a4b7

Please sign in to comment.