Skip to content

Commit d033912

Browse files
committed
#263 Improve Rules public API
1 parent b8dc76c commit d033912

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Rules.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use Pdp\Exception\CouldNotLoadRules;
1919
use Pdp\Exception\CouldNotResolvePublicSuffix;
20+
use Pdp\Exception\InvalidDomain;
2021
use function array_reverse;
2122
use function count;
2223
use function fclose;
@@ -104,7 +105,7 @@ public static function createFromPath(
104105

105106
$resource = @fopen(...$args);
106107
if (false === $resource) {
107-
throw new CouldNotLoadRules(sprintf('`%s`: failed to open stream: No such file or directory', $path));
108+
throw new CouldNotLoadRules(sprintf('`%s`: failed to open stream: No such file or directory.', $path));
108109
}
109110

110111
/** @var string $content */
@@ -193,7 +194,7 @@ public function getPublicSuffix($domain, string $section = self::ALL_DOMAINS): P
193194
}
194195

195196
if (!$domain->isResolvable()) {
196-
throw new CouldNotResolvePublicSuffix(sprintf('The domain `%s` can not contain a public suffix', $domain->getContent()));
197+
throw new CouldNotResolvePublicSuffix(sprintf('The domain `%s` can not contain a public suffix.', $domain->getContent()));
197198
}
198199

199200
return PublicSuffix::createFromDomain($domain->resolve($this->findPublicSuffix($domain, $section)));
@@ -262,9 +263,12 @@ public function privateResolve($domain): Domain
262263
}
263264

264265
/**
265-
* Returns PSL info for a given domain.
266+
* Assert the domain is valid and is resolvable.
266267
*
267268
* @param mixed $domain
269+
*
270+
* @throws InvalidDomain if the domain is invalid
271+
* @throws CouldNotResolvePublicSuffix if the domain is not resolvable
268272
*/
269273
private function validateDomain($domain): Domain
270274
{
@@ -273,7 +277,7 @@ private function validateDomain($domain): Domain
273277
}
274278

275279
if (!$domain->isResolvable()) {
276-
throw new CouldNotResolvePublicSuffix(sprintf('The domain `%s` can not contain a public suffix', $domain->getContent()));
280+
throw new CouldNotResolvePublicSuffix(sprintf('The domain `%s` can not contain a public suffix.', $domain->getContent()));
277281
}
278282

279283
return $domain;
@@ -298,7 +302,7 @@ private function validateSection(string $section): string
298302
return $section;
299303
}
300304

301-
throw new CouldNotResolvePublicSuffix(sprintf('%s is an unknown Public Suffix List section', $section));
305+
throw new CouldNotResolvePublicSuffix(sprintf('%s is an unknown Public Suffix List section.', $section));
302306
}
303307

304308
/**

0 commit comments

Comments
 (0)