mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-31 07:01:54 +00:00
Merge pull request #68 from brandonlamb/features/psr-formatting
Apply some PSR formatting updates
This commit is contained in:
commit
746871558b
@ -43,6 +43,7 @@ class Validator
|
|||||||
|
|
||||||
// set lang in the follow order: constructor param, static::$_lang, default to en
|
// set lang in the follow order: constructor param, static::$_lang, default to en
|
||||||
$lang = $lang ?: static::lang();
|
$lang = $lang ?: static::lang();
|
||||||
|
|
||||||
// set langDir in the follow order: constructor param, static::$_langDir, default to package lang dir
|
// set langDir in the follow order: constructor param, static::$_langDir, default to package lang dir
|
||||||
$langDir = $langDir ?: static::langDir();
|
$langDir = $langDir ?: static::langDir();
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ class Validator
|
|||||||
$langMessages = include $langFile;
|
$langMessages = include $langFile;
|
||||||
static::$_ruleMessages = array_merge(static::$_ruleMessages, $langMessages);
|
static::$_ruleMessages = array_merge(static::$_ruleMessages, $langMessages);
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidArgumentException("fail to load language file '$langFile'");
|
throw new \InvalidArgumentException("fail to load language file '$langFile'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ class Validator
|
|||||||
{
|
{
|
||||||
if (is_null($value)) {
|
if (is_null($value)) {
|
||||||
return false;
|
return false;
|
||||||
} elseif(is_string($value) and trim($value) === '') {
|
} elseif (is_string($value) && trim($value) === '') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -161,7 +162,7 @@ class Validator
|
|||||||
*/
|
*/
|
||||||
protected function validateInteger($field, $value)
|
protected function validateInteger($field, $value)
|
||||||
{
|
{
|
||||||
return filter_var($value, FILTER_VALIDATE_INT) !== false;
|
return filter_var($value, \FILTER_VALIDATE_INT) !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -329,7 +330,7 @@ class Validator
|
|||||||
*/
|
*/
|
||||||
protected function validateIp($field, $value)
|
protected function validateIp($field, $value)
|
||||||
{
|
{
|
||||||
return filter_var($value, FILTER_VALIDATE_IP) !== false;
|
return filter_var($value, \FILTER_VALIDATE_IP) !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -341,7 +342,7 @@ class Validator
|
|||||||
*/
|
*/
|
||||||
protected function validateEmail($field, $value)
|
protected function validateEmail($field, $value)
|
||||||
{
|
{
|
||||||
return filter_var($value, FILTER_VALIDATE_EMAIL) !== false;
|
return filter_var($value, \FILTER_VALIDATE_EMAIL) !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -355,7 +356,7 @@ class Validator
|
|||||||
{
|
{
|
||||||
foreach ($this->validUrlPrefixes as $prefix) {
|
foreach ($this->validUrlPrefixes as $prefix) {
|
||||||
if (strpos($value, $prefix) !== false) {
|
if (strpos($value, $prefix) !== false) {
|
||||||
return filter_var($value, FILTER_VALIDATE_URL) !== false;
|
return filter_var($value, \FILTER_VALIDATE_URL) !== false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -749,7 +750,7 @@ class Validator
|
|||||||
public static function addRule($name, $callback, $message = self::ERROR_DEFAULT)
|
public static function addRule($name, $callback, $message = self::ERROR_DEFAULT)
|
||||||
{
|
{
|
||||||
if (!is_callable($callback)) {
|
if (!is_callable($callback)) {
|
||||||
throw new \InvalidArgumentException("Second argument must be a valid callback. Given argument was not callable.");
|
throw new \InvalidArgumentException('Second argument must be a valid callback. Given argument was not callable.');
|
||||||
}
|
}
|
||||||
|
|
||||||
static::$_rules[$name] = $callback;
|
static::$_rules[$name] = $callback;
|
||||||
@ -843,7 +844,7 @@ class Validator
|
|||||||
if (is_array($params)) {
|
if (is_array($params)) {
|
||||||
foreach ($params as $innerParams) {
|
foreach ($params as $innerParams) {
|
||||||
array_unshift($innerParams, $ruleType);
|
array_unshift($innerParams, $ruleType);
|
||||||
call_user_func_array(array($this, "rule"), $innerParams);
|
call_user_func_array(array($this, 'rule'), $innerParams);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->rule($ruleType, $params);
|
$this->rule($ruleType, $params);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user