Skip to content

Commit

Permalink
Simple refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
romeOz committed Jun 4, 2015
1 parent e7443f4 commit 1356f74
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
* @method static Validate uploaded()
* @method static Validate uppercase()
* @method static Validate writable()
*
*
* @package rock\validate
*/
class Validate implements ObjectInterface
Expand Down Expand Up @@ -389,9 +389,8 @@ public function __call($name, $arguments)
if (!class_exists($this->rules[$name]['class'])) {
throw new ValidateException(ValidateException::UNKNOWN_CLASS, ['class' => $this->rules[$name]['class']]);
}
/** @var Rule $rule */
$reflect = new \ReflectionClass($this->rules[$name]['class']);
$rule = $reflect->newInstanceArgs($arguments);

$rule = $this->getInstanceRule($name, $arguments);
$this->rawRules[] = [$name, $rule];
return $this;
}
Expand Down Expand Up @@ -500,6 +499,18 @@ protected function labelRemainderInternal($label = '*')
return $this;
}

/**
* Returns instance rule.
* @param string $name name of rule
* @param array $arguments
* @return Rule
*/
protected function getInstanceRule($name, array $arguments)
{
$reflect = new \ReflectionClass($this->rules[$name]['class']);
return $reflect->newInstanceArgs($arguments);
}

/**
* Returns instance.
*
Expand Down

0 comments on commit 1356f74

Please sign in to comment.