Skip to content

Commit

Permalink
refactor: import InvalidArgumentException class
Browse files Browse the repository at this point in the history
  • Loading branch information
adevade committed Jan 31, 2023
1 parent bd4091c commit b9ff408
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/UrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Imgix;

use InvalidArgumentException;

class UrlBuilder
{
private $currentVersion = "4.1.0";
Expand Down Expand Up @@ -34,7 +36,7 @@ class UrlBuilder
public function __construct($domain, $useHttps = true, $signKey = '', $includeLibraryParam = true)
{
if (! is_string($domain)) {
throw new \InvalidArgumentException('UrlBuilder must be passed a string domain');
throw new InvalidArgumentException('UrlBuilder must be passed a string domain');
}

$this->domain = $domain;
Expand All @@ -50,9 +52,7 @@ private function validateDomain($domain)
$DOMAIN_PATTERN = "/^(?:[a-z\d\-_]{1,62}\.){0,125}(?:[a-z\d](?:\-(?=\-*[a-z\d])|[a-z]|\d){0,62}\.)[a-z\d]{1,63}$/";

if (! preg_match($DOMAIN_PATTERN, $domain)) {
throw new \InvalidArgumentException('Domain must be passed in as fully-qualified '.
'domain name and should not include a protocol or any path element, i.e. '.
'"example.imgix.net".');
throw new InvalidArgumentException('Domain must be passed in as fully-qualified domain name and should not include a protocol or any path element, i.e. "example.imgix.net".');
}
}

Expand Down
16 changes: 9 additions & 7 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

namespace Imgix;

use InvalidArgumentException;

class Validator
{
public const ONE_PERCENT = 0.01;

public static function validateMinWidth($start)
{
if ($start < 0) {
throw new \InvalidArgumentException('`start` width value must be greater than zero');
throw new InvalidArgumentException('`start` width value must be greater than zero');
}
}

public static function validateMaxWidth($stop)
{
throw new \InvalidArgumentException('`stop` width value must be greater than zero');
if ($stop < 0) {
throw new InvalidArgumentException('`stop` width value must be greater than zero');
}
}

Expand All @@ -29,7 +31,7 @@ public static function validateRange($start, $stop)

// Ensure that the range is valid, ie. `start <= stop`.
if ($start > $stop) {
throw new \InvalidArgumentException('`start` width value must be less than `stop` width value');
throw new InvalidArgumentException('`start` width value must be less than `stop` width value');
}
}

Expand All @@ -38,7 +40,7 @@ public static function validateTolerance($tol)
$msg = '`tol`erance value must be greater than, or equal to one percent, ie. >= 0.01';

if ($tol < self::ONE_PERCENT) {
throw new \InvalidArgumentException($msg);
throw new InvalidArgumentException($msg);
}
}

Expand All @@ -51,15 +53,15 @@ public static function validateMinMaxTol($start, $stop, $tol)
public static function validateWidths($widths)
{
if (is_null($widths)) {
throw new \InvalidArgumentException("`widths` array cannot be `null`");
throw new InvalidArgumentException('`widths` array cannot be `null`');
}

if (count($widths) === 0) {
throw new \InvalidArgumentException("`widths` array cannot be empty");
throw new InvalidArgumentException('`widths` array cannot be empty');
}
foreach ($widths as &$w) {
if ($w < 0) {
throw new \InvalidArgumentException('width values in `widths` cannot be negative');
throw new InvalidArgumentException('width values in `widths` cannot be negative');
}
}
}
Expand Down

0 comments on commit b9ff408

Please sign in to comment.