Skip to content

Commit

Permalink
Documentation corrections and tidying in SMF\Url
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
  • Loading branch information
Sesquipedalian committed Feb 24, 2024
1 parent 5c02c12 commit da34b89
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions Sources/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*******************/
Expand Down Expand Up @@ -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
*********************/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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'
)
Expand Down

0 comments on commit da34b89

Please sign in to comment.