From 91ff9278da1f492f9e32f4f6ad41fe3dcf29e209 Mon Sep 17 00:00:00 2001 From: peter279k Date: Sat, 17 Nov 2018 15:12:24 +0800 Subject: [PATCH] Using PSR-2 coding style for this source code --- .travis.yml | 4 ++- composer.json | 3 +- src/Attribute.php | 7 ++-- src/ErrorBag.php | 23 ++++++------ src/Helper.php | 1 - src/MimeTypeGuesser.php | 1 - src/Rule.php | 11 +++--- src/Rules/Accepted.php | 1 - src/Rules/After.php | 6 ++-- src/Rules/Alpha.php | 1 - src/Rules/AlphaDash.php | 1 - src/Rules/AlphaNum.php | 1 - src/Rules/Before.php | 6 ++-- src/Rules/Between.php | 15 ++++---- src/Rules/Callback.php | 7 ++-- src/Rules/Date.php | 5 ++- src/Rules/Defaults.php | 5 ++- src/Rules/Different.php | 9 +++-- src/Rules/Digits.php | 5 ++- src/Rules/DigitsBetween.php | 5 ++- src/Rules/Email.php | 1 - src/Rules/FileTrait.php | 12 ++++--- src/Rules/In.php | 3 +- src/Rules/Integer.php | 1 - src/Rules/Ip.php | 1 - src/Rules/Ipv4.php | 1 - src/Rules/Ipv6.php | 1 - src/Rules/Json.php | 1 - src/Rules/Lowercase.php | 3 +- src/Rules/Max.php | 9 +++-- src/Rules/Min.php | 9 +++-- src/Rules/NotIn.php | 7 ++-- src/Rules/Numeric.php | 1 - src/Rules/Present.php | 1 - src/Rules/Regex.php | 5 ++- src/Rules/Required.php | 13 ++++--- src/Rules/RequiredIf.php | 5 ++- src/Rules/RequiredUnless.php | 5 ++- src/Rules/RequiredWith.php | 7 ++-- src/Rules/RequiredWithAll.php | 7 ++-- src/Rules/RequiredWithout.php | 7 ++-- src/Rules/RequiredWithoutAll.php | 7 ++-- src/Rules/Same.php | 5 ++- src/Rules/TypeArray.php | 1 - src/Rules/UploadedFile.php | 6 ++-- src/Rules/Uppercase.php | 3 +- src/Rules/Url.php | 5 ++- src/Validation.php | 59 ++++++++++++++++--------------- src/Validator.php | 2 +- tests/ErrorBagTest.php | 1 - tests/Fixtures/Even.php | 3 +- tests/HelperTest.php | 1 - tests/Rules/AcceptedTest.php | 1 - tests/Rules/AlphaDashTest.php | 1 - tests/Rules/AlphaNumTest.php | 1 - tests/Rules/AlphaTest.php | 1 - tests/Rules/BetweenTest.php | 1 - tests/Rules/CallbackTest.php | 5 ++- tests/Rules/DateTest.php | 1 - tests/Rules/DefaultsTest.php | 1 - tests/Rules/DigitsBetweenTest.php | 1 - tests/Rules/DigitsTest.php | 1 - tests/Rules/EmailTest.php | 1 - tests/Rules/InTest.php | 1 - tests/Rules/IntegerTest.php | 2 -- tests/Rules/IpTest.php | 1 - tests/Rules/Ipv4Test.php | 1 - tests/Rules/Ipv6Test.php | 1 - tests/Rules/JsonTest.php | 2 -- tests/Rules/LowercaseTest.php | 1 - tests/Rules/MaxTest.php | 1 - tests/Rules/MinTest.php | 1 - tests/Rules/NotInTest.php | 1 - tests/Rules/NumericTest.php | 1 - tests/Rules/RegexTest.php | 1 - tests/Rules/RequiredTest.php | 1 - tests/Rules/TypeArrayTest.php | 1 - tests/Rules/UppercaseTest.php | 1 - tests/Rules/UrlTest.php | 1 - tests/ValidatorTest.php | 27 +++++++------- 80 files changed, 159 insertions(+), 211 deletions(-) diff --git a/.travis.yml b/.travis.yml index 320b162..5610f7d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,5 +7,7 @@ php: before_script: - composer install + - ./vendor/bin/phpcs -n --standard=PSR2 src/ tests/ -script: phpunit --coverage-text +script: + - phpunit --coverage-text diff --git a/composer.json b/composer.json index df8e866..d698c5a 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ "ext-mbstring": "*" }, "require-dev": { - "phpunit/phpunit": "^6.5" + "phpunit/phpunit": "^6.5", + "squizlabs/php_codesniffer": "^3" } } diff --git a/src/Attribute.php b/src/Attribute.php index 4d89162..4b261b1 100644 --- a/src/Attribute.php +++ b/src/Attribute.php @@ -26,7 +26,7 @@ public function __construct(Validation $validation, $key, $alias = null, array $ $this->validation = $validation; $this->alias = $alias; $this->key = $key; - foreach($rules as $rule) { + foreach ($rules as $rule) { $this->addRule($rule); } } @@ -49,7 +49,7 @@ public function getPrimaryAttribute() public function setOtherAttributes(array $otherAttributes) { $this->otherAttributes = []; - foreach($otherAttributes as $otherAttribute) { + foreach ($otherAttributes as $otherAttribute) { $this->addOtherAttribute($otherAttribute); } } @@ -149,7 +149,7 @@ public function getHumanizedKey() // Resolve key from array validation if ($primaryAttribute) { $split = explode('.', $key); - $key = implode(' ', array_map(function($word) { + $key = implode(' ', array_map(function ($word) { if (is_numeric($word)) { $word = $word + 1; } @@ -169,5 +169,4 @@ public function getAlias() { return $this->alias; } - } diff --git a/src/ErrorBag.php b/src/ErrorBag.php index e37fe1a..3b70f32 100644 --- a/src/ErrorBag.php +++ b/src/ErrorBag.php @@ -38,7 +38,7 @@ public function has($key) if (!$ruleName) { return !empty($messages); } else { - return !empty($messages) AND isset($messages[$ruleName]); + return !empty($messages) and isset($messages[$ruleName]); } } } @@ -71,15 +71,17 @@ public function get($key, $format = ':message') $results = []; if ($this->isWildcardKey($key)) { $messages = $this->filterMessagesForWildcardKey($key, $ruleName); - foreach($messages as $explicitKey => $keyMessages) { + foreach ($messages as $explicitKey => $keyMessages) { foreach ($keyMessages as $rule => $message) { $results[$explicitKey][$rule] = $this->formatMessage($message, $format); } } } else { $keyMessages = isset($this->messages[$key])? $this->messages[$key] : []; - foreach($keyMessages as $rule => $message) { - if ($ruleName AND $ruleName != $rule) continue; + foreach ($keyMessages as $rule => $message) { + if ($ruleName and $ruleName != $rule) { + continue; + } $results[$rule] = $this->formatMessage($message, $format); } } @@ -91,8 +93,8 @@ public function all($format = ':message') { $messages = $this->messages; $results = []; - foreach($messages as $key => $keyMessages) { - foreach($keyMessages as $message) { + foreach ($messages as $key => $keyMessages) { + foreach ($keyMessages as $message) { $results[] = $this->formatMessage($message, $format); } } @@ -103,7 +105,7 @@ public function firstOfAll($format = ':message', $dotNotation = false) { $messages = $this->messages; $results = []; - foreach($messages as $key => $keyMessages) { + foreach ($messages as $key => $keyMessages) { if ($dotNotation) { $results[$key] = $this->formatMessage(array_shift($messages[$key]), $format); } else { @@ -144,8 +146,10 @@ protected function filterMessagesForWildcardKey($key, $ruleName = null) continue; } - foreach($keyMessages as $rule => $message) { - if ($ruleName AND $rule != $ruleName) continue; + foreach ($keyMessages as $rule => $message) { + if ($ruleName and $rule != $ruleName) { + continue; + } $filteredMessages[$k][$rule] = $message; } } @@ -157,5 +161,4 @@ protected function formatMessage($message, $format) { return str_replace(':message', $message, $format); } - } diff --git a/src/Helper.php b/src/Helper.php index 0596152..47f2af3 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -204,5 +204,4 @@ public static function snakeCase($value, $delimiter = '_') return $value; } - } diff --git a/src/MimeTypeGuesser.php b/src/MimeTypeGuesser.php index 17d292a..feb5496 100644 --- a/src/MimeTypeGuesser.php +++ b/src/MimeTypeGuesser.php @@ -788,5 +788,4 @@ public function getMimeType($extension) $key = array_search($extension, $this->mimeTypes); return $key ?: null; } - } diff --git a/src/Rule.php b/src/Rule.php index 1a1080b..6890711 100644 --- a/src/Rule.php +++ b/src/Rule.php @@ -16,7 +16,7 @@ abstract class Rule protected $params = []; - protected $fillable_params = []; + protected $fillableParams = []; protected $message = "The :attribute is invalid"; @@ -66,8 +66,10 @@ public function setParameter($key, $value) public function fillParameters(array $params) { - foreach($this->fillable_params as $key) { - if (empty($params)) break; + foreach ($this->fillableParams as $key) { + if (empty($params)) { + break; + } $this->params[$key] = array_shift($params); } return $this; @@ -101,12 +103,11 @@ public function getMessage() protected function requireParameters(array $params) { - foreach($params as $param) { + foreach ($params as $param) { if (!isset($this->params[$param])) { $rule = $this->getKey(); throw new MissingRequiredParameterException("Missing required parameter '{$param}' on rule '{$rule}'"); } } } - } diff --git a/src/Rules/Accepted.php b/src/Rules/Accepted.php index fb9f27b..57d105d 100644 --- a/src/Rules/Accepted.php +++ b/src/Rules/Accepted.php @@ -15,5 +15,4 @@ public function check($value) $acceptables = ['yes', 'on', '1', 1, true, 'true']; return in_array($value, $acceptables, true); } - } diff --git a/src/Rules/After.php b/src/Rules/After.php index 8fdf8d1..950e16f 100644 --- a/src/Rules/After.php +++ b/src/Rules/After.php @@ -11,14 +11,14 @@ class After extends Rule protected $message = "The :attribute must be a date after :time."; - protected $fillable_params = ['time']; + protected $fillableParams = ['time']; public function check($value) { - $this->requireParameters($this->fillable_params); + $this->requireParameters($this->fillableParams); $time = $this->parameter('time'); - if (!$this->isValidDate($value)){ + if (!$this->isValidDate($value)) { throw $this->throwException($value); } diff --git a/src/Rules/Alpha.php b/src/Rules/Alpha.php index 225fe5d..949fb9b 100644 --- a/src/Rules/Alpha.php +++ b/src/Rules/Alpha.php @@ -13,5 +13,4 @@ public function check($value) { return is_string($value) && preg_match('/^[\pL\pM]+$/u', $value); } - } diff --git a/src/Rules/AlphaDash.php b/src/Rules/AlphaDash.php index 11c34dd..4c2762e 100644 --- a/src/Rules/AlphaDash.php +++ b/src/Rules/AlphaDash.php @@ -17,5 +17,4 @@ public function check($value) return preg_match('/^[\pL\pM\pN_-]+$/u', $value) > 0; } - } diff --git a/src/Rules/AlphaNum.php b/src/Rules/AlphaNum.php index fba0002..c8c199e 100644 --- a/src/Rules/AlphaNum.php +++ b/src/Rules/AlphaNum.php @@ -17,5 +17,4 @@ public function check($value) return preg_match('/^[\pL\pM\pN]+$/u', $value) > 0; } - } diff --git a/src/Rules/Before.php b/src/Rules/Before.php index b35b09e..b2640f5 100644 --- a/src/Rules/Before.php +++ b/src/Rules/Before.php @@ -10,14 +10,14 @@ class Before extends Rule protected $message = "The :attribute must be a date before :time."; - protected $fillable_params = ['time']; + protected $fillableParams = ['time']; public function check($value) { - $this->requireParameters($this->fillable_params); + $this->requireParameters($this->fillableParams); $time = $this->parameter('time'); - if (!$this->isValidDate($value)){ + if (!$this->isValidDate($value)) { throw $this->throwException($value); } diff --git a/src/Rules/Between.php b/src/Rules/Between.php index fa4df9c..9317de1 100644 --- a/src/Rules/Between.php +++ b/src/Rules/Between.php @@ -9,24 +9,23 @@ class Between extends Rule protected $message = "The :attribute must be between :min and :max"; - protected $fillable_params = ['min', 'max']; + protected $fillableParams = ['min', 'max']; public function check($value) { - $this->requireParameters($this->fillable_params); + $this->requireParameters($this->fillableParams); $min = (int) $this->parameter('min'); $max = (int) $this->parameter('max'); if (is_int($value) || is_float($value)) { - return $value >= $min AND $value <= $max; - } elseif(is_string($value)) { - return mb_strlen($value, 'UTF-8') >= $min AND mb_strlen($value, 'UTF-8') <= $max; - } elseif(is_array($value)) { - return count($value) >= $min AND count($value) <= $max; + return $value >= $min and $value <= $max; + } elseif (is_string($value)) { + return mb_strlen($value, 'UTF-8') >= $min and mb_strlen($value, 'UTF-8') <= $max; + } elseif (is_array($value)) { + return count($value) >= $min and count($value) <= $max; } else { return false; } } - } diff --git a/src/Rules/Callback.php b/src/Rules/Callback.php index d8e9991..ecfa235 100644 --- a/src/Rules/Callback.php +++ b/src/Rules/Callback.php @@ -11,7 +11,7 @@ class Callback extends Rule protected $message = "The :attribute is not valid"; - protected $fillable_params = ['callback']; + protected $fillableParams = ['callback']; public function setCallback(Closure $callback) { @@ -20,7 +20,7 @@ public function setCallback(Closure $callback) public function check($value) { - $this->requireParameters($this->fillable_params); + $this->requireParameters($this->fillableParams); $callback = $this->parameter('callback'); if (false === $callback instanceof Closure) { @@ -34,11 +34,10 @@ public function check($value) if (is_string($invalidMessage)) { $this->setMessage($invalidMessage); return false; - } elseif(false === $invalidMessage) { + } elseif (false === $invalidMessage) { return false; } return true; } - } diff --git a/src/Rules/Date.php b/src/Rules/Date.php index 73f4be5..8c95333 100644 --- a/src/Rules/Date.php +++ b/src/Rules/Date.php @@ -9,7 +9,7 @@ class Date extends Rule protected $message = "The :attribute is not valid date format"; - protected $fillable_params = ['format']; + protected $fillableParams = ['format']; protected $params = [ 'format' => 'Y-m-d' @@ -17,10 +17,9 @@ class Date extends Rule public function check($value) { - $this->requireParameters($this->fillable_params); + $this->requireParameters($this->fillableParams); $format = $this->parameter('format'); return date_create_from_format($format, $value) !== false; } - } diff --git a/src/Rules/Defaults.php b/src/Rules/Defaults.php index e1dc268..08ff26b 100644 --- a/src/Rules/Defaults.php +++ b/src/Rules/Defaults.php @@ -9,14 +9,13 @@ class Defaults extends Rule protected $message = "The :attribute default is :default"; - protected $fillable_params = ['default']; + protected $fillableParams = ['default']; public function check($value) { - $this->requireParameters($this->fillable_params); + $this->requireParameters($this->fillableParams); $default = $this->parameter('default'); return $default; } - } diff --git a/src/Rules/Different.php b/src/Rules/Different.php index fdab36c..1002e4c 100644 --- a/src/Rules/Different.php +++ b/src/Rules/Different.php @@ -9,16 +9,15 @@ class Different extends Rule protected $message = "The :attribute must be different with :field"; - protected $fillable_params = ['field']; + protected $fillableParams = ['field']; public function check($value) { - $this->requireParameters($this->fillable_params); + $this->requireParameters($this->fillableParams); $field = $this->parameter('field'); - $another_value = $this->validation->getValue($field); + $anotherValue = $this->validation->getValue($field); - return $value != $another_value; + return $value != $anotherValue; } - } diff --git a/src/Rules/Digits.php b/src/Rules/Digits.php index d578021..6a44271 100644 --- a/src/Rules/Digits.php +++ b/src/Rules/Digits.php @@ -9,16 +9,15 @@ class Digits extends Rule protected $message = "The :attribute must be numeric and must have an exact length of :length"; - protected $fillable_params = ['length']; + protected $fillableParams = ['length']; public function check($value) { - $this->requireParameters($this->fillable_params); + $this->requireParameters($this->fillableParams); $length = (int) $this->parameter('length'); return ! preg_match('/[^0-9]/', $value) && strlen((string) $value) == $length; } - } diff --git a/src/Rules/DigitsBetween.php b/src/Rules/DigitsBetween.php index 4209fc6..5bad524 100644 --- a/src/Rules/DigitsBetween.php +++ b/src/Rules/DigitsBetween.php @@ -9,11 +9,11 @@ class DigitsBetween extends Rule protected $message = "The :attribute must have a length between the given :min and :max"; - protected $fillable_params = ['min', 'max']; + protected $fillableParams = ['min', 'max']; public function check($value) { - $this->requireParameters($this->fillable_params); + $this->requireParameters($this->fillableParams); $min = (int) $this->parameter('min'); $max = (int) $this->parameter('max'); @@ -23,5 +23,4 @@ public function check($value) return ! preg_match('/[^0-9]/', $value) && $length >= $min && $length <= $max; } - } diff --git a/src/Rules/Email.php b/src/Rules/Email.php index 7d83694..9cf29dc 100644 --- a/src/Rules/Email.php +++ b/src/Rules/Email.php @@ -13,5 +13,4 @@ public function check($value) { return filter_var($value, FILTER_VALIDATE_EMAIL) !== false; } - } diff --git a/src/Rules/FileTrait.php b/src/Rules/FileTrait.php index d9bc3c5..4f39494 100644 --- a/src/Rules/FileTrait.php +++ b/src/Rules/FileTrait.php @@ -14,11 +14,15 @@ trait FileTrait */ public function isValueFromUploadedFiles($value) { - if (!is_array($value)) return false; + if (!is_array($value)) { + return false; + } $keys = ['name', 'type', 'tmp_name', 'size', 'error']; - foreach($keys as $key) { - if (!array_key_exists($key, $value)) return false; + foreach ($keys as $key) { + if (!array_key_exists($key, $value)) { + return false; + } } return true; @@ -26,7 +30,7 @@ public function isValueFromUploadedFiles($value) public function isUploadedFile($value) { - return $this->isValueFromUploadedFiles($value) AND is_uploaded_file($value['tmp_name']); + return $this->isValueFromUploadedFiles($value) and is_uploaded_file($value['tmp_name']); } protected function getBytes($size) diff --git a/src/Rules/In.php b/src/Rules/In.php index 3845edb..780b708 100644 --- a/src/Rules/In.php +++ b/src/Rules/In.php @@ -13,7 +13,7 @@ class In extends Rule public function fillParameters(array $params) { - if (count($params) == 1 AND is_array($params[0])) { + if (count($params) == 1 and is_array($params[0])) { $params = $params[0]; } $this->params['allowed_values'] = $params; @@ -32,5 +32,4 @@ public function check($value) $allowed_values = $this->parameter('allowed_values'); return in_array($value, $allowed_values, $this->strict); } - } diff --git a/src/Rules/Integer.php b/src/Rules/Integer.php index 04ffd7c..be36998 100644 --- a/src/Rules/Integer.php +++ b/src/Rules/Integer.php @@ -13,5 +13,4 @@ public function check($value) { return filter_var($value, FILTER_VALIDATE_INT) !== false; } - } diff --git a/src/Rules/Ip.php b/src/Rules/Ip.php index d8429d8..ca277b6 100644 --- a/src/Rules/Ip.php +++ b/src/Rules/Ip.php @@ -13,5 +13,4 @@ public function check($value) { return filter_var($value, FILTER_VALIDATE_IP) !== false; } - } diff --git a/src/Rules/Ipv4.php b/src/Rules/Ipv4.php index 3fa9bcf..00748f9 100644 --- a/src/Rules/Ipv4.php +++ b/src/Rules/Ipv4.php @@ -13,5 +13,4 @@ public function check($value) { return filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false; } - } diff --git a/src/Rules/Ipv6.php b/src/Rules/Ipv6.php index 3958bea..0b1e32d 100644 --- a/src/Rules/Ipv6.php +++ b/src/Rules/Ipv6.php @@ -13,5 +13,4 @@ public function check($value) { return filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false; } - } diff --git a/src/Rules/Json.php b/src/Rules/Json.php index d2853f2..a706881 100644 --- a/src/Rules/Json.php +++ b/src/Rules/Json.php @@ -23,5 +23,4 @@ public function check($value) return true; } - } diff --git a/src/Rules/Lowercase.php b/src/Rules/Lowercase.php index ff32814..3f6e207 100644 --- a/src/Rules/Lowercase.php +++ b/src/Rules/Lowercase.php @@ -11,7 +11,6 @@ class Lowercase extends Rule public function check($value) { - return mb_strtolower($value, mb_detect_encoding($value)) === $value; + return mb_strtolower($value, mb_detect_encoding($value)) === $value; } - } diff --git a/src/Rules/Max.php b/src/Rules/Max.php index 7d5aad8..2ec577d 100644 --- a/src/Rules/Max.php +++ b/src/Rules/Max.php @@ -9,22 +9,21 @@ class Max extends Rule protected $message = "The :attribute maximum is :max"; - protected $fillable_params = ['max']; + protected $fillableParams = ['max']; public function check($value) { - $this->requireParameters($this->fillable_params); + $this->requireParameters($this->fillableParams); $max = (int) $this->parameter('max'); if (is_int($value)) { return $value <= $max; - } elseif(is_string($value)) { + } elseif (is_string($value)) { return mb_strlen($value, 'UTF-8') <= $max; - } elseif(is_array($value)) { + } elseif (is_array($value)) { return count($value) <= $max; } else { return false; } } - } diff --git a/src/Rules/Min.php b/src/Rules/Min.php index b9cf1e7..9e3a2b6 100644 --- a/src/Rules/Min.php +++ b/src/Rules/Min.php @@ -9,22 +9,21 @@ class Min extends Rule protected $message = "The :attribute minimum is :min"; - protected $fillable_params = ['min']; + protected $fillableParams = ['min']; public function check($value) { - $this->requireParameters($this->fillable_params); + $this->requireParameters($this->fillableParams); $min = (int) $this->parameter('min'); if (is_int($value)) { return $value >= $min; - } elseif(is_string($value)) { + } elseif (is_string($value)) { return mb_strlen($value, 'UTF-8') >= $min; - } elseif(is_array($value)) { + } elseif (is_array($value)) { return count($value) >= $min; } else { return false; } } - } diff --git a/src/Rules/NotIn.php b/src/Rules/NotIn.php index 8abbb24..6bcbc7d 100644 --- a/src/Rules/NotIn.php +++ b/src/Rules/NotIn.php @@ -13,7 +13,7 @@ class NotIn extends Rule public function fillParameters(array $params) { - if (count($params) == 1 AND is_array($params[0])) { + if (count($params) == 1 and is_array($params[0])) { $params = $params[0]; } $this->params['disallowed_values'] = $params; @@ -28,8 +28,7 @@ public function strict($strict = true) public function check($value) { $this->requireParameters(['disallowed_values']); - $disallowed_values = (array) $this->parameter('disallowed_values'); - return !in_array($value, $disallowed_values, $this->strict); + $disallowedValues = (array) $this->parameter('disallowed_values'); + return !in_array($value, $disallowedValues, $this->strict); } - } diff --git a/src/Rules/Numeric.php b/src/Rules/Numeric.php index f312fb4..7863899 100644 --- a/src/Rules/Numeric.php +++ b/src/Rules/Numeric.php @@ -13,5 +13,4 @@ public function check($value) { return is_numeric($value); } - } diff --git a/src/Rules/Present.php b/src/Rules/Present.php index 4bc6d24..1d588c8 100644 --- a/src/Rules/Present.php +++ b/src/Rules/Present.php @@ -14,5 +14,4 @@ public function check($value) { return $this->validation->hasValue($this->attribute->getKey()); } - } diff --git a/src/Rules/Regex.php b/src/Rules/Regex.php index ab68eeb..047dbf1 100644 --- a/src/Rules/Regex.php +++ b/src/Rules/Regex.php @@ -9,13 +9,12 @@ class Regex extends Rule protected $message = "The :attribute is not valid format"; - protected $fillable_params = ['regex']; + protected $fillableParams = ['regex']; public function check($value) { - $this->requireParameters($this->fillable_params); + $this->requireParameters($this->fillableParams); $regex = $this->parameter('regex'); return preg_match($regex, $value) > 0; } - } diff --git a/src/Rules/Required.php b/src/Rules/Required.php index 48aa1e8..6fd448b 100644 --- a/src/Rules/Required.php +++ b/src/Rules/Required.php @@ -16,12 +16,16 @@ public function check($value) { $this->setAttributeAsRequired(); - if ($this->attribute AND $this->attribute->hasRule('uploaded_file')) { - return $this->isValueFromUploadedFiles($value) AND $value['error'] != UPLOAD_ERR_NO_FILE; + if ($this->attribute and $this->attribute->hasRule('uploaded_file')) { + return $this->isValueFromUploadedFiles($value) and $value['error'] != UPLOAD_ERR_NO_FILE; } - if (is_string($value)) return mb_strlen(trim($value), 'UTF-8') > 0; - if (is_array($value)) return count($value) > 0; + if (is_string($value)) { + return mb_strlen(trim($value), 'UTF-8') > 0; + } + if (is_array($value)) { + return count($value) > 0; + } return !is_null($value); } @@ -31,5 +35,4 @@ protected function setAttributeAsRequired() $this->attribute->setRequired(true); } } - } diff --git a/src/Rules/RequiredIf.php b/src/Rules/RequiredIf.php index 618f3c8..345039f 100644 --- a/src/Rules/RequiredIf.php +++ b/src/Rules/RequiredIf.php @@ -26,14 +26,13 @@ public function check($value) $anotherValue = $this->getAttribute()->getValue($anotherAttribute); $validator = $this->validation->getValidator(); - $required_validator = $validator('required'); + $requiredValidator = $validator('required'); if (in_array($anotherValue, $definedValues)) { $this->setAttributeAsRequired(); - return $required_validator->check($value, []); + return $requiredValidator->check($value, []); } return true; } - } diff --git a/src/Rules/RequiredUnless.php b/src/Rules/RequiredUnless.php index 7c747e1..97c8309 100644 --- a/src/Rules/RequiredUnless.php +++ b/src/Rules/RequiredUnless.php @@ -26,14 +26,13 @@ public function check($value) $anotherValue = $this->getAttribute()->getValue($anotherAttribute); $validator = $this->validation->getValidator(); - $required_validator = $validator('required'); + $requiredValidator = $validator('required'); if (!in_array($anotherValue, $definedValues)) { $this->setAttributeAsRequired(); - return $required_validator->check($value, []); + return $requiredValidator->check($value, []); } return true; } - } diff --git a/src/Rules/RequiredWith.php b/src/Rules/RequiredWith.php index cacf392..e432742 100644 --- a/src/Rules/RequiredWith.php +++ b/src/Rules/RequiredWith.php @@ -21,16 +21,15 @@ public function check($value) $this->requireParameters(['fields']); $fields = $this->parameter('fields'); $validator = $this->validation->getValidator(); - $required_validator = $validator('required'); + $requiredValidator = $validator('required'); - foreach($fields as $field) { + foreach ($fields as $field) { if ($this->validation->hasValue($field)) { $this->setAttributeAsRequired(); - return $required_validator->check($value, []); + return $requiredValidator->check($value, []); } } return true; } - } diff --git a/src/Rules/RequiredWithAll.php b/src/Rules/RequiredWithAll.php index 0b49656..1ef06b3 100644 --- a/src/Rules/RequiredWithAll.php +++ b/src/Rules/RequiredWithAll.php @@ -21,16 +21,15 @@ public function check($value) $this->requireParameters(['fields']); $fields = $this->parameter('fields'); $validator = $this->validation->getValidator(); - $required_validator = $validator('required'); + $requiredValidator = $validator('required'); - foreach($fields as $field) { + foreach ($fields as $field) { if (!$this->validation->hasValue($field)) { return true; } } $this->setAttributeAsRequired(); - return $required_validator->check($value, []); + return $requiredValidator->check($value, []); } - } diff --git a/src/Rules/RequiredWithout.php b/src/Rules/RequiredWithout.php index 78ae7e4..ee02e8a 100644 --- a/src/Rules/RequiredWithout.php +++ b/src/Rules/RequiredWithout.php @@ -21,16 +21,15 @@ public function check($value) $this->requireParameters(['fields']); $fields = $this->parameter('fields'); $validator = $this->validation->getValidator(); - $required_validator = $validator('required'); + $requiredValidator = $validator('required'); - foreach($fields as $field) { + foreach ($fields as $field) { if (!$this->validation->hasValue($field)) { $this->setAttributeAsRequired(); - return $required_validator->check($value, []); + return $requiredValidator->check($value, []); } } return true; } - } diff --git a/src/Rules/RequiredWithoutAll.php b/src/Rules/RequiredWithoutAll.php index cfc515f..5656f13 100644 --- a/src/Rules/RequiredWithoutAll.php +++ b/src/Rules/RequiredWithoutAll.php @@ -21,16 +21,15 @@ public function check($value) $this->requireParameters(['fields']); $fields = $this->parameter('fields'); $validator = $this->validation->getValidator(); - $required_validator = $validator('required'); + $requiredValidator = $validator('required'); - foreach($fields as $field) { + foreach ($fields as $field) { if ($this->validation->hasValue($field)) { return true; } } $this->setAttributeAsRequired(); - return $required_validator->check($value, []); + return $requiredValidator->check($value, []); } - } diff --git a/src/Rules/Same.php b/src/Rules/Same.php index 508071b..76ac577 100644 --- a/src/Rules/Same.php +++ b/src/Rules/Same.php @@ -9,16 +9,15 @@ class Same extends Rule protected $message = "The :attribute must be same with :field"; - protected $fillable_params = ['field']; + protected $fillableParams = ['field']; public function check($value) { - $this->requireParameters($this->fillable_params); + $this->requireParameters($this->fillableParams); $field = $this->parameter('field'); $anotherValue = $this->getAttribute()->getValue($field); return $value == $anotherValue; } - } diff --git a/src/Rules/TypeArray.php b/src/Rules/TypeArray.php index d706df9..47838b9 100644 --- a/src/Rules/TypeArray.php +++ b/src/Rules/TypeArray.php @@ -13,5 +13,4 @@ public function check($value) { return is_array($value); } - } diff --git a/src/Rules/UploadedFile.php b/src/Rules/UploadedFile.php index babc2ef..3ac02d7 100644 --- a/src/Rules/UploadedFile.php +++ b/src/Rules/UploadedFile.php @@ -62,7 +62,7 @@ public function check($value) $allowedTypes = $this->parameter('allowed_types'); // below is Required rule job - if (!$this->isValueFromUploadedFiles($value) OR $value['error'] == UPLOAD_ERR_NO_FILE) { + if (!$this->isValueFromUploadedFiles($value) or $value['error'] == UPLOAD_ERR_NO_FILE) { return true; } @@ -71,7 +71,9 @@ public function check($value) } // just make sure there is no error - if ($value['error']) return false; + if ($value['error']) { + return false; + } if ($minSize) { $bytesMinSize = $this->getBytes($minSize); diff --git a/src/Rules/Uppercase.php b/src/Rules/Uppercase.php index 641e681..eebe2a5 100644 --- a/src/Rules/Uppercase.php +++ b/src/Rules/Uppercase.php @@ -11,7 +11,6 @@ class Uppercase extends Rule public function check($value) { - return mb_strtoupper($value, mb_detect_encoding($value)) === $value; + return mb_strtoupper($value, mb_detect_encoding($value)) === $value; } - } diff --git a/src/Rules/Url.php b/src/Rules/Url.php index c1549e8..ce5f2d6 100644 --- a/src/Rules/Url.php +++ b/src/Rules/Url.php @@ -11,7 +11,7 @@ class Url extends Rule public function fillParameters(array $params) { - if (count($params) == 1 AND is_array($params[0])) { + if (count($params) == 1 and is_array($params[0])) { $params = $params[0]; } return $this->forScheme($params); @@ -36,7 +36,7 @@ public function check($value) if ($this->{$method}($value)) { return true; } - } elseif($this->validateCommonScheme($value, $scheme)) { + } elseif ($this->validateCommonScheme($value, $scheme)) { return true; } } @@ -68,5 +68,4 @@ public function validateJdbcScheme($value) { return (bool) preg_match("/^jdbc:\w+:\/\//", $value); } - } diff --git a/src/Validation.php b/src/Validation.php index 51cb4f5..6c187ac 100644 --- a/src/Validation.php +++ b/src/Validation.php @@ -30,15 +30,15 @@ public function __construct(Validator $validator, array $inputs, array $rules, a $this->inputs = $this->resolveInputAttributes($inputs); $this->messages = $messages; $this->errors = new ErrorBag; - foreach($rules as $attributeKey => $rules) { + foreach ($rules as $attributeKey => $rules) { $this->addAttribute($attributeKey, $rules); } } public function addAttribute($attributeKey, $rules) { - $resolved_rules = $this->resolveRules($rules); - $attribute = new Attribute($this, $attributeKey, $this->getAlias($attributeKey), $resolved_rules); + $resolvedRules = $this->resolveRules($rules); + $attribute = new Attribute($this, $attributeKey, $this->getAlias($attributeKey), $resolvedRules); $this->attributes[$attributeKey] = $attribute; } @@ -51,7 +51,7 @@ public function validate(array $inputs = array()) { $this->errors = new ErrorBag; // reset error bag $this->inputs = array_merge($this->inputs, $this->resolveInputAttributes($inputs)); - foreach($this->attributes as $attributeKey => $attribute) { + foreach ($this->attributes as $attributeKey => $attribute) { $this->validateAttribute($attribute); } } @@ -65,7 +65,7 @@ protected function validateAttribute(Attribute $attribute) { if ($this->isArrayAttribute($attribute)) { $attributes = $this->parseArrayAttribute($attribute); - foreach($attributes as $i => $attr) { + foreach ($attributes as $i => $attr) { $this->validateAttribute($attr); } return; @@ -78,7 +78,7 @@ protected function validateAttribute(Attribute $attribute) $isEmptyValue = $this->isEmptyValue($value); $isValid = true; - foreach($rules as $ruleValidator) { + foreach ($rules as $ruleValidator) { $ruleValidator->setAttribute($attribute); if ($isEmptyValue && $ruleValidator instanceof Defaults) { @@ -89,7 +89,7 @@ protected function validateAttribute(Attribute $attribute) $valid = $ruleValidator->check($value); - if ($isEmptyValue AND $this->ruleIsOptional($attribute, $ruleValidator)) { + if ($isEmptyValue and $this->ruleIsOptional($attribute, $ruleValidator)) { continue; } @@ -123,7 +123,8 @@ protected function parseArrayAttribute(Attribute $attribute) $pattern = str_replace('\*', '([^\.]+)', preg_quote($attributeKey)); $data = array_merge($data, $this->extractValuesForWildcards( - $data, $attributeKey + $data, + $attributeKey )); $attributes = []; @@ -254,8 +255,8 @@ protected function isEmptyValue($value) protected function ruleIsOptional(Attribute $attribute, Rule $rule) { - return false === $attribute->isRequired() AND - false === $rule->isImplicit() AND + return false === $attribute->isRequired() and + false === $rule->isImplicit() and false === $rule instanceof Required; } @@ -264,7 +265,7 @@ protected function resolveAttributeName(Attribute $attribute) $primaryAttribute = $attribute->getPrimaryAttribute(); if (isset($this->aliases[$attribute->getKey()])) { return $this->aliases[$attribute->getKey()]; - } elseif($primaryAttribute AND isset($this->aliases[$primaryAttribute->getKey()])) { + } elseif ($primaryAttribute and isset($this->aliases[$primaryAttribute->getKey()])) { return $this->aliases[$primaryAttribute->getKey()]; } elseif ($this->validator->getUseHumanizedKeys()) { return $attribute->getHumanizedKey(); @@ -281,7 +282,7 @@ protected function resolveMessage(Attribute $attribute, $value, Rule $validator) $ruleKey = $validator->getKey(); $alias = $attribute->getAlias() ?: $this->resolveAttributeName($attribute); $message = $validator->getMessage(); // default rule message - $message_keys = [ + $messageKeys = [ $attributeKey.$this->messageSeparator.$ruleKey, $attributeKey, $ruleKey @@ -289,7 +290,7 @@ protected function resolveMessage(Attribute $attribute, $value, Rule $validator) if ($primaryAttribute) { // insert primaryAttribute keys - // $message_keys = [ + // $messageKeys = [ // $attributeKey.$this->messageSeparator.$ruleKey, // >> here [1] << // $attributeKey, @@ -297,11 +298,11 @@ protected function resolveMessage(Attribute $attribute, $value, Rule $validator) // $ruleKey // ]; $primaryAttributeKey = $primaryAttribute->getKey(); - array_splice($message_keys, 1, 0, $primaryAttributeKey.$this->messageSeparator.$ruleKey); - array_splice($message_keys, 3, 0, $primaryAttributeKey); + array_splice($messageKeys, 1, 0, $primaryAttributeKey.$this->messageSeparator.$ruleKey); + array_splice($messageKeys, 3, 0, $primaryAttributeKey); } - foreach($message_keys as $key) { + foreach ($messageKeys as $key) { if (isset($this->messages[$key])) { $message = $this->messages[$key]; break; @@ -314,7 +315,7 @@ protected function resolveMessage(Attribute $attribute, $value, Rule $validator) 'value' => $value, ]); - foreach($vars as $key => $value) { + foreach ($vars as $key => $value) { $value = $this->stringify($value); $message = str_replace(':'.$key, $value, $message); } @@ -340,7 +341,7 @@ protected function stringify($value) { if (is_string($value) || is_numeric($value)) { return $value; - } elseif(is_array($value) || is_object($value)) { + } elseif (is_array($value) || is_object($value)) { return json_encode($value); } else { return ''; @@ -353,29 +354,31 @@ protected function resolveRules($rules) $rules = explode('|', $rules); } - $resolved_rules = []; + $resolvedRules = []; $validatorFactory = $this->getValidator(); - foreach($rules as $i => $rule) { - if (empty($rule)) continue; + foreach ($rules as $i => $rule) { + if (empty($rule)) { + continue; + } $params = []; if (is_string($rule)) { list($rulename, $params) = $this->parseRule($rule); $validator = call_user_func_array($validatorFactory, array_merge([$rulename], $params)); - } elseif($rule instanceof Rule) { + } elseif ($rule instanceof Rule) { $validator = $rule; - } elseif($rule instanceof Closure) { + } elseif ($rule instanceof Closure) { $validator = call_user_func_array($validatorFactory, ['callback', $rule]); } else { $ruleName = is_object($rule) ? get_class($rule) : gettype($rule); throw new \Exception("Rule must be a string, closure or Rakit\Validation\Rule instance. ".$ruleName." given"); } - $resolved_rules[] = $validator; + $resolvedRules[] = $validator; } - return $resolved_rules; + return $resolvedRules; } protected function parseRule($rule) @@ -444,7 +447,7 @@ public function getValidator() protected function resolveInputAttributes(array $inputs) { $resolvedInputs = []; - foreach($inputs as $key => $rules) { + foreach ($inputs as $key => $rules) { $exp = explode(':', $key); if (count($exp) > 1) { @@ -458,7 +461,8 @@ protected function resolveInputAttributes(array $inputs) return $resolvedInputs; } - public function getValidatedData() { + public function getValidatedData() + { return array_merge($this->validData, $this->invalidData); } @@ -493,5 +497,4 @@ public function getInvalidData() { return $this->invalidData; } - } diff --git a/src/Validator.php b/src/Validator.php index f95ac5e..112afbb 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -114,7 +114,7 @@ protected function registerBaseValidators() 'default' => new Rules\Defaults, // alias of defaults ]; - foreach($baseValidator as $key => $validator) { + foreach ($baseValidator as $key => $validator) { $this->setValidator($key, $validator); } } diff --git a/tests/ErrorBagTest.php b/tests/ErrorBagTest.php index b35b747..9f78c61 100644 --- a/tests/ErrorBagTest.php +++ b/tests/ErrorBagTest.php @@ -310,5 +310,4 @@ public function testFirstOfAllDotNotation() 'items.1.qty' => 'prefix b suffix', ]); } - } diff --git a/tests/Fixtures/Even.php b/tests/Fixtures/Even.php index c221dbc..74fcb5a 100644 --- a/tests/Fixtures/Even.php +++ b/tests/Fixtures/Even.php @@ -11,11 +11,10 @@ class Even extends Rule public function check($value) { - if ( ! is_numeric($value)) { + if (! is_numeric($value)) { return false; } return $value % 2 === 0; } - } diff --git a/tests/HelperTest.php b/tests/HelperTest.php index dc8f290..a6275a3 100644 --- a/tests/HelperTest.php +++ b/tests/HelperTest.php @@ -131,5 +131,4 @@ public function testArrayUnset() 'message' => "lorem ipsum", ]); } - } diff --git a/tests/Rules/AcceptedTest.php b/tests/Rules/AcceptedTest.php index 97a8b33..dbad471 100644 --- a/tests/Rules/AcceptedTest.php +++ b/tests/Rules/AcceptedTest.php @@ -30,5 +30,4 @@ public function testInvalids() $this->assertFalse($this->rule->check(' 1')); $this->assertFalse($this->rule->check(10)); } - } diff --git a/tests/Rules/AlphaDashTest.php b/tests/Rules/AlphaDashTest.php index 2375874..269d383 100644 --- a/tests/Rules/AlphaDashTest.php +++ b/tests/Rules/AlphaDashTest.php @@ -28,5 +28,4 @@ public function testInvalids() $this->assertFalse($this->rule->check('foo bar')); $this->assertFalse($this->rule->check('123 bar ')); } - } diff --git a/tests/Rules/AlphaNumTest.php b/tests/Rules/AlphaNumTest.php index ef9bb95..dbbff98 100644 --- a/tests/Rules/AlphaNumTest.php +++ b/tests/Rules/AlphaNumTest.php @@ -27,5 +27,4 @@ public function testInvalids() $this->assertFalse($this->rule->check('123 foo')); $this->assertFalse($this->rule->check(' foo123 ')); } - } diff --git a/tests/Rules/AlphaTest.php b/tests/Rules/AlphaTest.php index 47bddc7..11e6b4b 100644 --- a/tests/Rules/AlphaTest.php +++ b/tests/Rules/AlphaTest.php @@ -30,5 +30,4 @@ public function testInvalids() $this->assertFalse($this->rule->check('foo123bar')); $this->assertFalse($this->rule->check('foo bar')); } - } diff --git a/tests/Rules/BetweenTest.php b/tests/Rules/BetweenTest.php index 58f7382..cbe2d1a 100644 --- a/tests/Rules/BetweenTest.php +++ b/tests/Rules/BetweenTest.php @@ -30,5 +30,4 @@ public function testInvalids() $this->assertFalse($this->rule->fillParameters([50, 100])->check(123)); $this->assertFalse($this->rule->fillParameters([50, 100])->check(123.4)); } - } diff --git a/tests/Rules/CallbackTest.php b/tests/Rules/CallbackTest.php index 20f9227..de36ce8 100644 --- a/tests/Rules/CallbackTest.php +++ b/tests/Rules/CallbackTest.php @@ -11,8 +11,8 @@ class CallbackTest extends TestCase public function setUp() { $this->rule = new Callback; - $this->rule->setCallback(function($value) { - return (is_numeric($value) AND $value % 2 === 0); + $this->rule->setCallback(function ($value) { + return (is_numeric($value) and $value % 2 === 0); }); } @@ -29,5 +29,4 @@ public function testInvalids() $this->assertFalse($this->rule->check('abc12')); $this->assertFalse($this->rule->check("12abc")); } - } diff --git a/tests/Rules/DateTest.php b/tests/Rules/DateTest.php index 0615ff7..1619e28 100644 --- a/tests/Rules/DateTest.php +++ b/tests/Rules/DateTest.php @@ -24,5 +24,4 @@ public function testInvalids() $this->assertFalse($this->rule->check("10-10-2010")); $this->assertFalse($this->rule->fillParameters(['Y-m-d'])->check("2010-10-10 10:10")); } - } diff --git a/tests/Rules/DefaultsTest.php b/tests/Rules/DefaultsTest.php index 5c2aa79..72715c0 100644 --- a/tests/Rules/DefaultsTest.php +++ b/tests/Rules/DefaultsTest.php @@ -19,5 +19,4 @@ public function testDefaults() $this->assertEquals($this->rule->fillParameters(['something'])->check(null), 'something'); $this->assertEquals($this->rule->fillParameters([[1,2,3]])->check('anything'), [1,2,3]); } - } diff --git a/tests/Rules/DigitsBetweenTest.php b/tests/Rules/DigitsBetweenTest.php index 1159d2e..0602663 100644 --- a/tests/Rules/DigitsBetweenTest.php +++ b/tests/Rules/DigitsBetweenTest.php @@ -28,5 +28,4 @@ public function testInvalids() $this->assertFalse($this->rule->fillParameters([1, 3])->check(12345)); $this->assertFalse($this->rule->fillParameters([3, 6])->check('foobar')); } - } diff --git a/tests/Rules/DigitsTest.php b/tests/Rules/DigitsTest.php index c31ecbc..7d9db2e 100644 --- a/tests/Rules/DigitsTest.php +++ b/tests/Rules/DigitsTest.php @@ -26,5 +26,4 @@ public function testInvalids() $this->assertFalse($this->rule->fillParameters([4])->check(12)); $this->assertFalse($this->rule->fillParameters([3])->check('foo')); } - } diff --git a/tests/Rules/EmailTest.php b/tests/Rules/EmailTest.php index 151dc0c..66ba2fc 100644 --- a/tests/Rules/EmailTest.php +++ b/tests/Rules/EmailTest.php @@ -28,5 +28,4 @@ public function testInvalids() $this->assertFalse($this->rule->check('johndoe.gmail.com')); $this->assertFalse($this->rule->check('johndoe.gmail.com')); } - } diff --git a/tests/Rules/InTest.php b/tests/Rules/InTest.php index 55e85fd..29e86be 100644 --- a/tests/Rules/InTest.php +++ b/tests/Rules/InTest.php @@ -35,5 +35,4 @@ public function testStricts() $this->assertFalse($this->rule->fillParameters(['1', '2', '3'])->check(1)); $this->assertFalse($this->rule->fillParameters(['1', '2', '3'])->check(1)); } - } diff --git a/tests/Rules/IntegerTest.php b/tests/Rules/IntegerTest.php index 71ea8f7..101a4d4 100644 --- a/tests/Rules/IntegerTest.php +++ b/tests/Rules/IntegerTest.php @@ -21,7 +21,6 @@ public function testValids() $this->assertTrue($this->rule->check('-123')); $this->assertTrue($this->rule->check(123)); $this->assertTrue($this->rule->check(-123)); - } public function testInvalids() @@ -32,5 +31,4 @@ public function testInvalids() $this->assertFalse($this->rule->check('123.456')); $this->assertFalse($this->rule->check('-123.456')); } - } diff --git a/tests/Rules/IpTest.php b/tests/Rules/IpTest.php index df8bcd9..0eac7eb 100644 --- a/tests/Rules/IpTest.php +++ b/tests/Rules/IpTest.php @@ -28,5 +28,4 @@ public function testInvalids() $this->assertFalse($this->rule->check('hf02::2')); $this->assertFalse($this->rule->check('12345:0000:3238:DFE1:0063:0000:0000:FEFB')); } - } diff --git a/tests/Rules/Ipv4Test.php b/tests/Rules/Ipv4Test.php index 5597774..41bd6fe 100644 --- a/tests/Rules/Ipv4Test.php +++ b/tests/Rules/Ipv4Test.php @@ -25,5 +25,4 @@ public function testInvalids() $this->assertFalse($this->rule->check('hf02::2')); $this->assertFalse($this->rule->check('12345:0000:3238:DFE1:0063:0000:0000:FEFB')); } - } diff --git a/tests/Rules/Ipv6Test.php b/tests/Rules/Ipv6Test.php index f06d7cc..f3ab8d3 100644 --- a/tests/Rules/Ipv6Test.php +++ b/tests/Rules/Ipv6Test.php @@ -24,5 +24,4 @@ public function testInvalids() $this->assertFalse($this->rule->check('hf02::2')); $this->assertFalse($this->rule->check('12345:0000:3238:DFE1:0063:0000:0000:FEFB')); } - } diff --git a/tests/Rules/JsonTest.php b/tests/Rules/JsonTest.php index b40617e..9daa860 100644 --- a/tests/Rules/JsonTest.php +++ b/tests/Rules/JsonTest.php @@ -31,6 +31,4 @@ public function testInvalids() $this->assertFalse($this->rule->check('{"username": John Doe}')); $this->assertFalse($this->rule->check('{number: 12345678}')); } - } - diff --git a/tests/Rules/LowercaseTest.php b/tests/Rules/LowercaseTest.php index c03a496..dcc17b4 100644 --- a/tests/Rules/LowercaseTest.php +++ b/tests/Rules/LowercaseTest.php @@ -26,5 +26,4 @@ public function testInvalids() $this->assertFalse($this->rule->check('Username')); $this->assertFalse($this->rule->check('userName')); } - } diff --git a/tests/Rules/MaxTest.php b/tests/Rules/MaxTest.php index 327934e..0ce0a2f 100644 --- a/tests/Rules/MaxTest.php +++ b/tests/Rules/MaxTest.php @@ -31,5 +31,4 @@ public function testInvalids() $this->assertFalse($this->rule->fillParameters([2])->check([1,2,3])); $this->assertFalse($this->rule->fillParameters([100])->check(123)); } - } diff --git a/tests/Rules/MinTest.php b/tests/Rules/MinTest.php index 9347d0d..e946261 100644 --- a/tests/Rules/MinTest.php +++ b/tests/Rules/MinTest.php @@ -31,5 +31,4 @@ public function testInvalids() $this->assertFalse($this->rule->fillParameters([4])->check('ワード')); $this->assertFalse($this->rule->fillParameters([2])->check('字')); } - } diff --git a/tests/Rules/NotInTest.php b/tests/Rules/NotInTest.php index 3b4e89a..34f0523 100644 --- a/tests/Rules/NotInTest.php +++ b/tests/Rules/NotInTest.php @@ -35,5 +35,4 @@ public function testStricts() $this->assertTrue($this->rule->fillParameters(['1', '2', '3'])->check(1)); $this->assertTrue($this->rule->fillParameters(['1', '2', '3'])->check(1)); } - } diff --git a/tests/Rules/NumericTest.php b/tests/Rules/NumericTest.php index 0738c80..cc309df 100644 --- a/tests/Rules/NumericTest.php +++ b/tests/Rules/NumericTest.php @@ -28,5 +28,4 @@ public function testInvalids() $this->assertFalse($this->rule->check('123foo')); $this->assertFalse($this->rule->check([123])); } - } diff --git a/tests/Rules/RegexTest.php b/tests/Rules/RegexTest.php index cb0a69e..d5d5f35 100644 --- a/tests/Rules/RegexTest.php +++ b/tests/Rules/RegexTest.php @@ -22,5 +22,4 @@ public function testInvalids() { $this->assertFalse($this->rule->fillParameters(["/^F/i"])->check("bar")); } - } diff --git a/tests/Rules/RequiredTest.php b/tests/Rules/RequiredTest.php index 6edf7e0..3f3535f 100644 --- a/tests/Rules/RequiredTest.php +++ b/tests/Rules/RequiredTest.php @@ -31,5 +31,4 @@ public function testInvalids() $this->assertFalse($this->rule->check('')); $this->assertFalse($this->rule->check([])); } - } diff --git a/tests/Rules/TypeArrayTest.php b/tests/Rules/TypeArrayTest.php index d9d6f26..56e8e60 100644 --- a/tests/Rules/TypeArrayTest.php +++ b/tests/Rules/TypeArrayTest.php @@ -25,5 +25,4 @@ public function testInvalids() $this->assertFalse($this->rule->check('[]')); $this->assertFalse($this->rule->check('[1,2,3]')); } - } diff --git a/tests/Rules/UppercaseTest.php b/tests/Rules/UppercaseTest.php index db779f0..cf7bdc8 100644 --- a/tests/Rules/UppercaseTest.php +++ b/tests/Rules/UppercaseTest.php @@ -26,5 +26,4 @@ public function testInvalids() $this->assertFalse($this->rule->check('Username')); $this->assertFalse($this->rule->check('userName')); } - } diff --git a/tests/Rules/UrlTest.php b/tests/Rules/UrlTest.php index b15b5c7..d91fe3d 100644 --- a/tests/Rules/UrlTest.php +++ b/tests/Rules/UrlTest.php @@ -50,5 +50,4 @@ public function testInvalids() $this->assertFalse($this->rule->forScheme('jdbc')->check('http://www.foobar.com')); $this->assertFalse($this->rule->forScheme(['http', 'https'])->check('any://www.foobar.com')); } - } diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index a174730..9289bbb 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -87,7 +87,7 @@ public function testRequiredUploadedFile() public function testOptionalUploadedFile() { - $empty_file = [ + $emptyFile = [ 'name' => '', 'type' => '', 'size' => '', @@ -96,7 +96,7 @@ public function testOptionalUploadedFile() ]; $validation = $this->validator->validate([ - 'file' => $empty_file + 'file' => $emptyFile ], [ 'file' => 'uploaded_file' ]); @@ -106,10 +106,10 @@ public function testOptionalUploadedFile() /** * @dataProvider getSamplesMissingKeyFromUploadedFileValue */ - public function testMissingKeyUploadedFile($uploaded_file) + public function testMissingKeyUploadedFile($uploadedFile) { $validation = $this->validator->validate([ - 'file' => $uploaded_file + 'file' => $uploadedFile ], [ 'file' => 'required|uploaded_file' ]); @@ -121,7 +121,7 @@ public function testMissingKeyUploadedFile($uploaded_file) public function getSamplesMissingKeyFromUploadedFileValue() { - $valid_uploaded_file = [ + $validUploadedFile = [ 'name' => 'foo', 'type' => 'text/plain', 'size' => 1000, @@ -130,10 +130,10 @@ public function getSamplesMissingKeyFromUploadedFileValue() ]; $samples = []; - foreach($valid_uploaded_file as $key => $value) { - $uploaded_file = $valid_uploaded_file; - unset($uploaded_file[$key]); - $samples[] = $uploaded_file; + foreach ($validUploadedFile as $key => $value) { + $uploadedFile = $validUploadedFile; + unset($uploadedFile[$key]); + $samples[] = $uploadedFile; } return $samples; } @@ -287,7 +287,7 @@ public function testNonExistentValidationRule() 'name' => "some name" ], [ 'name' => 'required|xxx' - ],[ + ], [ 'name.required' => "Fill in your name", 'xxx' => "Oops" ]); @@ -309,7 +309,7 @@ public function testBeforeRule() $validator2 = $this->validator->make($data, [ 'date' => "required|before:last week" - ],[]); + ], []); $validator2->validate(); @@ -330,7 +330,7 @@ public function testAfterRule() $validator2 = $this->validator->make($data, [ 'date' => "required|after:next year" - ],[]); + ], []); $validator2->validate(); @@ -630,7 +630,7 @@ public function testSetCustomMessagesInValidation() public function testCustomMessageInCallbackRule() { $evenNumberValidator = function ($value) { - if (!is_numeric($value) OR $value % 2 !== 0) { + if (!is_numeric($value) or $value % 2 !== 0) { return ":attribute must be even number"; } return true; @@ -1010,5 +1010,4 @@ public function testGetInvalidData() $this->assertFalse(isset($stuffs['one'])); $this->assertFalse(isset($stuffs['two'])); } - }