addon_manager = $addon_manager; $this->my_yoast_api_request_factory = $my_yoast_api_request_factory; $this->curl_helper = $curl_helper; } /** * Runs the health check. Checks if cURL is installed and up to date, and if it's able to reach the MyYoast API * * @return void */ public function run() { $this->check_has_installed_addons(); $this->check_curl_installed(); if ( ! $this->curl_installed ) { return; } $this->check_curl_is_recent(); $this->check_can_reach_my_yoast_api(); } /** * Checks if there are installed Yoast add-ons. * * @return void */ private function check_has_installed_addons() { $this->has_installed_addons = $this->addon_manager->has_installed_addons(); } /** * Checks if cURL is installed. * * @return void */ private function check_curl_installed() { $this->curl_installed = $this->curl_helper->is_installed(); } /** * Checks if the installed cURL version is equal to or more recent than MINIMUM_CURL_VERSION. * * @return void */ private function check_curl_is_recent() { $version = $this->curl_helper->get_version(); if ( $version === null ) { $this->curl_is_recent = false; return; } $this->curl_is_recent = version_compare( $version, self::MINIMUM_CURL_VERSION, '>=' ); } /** * Checks if cURL is able to reach the MyYoast API. * * @return void */ private function check_can_reach_my_yoast_api() { $api_request = $this->my_yoast_api_request_factory->create( self::MYYOAST_API_REQUEST_URL ); $got_response = $api_request->fire(); $this->got_my_yoast_api_response = $got_response; } /** * Returns whether the health check was successful. * * @return bool True if all the routines for this health check were successful. */ public function is_successful() { return $this->has_installed_addons && $this->curl_is_recent && $this->got_my_yoast_api_response; } /** * Returns whether there are premium plugins installed. * * @return bool True if there are premium plugins installed. */ public function has_premium_plugins_installed() { return $this->has_installed_addons; } /** * Returns whether cURL was able to reach the MyYoast API. * * @return bool True if cURL was able to reach the MyYoast API. */ public function can_reach_my_yoast_api() { return $this->got_my_yoast_api_response; } /** * Returns whether the installed cURL version is recent enough. * * @return bool True if the installed cURL version is more recent than MINIMUM_CURL_VERSION. */ public function has_recent_curl_version_installed() { return $this->curl_is_recent; } }