*/ public function suggestions_for( Link $link ): array { if ( Verdict::Broken !== $link->verdict ) { return array(); } if ( $link->internal ) { return $this->internal_suggestions( $link ); } return $this->external_suggestions( $link ); } /** @return list */ private function internal_suggestions( Link $link ): array { $closest_page = $this->closest_page_finder->closest_to( $link->url ); if ( null === $closest_page ) { return array(); } return array( $this->suggestion( SuggestionKind::ClosestPage, $closest_page ), ); } /** @return list */ private function external_suggestions( Link $link ): array { $suggestions = array(); $site_home = $this->site_home_probe->answering_home_of( $link->url ); if ( null !== $site_home ) { $suggestions[] = $this->suggestion( SuggestionKind::SiteHome, $site_home ); } $archived_copy = $this->archive_address->archived_copy_of( $link ); if ( null !== $archived_copy ) { $suggestions[] = $this->suggestion( SuggestionKind::Archive, $archived_copy ); } return $suggestions; } /** @return array{kind: string, url: string} */ private function suggestion( SuggestionKind $kind, string $url ): array { return array( 'kind' => $kind->value, 'url' => $url, ); } }