ok() ) { Log::warning( sprintf( 'Status panel: CortexCommerce did not give the numbers (%s).', $response->describe() ) ); set_transient( Options::STATS_FAILED_TRANSIENT, 1, self::FAILURE_TTL ); return null; } $stats = self::parse( $response->json ); if ( null === $stats ) { Log::error( 'Status panel: CortexCommerce answered the numbers request with an unexpected body.' ); set_transient( Options::STATS_FAILED_TRANSIENT, 1, self::FAILURE_TTL ); return null; } set_transient( Options::STATS_TRANSIENT, $stats, self::TTL ); return $stats; } /** * @param mixed $raw Decoded body or cached value. * @return array{products_synced: int, products_enriched: int, products_live: int, awaiting_review: int, store_blocked: bool}|null */ private static function parse( $raw ): ?array { if ( ! is_array( $raw ) || ! isset( $raw['store_blocked'] ) || ! is_bool( $raw['store_blocked'] ) ) { return null; } foreach ( self::COUNTS as $key ) { if ( ! isset( $raw[ $key ] ) || ! is_int( $raw[ $key ] ) || $raw[ $key ] < 0 ) { return null; } } return array( 'products_synced' => $raw['products_synced'], 'products_enriched' => $raw['products_enriched'], 'products_live' => $raw['products_live'], 'awaiting_review' => $raw['awaiting_review'], 'store_blocked' => $raw['store_blocked'], ); } }