Skip to content

Commit

Permalink
Improve docblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jan 29, 2020
1 parent 64fa70a commit c64eab8
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 58 deletions.
3 changes: 1 addition & 2 deletions src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@

namespace League\Uri;

use JsonSerializable;
use League\Uri\Contracts\UriInterface;
use League\Uri\Exceptions\SyntaxError;
use Psr\Http\Message\UriInterface as Psr7UriInterface;
use function is_scalar;
use function method_exists;
use function sprintf;

final class Http implements Psr7UriInterface, JsonSerializable
final class Http implements Psr7UriInterface, \JsonSerializable
{
/**
* @var UriInterface
Expand Down
40 changes: 19 additions & 21 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@

namespace League\Uri;

use finfo;
use League\Uri\Contracts\UriInterface;
use League\Uri\Exceptions\IdnSupportMissing;
use League\Uri\Exceptions\SyntaxError;
use Psr\Http\Message\UriInterface as Psr7UriInterface;
use TypeError;
use function array_filter;
use function array_map;
use function base64_decode;
Expand Down Expand Up @@ -76,7 +74,7 @@ final class Uri implements UriInterface
/**
* RFC3986 invalid characters.
*
* @see https://tools.ietf.org/html/rfc3986#section-2.2
* @link https://tools.ietf.org/html/rfc3986#section-2.2
*
* @var string
*/
Expand All @@ -85,7 +83,7 @@ final class Uri implements UriInterface
/**
* RFC3986 Sub delimiter characters regular expression pattern.
*
* @see https://tools.ietf.org/html/rfc3986#section-2.2
* @link https://tools.ietf.org/html/rfc3986#section-2.2
*
* @var string
*/
Expand All @@ -94,7 +92,7 @@ final class Uri implements UriInterface
/**
* RFC3986 unreserved characters regular expression pattern.
*
* @see https://tools.ietf.org/html/rfc3986#section-2.3
* @link https://tools.ietf.org/html/rfc3986#section-2.3
*
* @var string
*/
Expand All @@ -103,14 +101,14 @@ final class Uri implements UriInterface
/**
* RFC3986 schema regular expression pattern.
*
* @see https://tools.ietf.org/html/rfc3986#section-3.1
* @link https://tools.ietf.org/html/rfc3986#section-3.1
*/
private const REGEXP_SCHEME = ',^[a-z]([-a-z0-9+.]+)?$,i';

/**
* RFC3986 host identified by a registered name regular expression pattern.
*
* @see https://tools.ietf.org/html/rfc3986#section-3.2.2
* @link https://tools.ietf.org/html/rfc3986#section-3.2.2
*/
private const REGEXP_HOST_REGNAME = '/^(
(?<unreserved>[a-z0-9_~\-\.])|
Expand All @@ -121,14 +119,14 @@ final class Uri implements UriInterface
/**
* RFC3986 delimiters of the generic URI components regular expression pattern.
*
* @see https://tools.ietf.org/html/rfc3986#section-2.2
* @link https://tools.ietf.org/html/rfc3986#section-2.2
*/
private const REGEXP_HOST_GEN_DELIMS = '/[:\/?#\[\]@ ]/'; // Also includes space.

/**
* RFC3986 IPvFuture regular expression pattern.
*
* @see https://tools.ietf.org/html/rfc3986#section-3.2.2
* @link https://tools.ietf.org/html/rfc3986#section-3.2.2
*/
private const REGEXP_HOST_IPFUTURE = '/^
v(?<version>[A-F0-9])+\.
Expand All @@ -151,14 +149,14 @@ final class Uri implements UriInterface
/**
* Mimetype regular expression pattern.
*
* @see https://tools.ietf.org/html/rfc2397
* @link https://tools.ietf.org/html/rfc2397
*/
private const REGEXP_MIMETYPE = ',^\w+/[-.\w]+(?:\+[-.\w]+)?$,';

/**
* Base64 content regular expression pattern.
*
* @see https://tools.ietf.org/html/rfc2397
* @link https://tools.ietf.org/html/rfc2397
*/
private const REGEXP_BINARY = ',(;|^)base64$,';

Expand Down Expand Up @@ -452,7 +450,7 @@ private function formatRegisteredName(string $host): string
/**
* Retrieves and format IDNA conversion error message.
*
* @see http://icu-project.org/apiref/icu4j/com/ibm/icu/text/IDNA.Error.html
* @link http://icu-project.org/apiref/icu4j/com/ibm/icu/text/IDNA.Error.html
*/
private function getIDNAErrors(int $error_byte): string
{
Expand Down Expand Up @@ -689,7 +687,7 @@ public static function createFromDataPath(string $path, $context = null): self
throw new SyntaxError(sprintf('The file `%s` does not exist or is not readable', $path));
}

$mimetype = (string) (new finfo(FILEINFO_MIME))->file(...$mime_args);
$mimetype = (string) (new \finfo(FILEINFO_MIME))->file(...$mime_args);

return Uri::createFromComponents([
'scheme' => 'data',
Expand Down Expand Up @@ -766,7 +764,7 @@ public static function createFromUri($uri): self
}

if (!$uri instanceof Psr7UriInterface) {
throw new TypeError(sprintf('The object must implement the `%s` or the `%s`', Psr7UriInterface::class, UriInterface::class));
throw new \TypeError(sprintf('The object must implement the `%s` or the `%s`', Psr7UriInterface::class, UriInterface::class));
}

$scheme = $uri->getScheme();
Expand Down Expand Up @@ -965,7 +963,7 @@ private function formatPath(string $path): string
/**
* Filter the Path component.
*
* @see https://tools.ietf.org/html/rfc2397
* @link https://tools.ietf.org/html/rfc2397
*
* @throws SyntaxError If the path is not compliant with RFC2397
*/
Expand Down Expand Up @@ -1004,7 +1002,7 @@ private function formatDataPath(string $path): string
/**
* Assert the path is a compliant with RFC2397.
*
* @see https://tools.ietf.org/html/rfc2397
* @link https://tools.ietf.org/html/rfc2397
*
* @throws SyntaxError If the mediatype or the data are not compliant with the RFC2397
*/
Expand Down Expand Up @@ -1085,8 +1083,8 @@ private function formatQueryAndFragment(?string $component): ?string
/**
* assert the URI internal state is valid.
*
* @see https://tools.ietf.org/html/rfc3986#section-3
* @see https://tools.ietf.org/html/rfc3986#section-3.3
* @link https://tools.ietf.org/html/rfc3986#section-3
* @link https://tools.ietf.org/html/rfc3986#section-3.3
*
* @throws SyntaxError if the URI is in an invalid state according to RFC3986
* @throws SyntaxError if the URI is in an invalid state according to scheme specific rules
Expand Down Expand Up @@ -1172,7 +1170,7 @@ private function isNonEmptyHostUriWithoutFragmentAndQuery(): bool
/**
* Generate the URI string representation from its components.
*
* @see https://tools.ietf.org/html/rfc3986#section-5.3
* @link https://tools.ietf.org/html/rfc3986#section-5.3
*
* @param ?string $scheme
* @param ?string $authority
Expand Down Expand Up @@ -1344,7 +1342,7 @@ private function filterString($str): ?string
}

if (!is_scalar($str) && !method_exists($str, '__toString')) {
throw new TypeError(sprintf('The component must be a string, a scalar or a stringable object %s given', gettype($str)));
throw new \TypeError(sprintf('The component must be a string, a scalar or a stringable object %s given', gettype($str)));
}

$str = (string) $str;
Expand Down Expand Up @@ -1425,7 +1423,7 @@ public function withPath($path): UriInterface
{
$path = $this->filterString($path);
if (null === $path) {
throw new TypeError('A path must be a string NULL given');
throw new \TypeError('A path must be a string NULL given');
}

$path = $this->formatPath($path);
Expand Down
5 changes: 2 additions & 3 deletions src/UriInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use League\Uri\Contracts\UriInterface;
use Psr\Http\Message\UriInterface as Psr7UriInterface;
use TypeError;
use function explode;
use function implode;
use function preg_replace_callback;
Expand All @@ -42,7 +41,7 @@ private function __construct()
*
* @param mixed $uri the URI to validate
*
* @throws TypeError if the URI object does not implements the supported interfaces.
* @throws \TypeError if the URI object does not implements the supported interfaces.
*
* @return Psr7UriInterface|UriInterface
*/
Expand All @@ -52,7 +51,7 @@ private static function filterUri($uri)
return $uri;
}

throw new TypeError(sprintf('The uri must be a valid URI object received `%s`', is_object($uri) ? get_class($uri) : gettype($uri)));
throw new \TypeError(sprintf('The uri must be a valid URI object received `%s`', is_object($uri) ? get_class($uri) : gettype($uri)));
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/UriResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use League\Uri\Contracts\UriInterface;
use Psr\Http\Message\UriInterface as Psr7UriInterface;
use TypeError;
use function array_pop;
use function array_reduce;
use function count;
Expand All @@ -32,7 +31,7 @@
final class UriResolver
{
/**
* @var array
* @var array<string,int>
*/
const DOT_SEGMENTS = ['.' => 1, '..' => 1];

Expand Down Expand Up @@ -95,12 +94,12 @@ public static function resolve($uri, $base_uri)
*
* @param mixed $uri an URI object
*
* @throws TypeError if the URI object does not implements the supported interfaces.
* @throws \TypeError if the URI object does not implements the supported interfaces.
*/
private static function filterUri($uri): void
{
if (!$uri instanceof UriInterface && !$uri instanceof Psr7UriInterface) {
throw new TypeError(sprintf('The uri must be a valid URI object received `%s`', gettype($uri)));
throw new \TypeError(sprintf('The uri must be a valid URI object received `%s`', gettype($uri)));
}
}

Expand Down Expand Up @@ -273,7 +272,7 @@ private static function getComponent(string $method, $uri): ?string
*
* @param null|mixed $uri
*
* @throws TypeError if the URI object does not implements the supported interfaces.
* @throws \TypeError if the URI object does not implements the supported interfaces.
*
* @return Psr7UriInterface|UriInterface
*/
Expand Down
Loading

0 comments on commit c64eab8

Please sign in to comment.