From 1356f742a091893565b178f37a955bed975bdf00 Mon Sep 17 00:00:00 2001 From: romeOz Date: Thu, 4 Jun 2015 18:43:52 +0300 Subject: [PATCH] Simple refactoring. --- src/Validate.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Validate.php b/src/Validate.php index f029667..73b8d54 100644 --- a/src/Validate.php +++ b/src/Validate.php @@ -125,7 +125,7 @@ * @method static Validate uploaded() * @method static Validate uppercase() * @method static Validate writable() - * + * * @package rock\validate */ class Validate implements ObjectInterface @@ -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; } @@ -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. *