From da34b89f8abfab1db55fe5bb950eced0db1b4fa1 Mon Sep 17 00:00:00 2001 From: Jon Stovell Date: Sat, 24 Feb 2024 12:10:07 -0700 Subject: [PATCH] Documentation corrections and tidying in SMF\Url Signed-off-by: Jon Stovell --- Sources/Url.php | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/Sources/Url.php b/Sources/Url.php index 4d3ccbb8ca..99da17be28 100644 --- a/Sources/Url.php +++ b/Sources/Url.php @@ -31,6 +31,14 @@ class Url implements \Stringable { use BackwardCompatibility; + /***************** + * Class constants + *****************/ + + public const SCHEME_HTTPS = 'https'; + public const SCHEME_HTTP = 'http'; + public const SCHEME_GRAVATAR = 'gravatar'; + /******************* * Public properties *******************/ @@ -91,14 +99,6 @@ class Url implements \Stringable */ public string $fragment; - /***************** - * Class constants - *****************/ - - public const SCHEMA_HTTPS = 'https'; - public const SCHEMA_HTTP = 'http'; - public const SCHEMA_GRAVATAR = 'gravatar'; - /********************* * Internal properties *********************/ @@ -460,7 +460,7 @@ public function proxied(): self } /** - * Check if this URL has an SSL certificate. + * Checks if this URL has an SSL certificate. * * @return bool Whether the URL has an SSL certificate. */ @@ -496,7 +496,7 @@ public function hasSSL(): bool } /** - * Check if this URL has a redirect to https:// by querying headers. + * Checks if this URL has a redirect to https:// by querying headers. * * @return bool Whether a redirect to HTTPS was found. */ @@ -530,38 +530,39 @@ public function redirectsToHttps(): bool } /** - * Check if this URL has an SSL certificate. + * Checks if this URL points to a website. * - * @return bool Whether the URL matches the https or http schema. + * @return bool Whether the URL matches the https or http schemes. */ public function isWebsite(): bool { - return $this->isSchema([self::SCHEMA_HTTP, self::SCHEMA_HTTPS]); + return $this->isScheme([self::SCHEME_HTTP, self::SCHEME_HTTPS]); } /** - * Check if this URL has an SSL certificate. + * Check if this URL uses one of the specified schemes. * - * @param string|string[] $schema Schemas to check. - * @return bool Whether the URL matches a schema. + * @param string|string[] $schema Schemes to check. + * @return bool Whether the URL matches a scheme. */ - public function isSchema(string|array $schema): bool + public function isSchema(string|array $scheme): bool { return !empty($this->scheme) && in_array($this->scheme, array_map('strval', (array) $schema)); } /** - * Check if this URL has an SSL certificate. + * Checks if this is a Gravatar URL. * - * @return bool Whether the URL validates as a garavatar. + * @return bool Whether this is a Gravatar URL. */ public function isGravatar(): bool { return - $this->isSchema(self::SCHEMA_GRAVATAR) + $this->isScheme(self::SCHEME_GRAVATAR) || $this->url === 'gravatar://' || ( - !empty($this->host) && ( + !empty($this->host) + && ( $this->host === 'gravatar.com' || $this->host === 'secure.gravatar.com' )