Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonTheAdams committed Mar 24, 2023
2 parents a293d6f + 7dc73b8 commit a79536d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/ValidationRulesRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace StellarWP\Validation;

use StellarWP\Exceptions\Primitives\InvalidArgumentException;
use StellarWP\Validation\Contracts\ValidationRule;

/**
Expand Down Expand Up @@ -32,26 +31,29 @@ public function register(string ...$rules): self
/**
* Register a validation rule.
*
* @unreleased switch to throwing InvalidArgumentException from Config
* @since 1.0.0
*/
private function registerClass(string $class): self
{
if (!is_subclass_of($class, ValidationRule::class)) {
throw new InvalidArgumentException(
Config::throwInvalidArgumentException(
sprintf(
'Validation rule must implement %s',
ValidationRule::class
)
);
}

if (isset($this->rules[$class::id()])) {
throw new InvalidArgumentException(
"A validation rule with the id {$class::id()} has already been registered."
$classId = $class::id();

if (isset($this->rules[$classId])) {
Config::throwInvalidArgumentException(
"A validation rule with the id $classId has already been registered."
);
}

$this->rules[$class::id()] = $class;
$this->rules[$classId] = $class;

return $this;
}
Expand Down

0 comments on commit a79536d

Please sign in to comment.