$info Result of WporgClient::fetch(). * @param int $now Current Unix timestamp. * @param string $latest_wp Latest known WordPress version. * @return array */ public static function evaluate( array $info, int $now, string $latest_wp ): array { if ( empty( $info['found'] ) ) { return array( 'status' => Status::UNKNOWN ); } if ( ! empty( $info['closed'] ) ) { return array( 'status' => Status::CLOSED, 'name' => (string) ( $info['name'] ?? '' ), 'closed_date' => (string) ( $info['closed_date'] ?? '' ), 'reason' => (string) ( $info['reason'] ?? '' ), 'reason_text' => (string) ( $info['reason_text'] ?? '' ), ); } $last_updated = self::parse_date( (string) ( $info['last_updated'] ?? '' ) ); $tested = (string) ( $info['tested'] ?? '' ); $result = array( 'status' => Status::OK, 'name' => (string) ( $info['name'] ?? '' ), 'version' => (string) ( $info['version'] ?? '' ), 'tested' => $tested, 'last_updated' => $last_updated, ); if ( $last_updated > 0 && $last_updated < (int) strtotime( self::ABANDONED_AFTER, $now ) ) { $result['status'] = Status::ABANDONED; return $result; } if ( self::is_outdated( $tested, $latest_wp ) ) { $result['status'] = Status::OUTDATED; } return $result; } /** * Whether "Tested up to" is older than the last three major versions. * * @param string $tested Tested up to. * @param string $latest_wp Latest known WordPress version. * @return bool */ public static function is_outdated( string $tested, string $latest_wp ): bool { $majors = WpVersions::last_majors( $latest_wp, self::TESTED_MAJORS ); if ( empty( $majors ) ) { return false; } $tested_major = WpVersions::major( $tested ); if ( '' === $tested_major ) { return true; } return version_compare( $tested_major, (string) end( $majors ), '<' ); } /** * Parses dates such as "2024-05-10 3:45pm GMT". * * @param string $date Date string. * @return int Unix timestamp or 0. */ public static function parse_date( string $date ): int { if ( '' === $date ) { return 0; } $time = strtotime( $date ); return false === $time ? 0 : $time; } }