diff --git a/.scrutinizer.yml b/.scrutinizer.yml index aeca59935..d31d0e856 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -10,6 +10,9 @@ tools: external_code_coverage: true php_analyzer: true php_changetracking: true + php_code_sniffer: + config: + standard: "PSR2" php_cpd: true php_mess_detector: true php_pdepend: true diff --git a/LICENSE b/LICENSE index 05b7b5512..4b241ad16 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009-2014, Alexandre Gomes Gaigalas. +Copyright (c) 2009-2015, Alexandre Gomes Gaigalas. All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/library/ExceptionIterator.php b/library/ExceptionIterator.php index 3aa37742a..eb08e861f 100644 --- a/library/ExceptionIterator.php +++ b/library/ExceptionIterator.php @@ -28,4 +28,3 @@ public function getChildren() return new static($this->current()->getRelated($this->fullRelated), $this->fullRelated); } } - diff --git a/library/Exceptions/AbstractGroupedException.php b/library/Exceptions/AbstractGroupedException.php index e794eb3b4..d90ac9f01 100644 --- a/library/Exceptions/AbstractGroupedException.php +++ b/library/Exceptions/AbstractGroupedException.php @@ -13,7 +13,7 @@ class AbstractGroupedException extends AbstractNestedException self::MODE_NEGATIVE => array( self::NONE => 'None of there rules must pass for {{name}}', self::SOME => 'These rules must not pass for {{name}}', - ) + ), ); public function chooseTemplate() @@ -40,11 +40,11 @@ public function getTemplate() if (!$isEmpty && $this->template != $parentTemplate) { return $this->template; - } if ($isEmpty && 1 === count($this->related)) { + } + if ($isEmpty && 1 === count($this->related)) { return current($this->related)->getTemplate(); } else { return $parentTemplate; } } } - diff --git a/library/Exceptions/AbstractNestedException.php b/library/Exceptions/AbstractNestedException.php index a03368683..1339cce32 100644 --- a/library/Exceptions/AbstractNestedException.php +++ b/library/Exceptions/AbstractNestedException.php @@ -52,7 +52,7 @@ public function findRelated($path) return $target; } - public function getIterator($full=false, $mode=self::ITERATE_ALL) + public function getIterator($full = false, $mode = self::ITERATE_ALL) { $exceptionIterator = new ExceptionIterator($this, $full); @@ -74,7 +74,7 @@ public function getFullMessage() return implode(PHP_EOL, $message); } - public function getRelated($full=false) + public function getRelated($full = false) { if (!$full && 1 === count($this->related) && current($this->related) instanceof AbstractNestedException) { @@ -104,4 +104,3 @@ public function setRelated(array $relatedExceptions) return $this; } } - diff --git a/library/Exceptions/AllOfException.php b/library/Exceptions/AllOfException.php index bf2662ee3..be5de197a 100644 --- a/library/Exceptions/AllOfException.php +++ b/library/Exceptions/AllOfException.php @@ -11,7 +11,6 @@ class AllOfException extends AbstractGroupedException self::MODE_NEGATIVE => array( self::NONE => 'None of these rules must pass for {{name}}', self::SOME => 'These rules must not pass for {{name}}', - ) + ), ); } - diff --git a/library/Exceptions/AlnumException.php b/library/Exceptions/AlnumException.php index 51f7759d8..1b3b26d33 100644 --- a/library/Exceptions/AlnumException.php +++ b/library/Exceptions/AlnumException.php @@ -6,12 +6,11 @@ class AlnumException extends AlphaException public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must contain only letters (a-z) and digits (0-9)', - self::EXTRA => '{{name}} must contain only letters (a-z), digits (0-9) and "{{additionalChars}}"' + self::EXTRA => '{{name}} must contain only letters (a-z), digits (0-9) and "{{additionalChars}}"', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not contain letters (a-z) or digits (0-9)', - self::EXTRA => '{{name}} must not contain letters (a-z), digits (0-9) or "{{additionalChars}}"' - ) + self::EXTRA => '{{name}} must not contain letters (a-z), digits (0-9) or "{{additionalChars}}"', + ), ); } - diff --git a/library/Exceptions/AlphaException.php b/library/Exceptions/AlphaException.php index b21496ffe..24b2e943d 100644 --- a/library/Exceptions/AlphaException.php +++ b/library/Exceptions/AlphaException.php @@ -8,12 +8,12 @@ class AlphaException extends ValidationException public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must contain only letters (a-z)', - self::EXTRA => '{{name}} must contain only letters (a-z) and "{{additionalChars}}"' + self::EXTRA => '{{name}} must contain only letters (a-z) and "{{additionalChars}}"', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not contain letters (a-z)', - self::EXTRA => '{{name}} must not contain letters (a-z) or "{{additionalChars}}"' - ) + self::EXTRA => '{{name}} must not contain letters (a-z) or "{{additionalChars}}"', + ), ); public function chooseTemplate() @@ -21,4 +21,3 @@ public function chooseTemplate() return $this->getParam('additionalChars') ? static::EXTRA : static::STANDARD; } } - diff --git a/library/Exceptions/AlwaysInvalidException.php b/library/Exceptions/AlwaysInvalidException.php index 4dd403377..d078f4a47 100644 --- a/library/Exceptions/AlwaysInvalidException.php +++ b/library/Exceptions/AlwaysInvalidException.php @@ -9,7 +9,6 @@ class AlwaysInvalidException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} is always valid', - ) + ), ); } - diff --git a/library/Exceptions/AlwaysValidException.php b/library/Exceptions/AlwaysValidException.php index ee962fc0a..674fe2917 100644 --- a/library/Exceptions/AlwaysValidException.php +++ b/library/Exceptions/AlwaysValidException.php @@ -9,7 +9,6 @@ class AlwaysValidException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} is always invalid', - ) + ), ); } - diff --git a/library/Exceptions/ArrException.php b/library/Exceptions/ArrException.php index 63b715004..5f2a2ab51 100644 --- a/library/Exceptions/ArrException.php +++ b/library/Exceptions/ArrException.php @@ -9,7 +9,6 @@ class ArrException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be an array', - ) + ), ); } - diff --git a/library/Exceptions/AtLeastException.php b/library/Exceptions/AtLeastException.php index 590f21305..6e01b20f9 100644 --- a/library/Exceptions/AtLeastException.php +++ b/library/Exceptions/AtLeastException.php @@ -11,7 +11,6 @@ class AtLeastException extends AbstractGroupedException self::MODE_NEGATIVE => array( self::NONE => 'At least {{howMany}} of the {{failed}} required rules must not pass for {{name}}', self::SOME => 'At least {{howMany}} of the {{failed}} required rules must not pass for {{name}}, only {{passed}} passed.', - ) + ), ); } - diff --git a/library/Exceptions/AttributeException.php b/library/Exceptions/AttributeException.php index 8f0684236..561a78764 100644 --- a/library/Exceptions/AttributeException.php +++ b/library/Exceptions/AttributeException.php @@ -13,7 +13,7 @@ class AttributeException extends AbstractNestedException self::MODE_NEGATIVE => array( self::NOT_PRESENT => 'Attribute {{name}} must not be present', self::INVALID => 'Attribute {{name}} must not validate', - ) + ), ); public function chooseTemplate() @@ -21,4 +21,3 @@ public function chooseTemplate() return $this->getParam('hasReference') ? static::INVALID : static::NOT_PRESENT; } } - diff --git a/library/Exceptions/BaseException.php b/library/Exceptions/BaseException.php index a0681b010..cf7c00e0a 100644 --- a/library/Exceptions/BaseException.php +++ b/library/Exceptions/BaseException.php @@ -3,6 +3,4 @@ class BaseException extends ValidationException { - } - diff --git a/library/Exceptions/BetweenException.php b/library/Exceptions/BetweenException.php index 66cdef45c..0cbbe4537 100644 --- a/library/Exceptions/BetweenException.php +++ b/library/Exceptions/BetweenException.php @@ -17,10 +17,10 @@ class BetweenException extends AbstractNestedException self::BOTH => '{{name}} must not be between {{minValue}} and {{maxValue}}', self::LOWER => '{{name}} must not be greater than {{minValue}}', self::GREATER => '{{name}} must not be lower than {{maxValue}}', - ) + ), ); - public function configure($name, array $params=array()) + public function configure($name, array $params = array()) { $params['minValue'] = static::stringify($params['minValue']); $params['maxValue'] = static::stringify($params['maxValue']); @@ -39,4 +39,3 @@ public function chooseTemplate() } } } - diff --git a/library/Exceptions/BoolException.php b/library/Exceptions/BoolException.php index 9aeac697c..4529f0d07 100644 --- a/library/Exceptions/BoolException.php +++ b/library/Exceptions/BoolException.php @@ -9,7 +9,6 @@ class BoolException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a boolean', - ) + ), ); } - diff --git a/library/Exceptions/CallException.php b/library/Exceptions/CallException.php index 838f51b4d..5293afe56 100644 --- a/library/Exceptions/CallException.php +++ b/library/Exceptions/CallException.php @@ -4,4 +4,3 @@ class CallException extends AbstractGroupedException { } - diff --git a/library/Exceptions/CallbackException.php b/library/Exceptions/CallbackException.php index 127deadc7..2cd42e6f1 100644 --- a/library/Exceptions/CallbackException.php +++ b/library/Exceptions/CallbackException.php @@ -9,7 +9,6 @@ class CallbackException extends AbstractNestedException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be valid', - ) + ), ); } - diff --git a/library/Exceptions/CharsetException.php b/library/Exceptions/CharsetException.php index 31d8d41c1..bcbdcbdc2 100644 --- a/library/Exceptions/CharsetException.php +++ b/library/Exceptions/CharsetException.php @@ -5,11 +5,10 @@ class CharsetException extends ValidationException { public static $defaultTemplates = array( self::MODE_DEFAULT => array( - self::STANDARD => '{{name}} must be in the {{charset}} charset' + self::STANDARD => '{{name}} must be in the {{charset}} charset', ), self::MODE_NEGATIVE => array( - self::STANDARD => '{{name}} must not be in the {{charset}} charset' - ) + self::STANDARD => '{{name}} must not be in the {{charset}} charset', + ), ); } - diff --git a/library/Exceptions/CnhException.php b/library/Exceptions/CnhException.php index 65ee95f7c..bb7479d19 100644 --- a/library/Exceptions/CnhException.php +++ b/library/Exceptions/CnhException.php @@ -9,7 +9,6 @@ class CnhException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid CNH number', - ) + ), ); } - diff --git a/library/Exceptions/CnpjException.php b/library/Exceptions/CnpjException.php index f30da8b3a..b803c372d 100644 --- a/library/Exceptions/CnpjException.php +++ b/library/Exceptions/CnpjException.php @@ -4,14 +4,12 @@ class CnpjException extends ValidationException { - public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must be a valid CNPJ number', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid CNPJ number', - ) + ), ); - -} +} diff --git a/library/Exceptions/CntrlException.php b/library/Exceptions/CntrlException.php index f5dbe029c..56eea09cf 100644 --- a/library/Exceptions/CntrlException.php +++ b/library/Exceptions/CntrlException.php @@ -6,12 +6,11 @@ class CntrlException extends AlphaException public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must contain only control characters', - self::EXTRA => '{{name}} must contain only control characters and "{{additionalChars}}"' + self::EXTRA => '{{name}} must contain only control characters and "{{additionalChars}}"', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not contain control characters', - self::EXTRA => '{{name}} must not contain control characters or "{{additionalChars}}"' - ) + self::EXTRA => '{{name}} must not contain control characters or "{{additionalChars}}"', + ), ); } - diff --git a/library/Exceptions/ComponentException.php b/library/Exceptions/ComponentException.php index 7ec827894..55c20f199 100644 --- a/library/Exceptions/ComponentException.php +++ b/library/Exceptions/ComponentException.php @@ -6,4 +6,3 @@ class ComponentException extends Exception { } - diff --git a/library/Exceptions/ConsonantException.php b/library/Exceptions/ConsonantException.php index 266bbb5b4..506bd12fe 100644 --- a/library/Exceptions/ConsonantException.php +++ b/library/Exceptions/ConsonantException.php @@ -6,12 +6,11 @@ class ConsonantException extends AlphaException public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must contain only consonants', - self::EXTRA => '{{name}} must contain only consonants and "{{additionalChars}}"' + self::EXTRA => '{{name}} must contain only consonants and "{{additionalChars}}"', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not contain consonants', - self::EXTRA => '{{name}} must not contain consonants or "{{additionalChars}}"' - ) + self::EXTRA => '{{name}} must not contain consonants or "{{additionalChars}}"', + ), ); } - diff --git a/library/Exceptions/ContainsException.php b/library/Exceptions/ContainsException.php index ede2c161b..fb3308e8e 100644 --- a/library/Exceptions/ContainsException.php +++ b/library/Exceptions/ContainsException.php @@ -9,7 +9,6 @@ class ContainsException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not contain the value "{{containsValue}}"', - ) + ), ); } - diff --git a/library/Exceptions/CountryCodeException.php b/library/Exceptions/CountryCodeException.php index ab54ce355..7afae478b 100644 --- a/library/Exceptions/CountryCodeException.php +++ b/library/Exceptions/CountryCodeException.php @@ -9,7 +9,6 @@ class CountryCodeException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid country', - ) + ), ); } - diff --git a/library/Exceptions/CpfException.php b/library/Exceptions/CpfException.php index 318cbd52e..9627cd759 100644 --- a/library/Exceptions/CpfException.php +++ b/library/Exceptions/CpfException.php @@ -9,7 +9,6 @@ class CpfException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid CPF number', - ) + ), ); } - diff --git a/library/Exceptions/CreditCardException.php b/library/Exceptions/CreditCardException.php index 1305c8d78..1ebf8a4ae 100644 --- a/library/Exceptions/CreditCardException.php +++ b/library/Exceptions/CreditCardException.php @@ -9,7 +9,6 @@ class CreditCardException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid Credit Card number', - ) + ), ); } - diff --git a/library/Exceptions/DateException.php b/library/Exceptions/DateException.php index 9da429ded..aeb51d8db 100644 --- a/library/Exceptions/DateException.php +++ b/library/Exceptions/DateException.php @@ -8,18 +8,19 @@ class DateException extends ValidationException public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must be a valid date', - self::FORMAT => '{{name}} must be a valid date. Sample format: {{format}}' + self::FORMAT => '{{name}} must be a valid date. Sample format: {{format}}', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid date', - self::FORMAT => '{{name}} must not be a valid date in the format {{format}}' - ) + self::FORMAT => '{{name}} must not be a valid date in the format {{format}}', + ), ); - public function configure($name, array $params=array()) + public function configure($name, array $params = array()) { $params['format'] = date( - $params['format'], strtotime('2005-12-30 01:02:03') + $params['format'], + strtotime('2005-12-30 01:02:03') ); return parent::configure($name, $params); @@ -30,4 +31,3 @@ public function chooseTemplate() return $this->getParam('format') ? static::FORMAT : static::STANDARD; } } - diff --git a/library/Exceptions/DigitException.php b/library/Exceptions/DigitException.php index 6750ca5f5..c52a5ffd9 100644 --- a/library/Exceptions/DigitException.php +++ b/library/Exceptions/DigitException.php @@ -6,12 +6,11 @@ class DigitException extends AlphaException public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must contain only digits (0-9)', - self::EXTRA => '{{name}} must contain only digits (0-9) and "{{additionalChars}}"' + self::EXTRA => '{{name}} must contain only digits (0-9) and "{{additionalChars}}"', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not contain digits (0-9)', - self::EXTRA => '{{name}} must not contain digits (0-9) or "{{additionalChars}}"' - ) + self::EXTRA => '{{name}} must not contain digits (0-9) or "{{additionalChars}}"', + ), ); } - diff --git a/library/Exceptions/DirectoryException.php b/library/Exceptions/DirectoryException.php index 186fd9596..d0de1afd3 100644 --- a/library/Exceptions/DirectoryException.php +++ b/library/Exceptions/DirectoryException.php @@ -9,7 +9,6 @@ class DirectoryException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a directory', - ) + ), ); } - diff --git a/library/Exceptions/DomainException.php b/library/Exceptions/DomainException.php index 16242751f..ac7d2358d 100644 --- a/library/Exceptions/DomainException.php +++ b/library/Exceptions/DomainException.php @@ -9,7 +9,6 @@ class DomainException extends AbstractNestedException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid domain', - ) + ), ); } - diff --git a/library/Exceptions/EachException.php b/library/Exceptions/EachException.php index c87fb635b..98d174c21 100644 --- a/library/Exceptions/EachException.php +++ b/library/Exceptions/EachException.php @@ -9,7 +9,6 @@ class EachException extends AbstractNestedException ), self::MODE_NEGATIVE => array( self::STANDARD => 'Each item in {{name}} must not validate', - ) + ), ); } - diff --git a/library/Exceptions/EmailException.php b/library/Exceptions/EmailException.php index cbf2068b9..09432f26a 100644 --- a/library/Exceptions/EmailException.php +++ b/library/Exceptions/EmailException.php @@ -9,7 +9,6 @@ class EmailException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be an email', - ) + ), ); } - diff --git a/library/Exceptions/EndsWithException.php b/library/Exceptions/EndsWithException.php index 5ef40a349..b6ba3f764 100644 --- a/library/Exceptions/EndsWithException.php +++ b/library/Exceptions/EndsWithException.php @@ -9,7 +9,6 @@ class EndsWithException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not end with ({{endValue}})', - ) + ), ); } - diff --git a/library/Exceptions/EqualsException.php b/library/Exceptions/EqualsException.php index 50ba2bf3b..2aa40d109 100644 --- a/library/Exceptions/EqualsException.php +++ b/library/Exceptions/EqualsException.php @@ -14,7 +14,7 @@ class EqualsException extends ValidationException self::MODE_NEGATIVE => array( self::EQUALS => '{{name}} must not be equals {{compareTo}}', self::IDENTICAL => '{{name}} must not be identical as {{compareTo}}', - ) + ), ); public function chooseTemplate() @@ -22,4 +22,3 @@ public function chooseTemplate() return $this->getParam('identical') ? static::IDENTICAL : static::EQUALS; } } - diff --git a/library/Exceptions/EvenException.php b/library/Exceptions/EvenException.php index f6f2d9b87..511e5bae8 100644 --- a/library/Exceptions/EvenException.php +++ b/library/Exceptions/EvenException.php @@ -9,7 +9,6 @@ class EvenException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be an even number', - ) + ), ); } - diff --git a/library/Exceptions/ExecutableException.php b/library/Exceptions/ExecutableException.php index fb6029f46..84a5158ad 100644 --- a/library/Exceptions/ExecutableException.php +++ b/library/Exceptions/ExecutableException.php @@ -10,6 +10,6 @@ class ExecutableException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be an executable file', - ) + ), ); } diff --git a/library/Exceptions/ExistsException.php b/library/Exceptions/ExistsException.php index 240cb886a..360a66ceb 100644 --- a/library/Exceptions/ExistsException.php +++ b/library/Exceptions/ExistsException.php @@ -4,14 +4,12 @@ class ExistsException extends ValidationException { - public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must exists', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not exists', - ) + ), ); - } diff --git a/library/Exceptions/FileException.php b/library/Exceptions/FileException.php index e6368a2f2..13ab5b986 100644 --- a/library/Exceptions/FileException.php +++ b/library/Exceptions/FileException.php @@ -4,14 +4,12 @@ class FileException extends ValidationException { - public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must be a file', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a file', - ) + ), ); - } diff --git a/library/Exceptions/FloatException.php b/library/Exceptions/FloatException.php index 0c42efa6f..1296a1031 100644 --- a/library/Exceptions/FloatException.php +++ b/library/Exceptions/FloatException.php @@ -9,7 +9,6 @@ class FloatException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a float number', - ) + ), ); } - diff --git a/library/Exceptions/GraphException.php b/library/Exceptions/GraphException.php index a50129cdb..14a4df517 100644 --- a/library/Exceptions/GraphException.php +++ b/library/Exceptions/GraphException.php @@ -6,12 +6,11 @@ class GraphException extends AlphaException public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must contain only graphical characters', - self::EXTRA => '{{name}} must contain only graphical characters and "{{additionalChars}}"' + self::EXTRA => '{{name}} must contain only graphical characters and "{{additionalChars}}"', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not contain graphical characters', - self::EXTRA => '{{name}} must not contain graphical characters or "{{additionalChars}}"' - ) + self::EXTRA => '{{name}} must not contain graphical characters or "{{additionalChars}}"', + ), ); } - diff --git a/library/Exceptions/HexRgbColorException.php b/library/Exceptions/HexRgbColorException.php index a36701a94..b2b639dd7 100644 --- a/library/Exceptions/HexRgbColorException.php +++ b/library/Exceptions/HexRgbColorException.php @@ -9,7 +9,6 @@ class HexRgbColorException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a hex RGB color', - ) + ), ); } - diff --git a/library/Exceptions/HexaException.php b/library/Exceptions/HexaException.php index a359ae1f7..991775489 100644 --- a/library/Exceptions/HexaException.php +++ b/library/Exceptions/HexaException.php @@ -9,7 +9,6 @@ class HexaException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a hexadecimal number', - ) + ), ); } - diff --git a/library/Exceptions/InException.php b/library/Exceptions/InException.php index 909854caa..83302a541 100644 --- a/library/Exceptions/InException.php +++ b/library/Exceptions/InException.php @@ -9,7 +9,6 @@ class InException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be in ({{haystack}})', - ) + ), ); } - diff --git a/library/Exceptions/InstanceException.php b/library/Exceptions/InstanceException.php index 39db7ad9b..e861348f5 100644 --- a/library/Exceptions/InstanceException.php +++ b/library/Exceptions/InstanceException.php @@ -9,7 +9,6 @@ class InstanceException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be an instance of {{instanceName}}', - ) + ), ); } - diff --git a/library/Exceptions/IntException.php b/library/Exceptions/IntException.php index 25792a940..9abfb0dcf 100644 --- a/library/Exceptions/IntException.php +++ b/library/Exceptions/IntException.php @@ -9,7 +9,6 @@ class IntException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be an integer number', - ) + ), ); } - diff --git a/library/Exceptions/IpException.php b/library/Exceptions/IpException.php index 67354a693..d99be4557 100644 --- a/library/Exceptions/IpException.php +++ b/library/Exceptions/IpException.php @@ -14,19 +14,19 @@ class IpException extends ValidationException self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be an IP address', self::NETWORK_RANGE => '{{name}} must not be an IP address in the {{range}} range', - ) + ), ); - public function configure($name, array $params=array()) + public function configure($name, array $params = array()) { if ($params['networkRange']) { $range = $params['networkRange']; $message = $range['min']; if (isset($range['max'])) { - $message .= '-' . $range['max']; + $message .= '-'.$range['max']; } else { - $message .= '/' . long2ip($range['mask']); + $message .= '/'.long2ip($range['mask']); } $params['range'] = $message; @@ -44,4 +44,3 @@ public function chooseTemplate() } } } - diff --git a/library/Exceptions/JsonException.php b/library/Exceptions/JsonException.php index 93bf89670..bbc53035e 100644 --- a/library/Exceptions/JsonException.php +++ b/library/Exceptions/JsonException.php @@ -9,7 +9,6 @@ class JsonException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid JSON string', - ) + ), ); } - diff --git a/library/Exceptions/KeyException.php b/library/Exceptions/KeyException.php index 8e6228016..969734735 100644 --- a/library/Exceptions/KeyException.php +++ b/library/Exceptions/KeyException.php @@ -11,7 +11,6 @@ class KeyException extends AttributeException self::MODE_NEGATIVE => array( self::NOT_PRESENT => 'Key {{name}} must not be present', self::INVALID => 'Key {{name}} must not be valid', - ) + ), ); } - diff --git a/library/Exceptions/LengthException.php b/library/Exceptions/LengthException.php index 5338e0c47..51dd7395a 100644 --- a/library/Exceptions/LengthException.php +++ b/library/Exceptions/LengthException.php @@ -17,10 +17,10 @@ class LengthException extends ValidationException self::BOTH => '{{name}} must not have a length between {{minValue}} and {{maxValue}}', self::LOWER => '{{name}} must not have a length greater than {{minValue}}', self::GREATER => '{{name}} must not have a length lower than {{maxValue}}', - ) + ), ); - public function configure($name, array $params=array()) + public function configure($name, array $params = array()) { $params['minValue'] = static::stringify($params['minValue']); $params['maxValue'] = static::stringify($params['maxValue']); @@ -39,4 +39,3 @@ public function chooseTemplate() } } } - diff --git a/library/Exceptions/LowercaseException.php b/library/Exceptions/LowercaseException.php index 5478e1b5a..f83db92f5 100644 --- a/library/Exceptions/LowercaseException.php +++ b/library/Exceptions/LowercaseException.php @@ -9,7 +9,6 @@ class LowercaseException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be lowercase', - ) + ), ); } - diff --git a/library/Exceptions/MacAddressException.php b/library/Exceptions/MacAddressException.php index ee139937a..4a5cb1d99 100644 --- a/library/Exceptions/MacAddressException.php +++ b/library/Exceptions/MacAddressException.php @@ -9,7 +9,6 @@ class MacAddressException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid mac address', - ) + ), ); } - diff --git a/library/Exceptions/MaxException.php b/library/Exceptions/MaxException.php index 9a9b21538..373b5711d 100644 --- a/library/Exceptions/MaxException.php +++ b/library/Exceptions/MaxException.php @@ -13,7 +13,7 @@ class MaxException extends ValidationException self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be lower than {{maxValue}}', self::INCLUSIVE => '{{name}} must not be lower than or equals {{maxValue}}', - ) + ), ); public function chooseTemplate() @@ -21,4 +21,3 @@ public function chooseTemplate() return $this->getParam('inclusive') ? static::INCLUSIVE : static::STANDARD; } } - diff --git a/library/Exceptions/MinException.php b/library/Exceptions/MinException.php index 341b50f5f..70c39e6a4 100644 --- a/library/Exceptions/MinException.php +++ b/library/Exceptions/MinException.php @@ -13,7 +13,7 @@ class MinException extends ValidationException self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be greater than {{minValue}}', self::INCLUSIVE => '{{name}} must not be greater than or equals {{minValue}}', - ) + ), ); public function chooseTemplate() @@ -21,4 +21,3 @@ public function chooseTemplate() return $this->getParam('inclusive') ? static::INCLUSIVE : static::STANDARD; } } - diff --git a/library/Exceptions/MinimumAgeException.php b/library/Exceptions/MinimumAgeException.php index 89ea97582..236b30635 100644 --- a/library/Exceptions/MinimumAgeException.php +++ b/library/Exceptions/MinimumAgeException.php @@ -9,7 +9,6 @@ class MinimumAgeException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => 'The age must not be {{age}} years or more.', - ) + ), ); } - diff --git a/library/Exceptions/MostOfException.php b/library/Exceptions/MostOfException.php index cfd55d6fa..a93bef42c 100644 --- a/library/Exceptions/MostOfException.php +++ b/library/Exceptions/MostOfException.php @@ -4,4 +4,3 @@ class MostOfException extends AtLeastException { } - diff --git a/library/Exceptions/MultipleException.php b/library/Exceptions/MultipleException.php index 9568c3402..cc27d281c 100644 --- a/library/Exceptions/MultipleException.php +++ b/library/Exceptions/MultipleException.php @@ -9,7 +9,6 @@ class MultipleException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be multiple of {{multipleOf}}', - ) + ), ); } - diff --git a/library/Exceptions/NegativeException.php b/library/Exceptions/NegativeException.php index 235f7a750..65b677247 100644 --- a/library/Exceptions/NegativeException.php +++ b/library/Exceptions/NegativeException.php @@ -9,7 +9,6 @@ class NegativeException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be negative', - ) + ), ); } - diff --git a/library/Exceptions/NfeAccessKeyException.php b/library/Exceptions/NfeAccessKeyException.php index da04eb665..75a5c5725 100644 --- a/library/Exceptions/NfeAccessKeyException.php +++ b/library/Exceptions/NfeAccessKeyException.php @@ -9,7 +9,6 @@ class NfeAccessKeyException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid NFe access key', - ) + ), ); } - diff --git a/library/Exceptions/NoWhitespaceException.php b/library/Exceptions/NoWhitespaceException.php index 84311bacc..6b6f3c4bb 100644 --- a/library/Exceptions/NoWhitespaceException.php +++ b/library/Exceptions/NoWhitespaceException.php @@ -9,7 +9,6 @@ class NoWhitespaceException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not not contain whitespace', - ) + ), ); } - diff --git a/library/Exceptions/NoneOfException.php b/library/Exceptions/NoneOfException.php index ccda89442..2d5aefdec 100644 --- a/library/Exceptions/NoneOfException.php +++ b/library/Exceptions/NoneOfException.php @@ -9,7 +9,6 @@ class NoneOfException extends AbstractNestedException ), self::MODE_NEGATIVE => array( self::STANDARD => 'All of these rules must pass for {{name}}', - ) + ), ); } - diff --git a/library/Exceptions/NotEmptyException.php b/library/Exceptions/NotEmptyException.php index e74d89d7d..5bde51beb 100644 --- a/library/Exceptions/NotEmptyException.php +++ b/library/Exceptions/NotEmptyException.php @@ -13,7 +13,7 @@ class NotEmptyException extends ValidationException self::MODE_NEGATIVE => array( self::STANDARD => 'The value must be empty', self::NAMED => '{{name}} must be empty', - ) + ), ); public function chooseTemplate() @@ -21,4 +21,3 @@ public function chooseTemplate() return $this->getName() == "" ? static::STANDARD : static::NAMED; } } - diff --git a/library/Exceptions/NotException.php b/library/Exceptions/NotException.php index 288dcaca1..01ebcfb0f 100644 --- a/library/Exceptions/NotException.php +++ b/library/Exceptions/NotException.php @@ -4,4 +4,3 @@ class NotException extends AbstractGroupedException { } - diff --git a/library/Exceptions/NullValueException.php b/library/Exceptions/NullValueException.php index 932ac2941..283eb4e41 100644 --- a/library/Exceptions/NullValueException.php +++ b/library/Exceptions/NullValueException.php @@ -9,7 +9,6 @@ class NullValueException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be null', - ) + ), ); } - diff --git a/library/Exceptions/NumericException.php b/library/Exceptions/NumericException.php index 2fd3cb236..3fcf92cfa 100644 --- a/library/Exceptions/NumericException.php +++ b/library/Exceptions/NumericException.php @@ -9,7 +9,6 @@ class NumericException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be numeric', - ) + ), ); } - diff --git a/library/Exceptions/ObjectException.php b/library/Exceptions/ObjectException.php index 9e7c80363..ae8ba4d0f 100644 --- a/library/Exceptions/ObjectException.php +++ b/library/Exceptions/ObjectException.php @@ -9,7 +9,6 @@ class ObjectException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be an object', - ) + ), ); } - diff --git a/library/Exceptions/OddException.php b/library/Exceptions/OddException.php index 588783e6d..e6bae0e42 100644 --- a/library/Exceptions/OddException.php +++ b/library/Exceptions/OddException.php @@ -9,7 +9,6 @@ class OddException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be an odd number', - ) + ), ); } - diff --git a/library/Exceptions/OneOfException.php b/library/Exceptions/OneOfException.php index 914c69843..16838b1c5 100644 --- a/library/Exceptions/OneOfException.php +++ b/library/Exceptions/OneOfException.php @@ -9,7 +9,6 @@ class OneOfException extends AbstractNestedException ), self::MODE_NEGATIVE => array( self::STANDARD => 'At least one of these rules must not pass for {{name}}', - ) + ), ); } - diff --git a/library/Exceptions/PerfectSquareException.php b/library/Exceptions/PerfectSquareException.php index 1c5c39d1f..350cd52c4 100644 --- a/library/Exceptions/PerfectSquareException.php +++ b/library/Exceptions/PerfectSquareException.php @@ -9,7 +9,6 @@ class PerfectSquareException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid perfect square', - ) + ), ); } - diff --git a/library/Exceptions/PhoneException.php b/library/Exceptions/PhoneException.php index 4034c538f..41f0c191d 100644 --- a/library/Exceptions/PhoneException.php +++ b/library/Exceptions/PhoneException.php @@ -9,7 +9,6 @@ class PhoneException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid telephone number', - ) + ), ); } - diff --git a/library/Exceptions/PositiveException.php b/library/Exceptions/PositiveException.php index 2f13a1297..366bf13ab 100644 --- a/library/Exceptions/PositiveException.php +++ b/library/Exceptions/PositiveException.php @@ -9,7 +9,6 @@ class PositiveException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be positive', - ) + ), ); } - diff --git a/library/Exceptions/PostalCodeException.php b/library/Exceptions/PostalCodeException.php index 8dabd2715..375450847 100644 --- a/library/Exceptions/PostalCodeException.php +++ b/library/Exceptions/PostalCodeException.php @@ -9,6 +9,6 @@ class PostalCodeException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid postal code', - ) + ), ); } diff --git a/library/Exceptions/PrimeNumberException.php b/library/Exceptions/PrimeNumberException.php index 4d950f9e1..5ce0fb86e 100644 --- a/library/Exceptions/PrimeNumberException.php +++ b/library/Exceptions/PrimeNumberException.php @@ -9,7 +9,6 @@ class PrimeNumberException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid prime number', - ) + ), ); } - diff --git a/library/Exceptions/PrntException.php b/library/Exceptions/PrntException.php index bd9a6154e..421d0612c 100644 --- a/library/Exceptions/PrntException.php +++ b/library/Exceptions/PrntException.php @@ -6,12 +6,11 @@ class PrntException extends AlphaException public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must contain only printable characters', - self::EXTRA => '{{name}} must contain only printable characters and "{{additionalChars}}"' + self::EXTRA => '{{name}} must contain only printable characters and "{{additionalChars}}"', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not contain printable characters', - self::EXTRA => '{{name}} must not contain printable characters or "{{additionalChars}}"' - ) + self::EXTRA => '{{name}} must not contain printable characters or "{{additionalChars}}"', + ), ); } - diff --git a/library/Exceptions/PunctException.php b/library/Exceptions/PunctException.php index bda17bec6..6c6ecac2f 100644 --- a/library/Exceptions/PunctException.php +++ b/library/Exceptions/PunctException.php @@ -6,12 +6,11 @@ class PunctException extends AlphaException public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must contain only punctuation characters', - self::EXTRA => '{{name}} must contain only punctuation characters and "{{additionalChars}}"' + self::EXTRA => '{{name}} must contain only punctuation characters and "{{additionalChars}}"', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not contain punctuation characters', - self::EXTRA => '{{name}} must not contain punctuation characters or "{{additionalChars}}"' - ) + self::EXTRA => '{{name}} must not contain punctuation characters or "{{additionalChars}}"', + ), ); } - diff --git a/library/Exceptions/ReadableException.php b/library/Exceptions/ReadableException.php index 9a40f3a22..915e9c535 100644 --- a/library/Exceptions/ReadableException.php +++ b/library/Exceptions/ReadableException.php @@ -4,14 +4,12 @@ class ReadableException extends ValidationException { - public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must be readable', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be readable', - ) + ), ); - } diff --git a/library/Exceptions/RegexException.php b/library/Exceptions/RegexException.php index c850688ad..fada9550e 100644 --- a/library/Exceptions/RegexException.php +++ b/library/Exceptions/RegexException.php @@ -9,7 +9,6 @@ class RegexException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not validate against {{regex}}', - ) + ), ); } - diff --git a/library/Exceptions/RomanException.php b/library/Exceptions/RomanException.php index 6d97ba74b..8d4cbc262 100644 --- a/library/Exceptions/RomanException.php +++ b/library/Exceptions/RomanException.php @@ -9,7 +9,6 @@ class RomanException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid roman number', - ) + ), ); } - diff --git a/library/Exceptions/SfException.php b/library/Exceptions/SfException.php index 2328c6135..99d7aea6e 100644 --- a/library/Exceptions/SfException.php +++ b/library/Exceptions/SfException.php @@ -9,7 +9,6 @@ class SfException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}}', - ) + ), ); } - diff --git a/library/Exceptions/SlugException.php b/library/Exceptions/SlugException.php index fed55078f..b83dfd367 100644 --- a/library/Exceptions/SlugException.php +++ b/library/Exceptions/SlugException.php @@ -9,7 +9,6 @@ class SlugException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid slug', - ) + ), ); } - diff --git a/library/Exceptions/SpaceException.php b/library/Exceptions/SpaceException.php index fb8772f1f..ef1c34ee5 100644 --- a/library/Exceptions/SpaceException.php +++ b/library/Exceptions/SpaceException.php @@ -6,12 +6,11 @@ class SpaceException extends AlphaException public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must contain only space characters', - self::EXTRA => '{{name}} must contain only space characters and "{{additionalChars}}"' + self::EXTRA => '{{name}} must contain only space characters and "{{additionalChars}}"', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not contain space characters', - self::EXTRA => '{{name}} must not contain space characters or "{{additionalChars}}"' - ) + self::EXTRA => '{{name}} must not contain space characters or "{{additionalChars}}"', + ), ); } - diff --git a/library/Exceptions/StartsWithException.php b/library/Exceptions/StartsWithException.php index 1a9fcb87b..ce7d900c6 100644 --- a/library/Exceptions/StartsWithException.php +++ b/library/Exceptions/StartsWithException.php @@ -9,7 +9,6 @@ class StartsWithException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not start with ({{startValue}})', - ) + ), ); } - diff --git a/library/Exceptions/StringException.php b/library/Exceptions/StringException.php index b03a9939b..bfa22b53a 100644 --- a/library/Exceptions/StringException.php +++ b/library/Exceptions/StringException.php @@ -9,7 +9,6 @@ class StringException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be string', - ) + ), ); } - diff --git a/library/Exceptions/SymbolicLinkException.php b/library/Exceptions/SymbolicLinkException.php index 41eacbb37..01d4fe191 100644 --- a/library/Exceptions/SymbolicLinkException.php +++ b/library/Exceptions/SymbolicLinkException.php @@ -4,14 +4,12 @@ class SymbolicLinkException extends ValidationException { - public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must be a symbolic link', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a symbolic link', - ) + ), ); - } diff --git a/library/Exceptions/TldException.php b/library/Exceptions/TldException.php index 7e8ab60ea..9cd18fbe5 100644 --- a/library/Exceptions/TldException.php +++ b/library/Exceptions/TldException.php @@ -4,12 +4,11 @@ class TldException extends ValidationException { public static $defaultTemplates = array( - self::MODE_DEFAULT =>array( + self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must be a valid top-level domain name', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a valid top-level domain name', - ) + ), ); } - diff --git a/library/Exceptions/UploadedException.php b/library/Exceptions/UploadedException.php index 8ba096e39..1864d46bb 100644 --- a/library/Exceptions/UploadedException.php +++ b/library/Exceptions/UploadedException.php @@ -4,14 +4,12 @@ class UploadedException extends ValidationException { - public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must be an uploaded file', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be an uploaded file', - ) + ), ); - } diff --git a/library/Exceptions/UppercaseException.php b/library/Exceptions/UppercaseException.php index b82084256..4f31a0786 100644 --- a/library/Exceptions/UppercaseException.php +++ b/library/Exceptions/UppercaseException.php @@ -9,7 +9,6 @@ class UppercaseException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be uppercase', - ) + ), ); } - diff --git a/library/Exceptions/ValidationException.php b/library/Exceptions/ValidationException.php index 64b36fc8f..0bffff806 100644 --- a/library/Exceptions/ValidationException.php +++ b/library/Exceptions/ValidationException.php @@ -12,11 +12,11 @@ class ValidationException extends InvalidArgumentException const STANDARD = 0; public static $defaultTemplates = array( self::MODE_DEFAULT => array( - self::STANDARD => 'Data validation failed for %s' + self::STANDARD => 'Data validation failed for %s', ), self::MODE_NEGATIVE => array( - self::STANDARD => 'Data validation failed for %s' - ) + self::STANDARD => 'Data validation failed for %s', + ), ); protected $id = 'validation'; protected $mode = self::MODE_DEFAULT; @@ -24,11 +24,11 @@ class ValidationException extends InvalidArgumentException protected $template = ''; protected $params = array(); - public static function format($template, array $vars=array()) + public static function format($template, array $vars = array()) { return preg_replace_callback( '/{{(\w+)}}/', - function($match) use ($vars) { + function ($match) use ($vars) { return isset($vars[$match[1]]) ? $vars[$match[1]] : $match[0]; }, $template @@ -55,7 +55,7 @@ public static function stringifyObject($value) } elseif ($value instanceof DateTime) { return $value->format('Y-m-d H:i:s'); } else { - return "Object of class " . get_class($value); + return "Object of class ".get_class($value); } } @@ -179,10 +179,15 @@ protected function buildTemplate() protected function guessId() { - if (!empty($this->id) && $this->id != 'validation') + if (!empty($this->id) && $this->id != 'validation') { return $this->id; - return lcfirst(str_replace('Exception', '', - end((explode('\\', get_called_class()))))); + } + + $pieces = explode('\\', get_called_class()); + $exceptionClassShortName = end($pieces); + $ruleClassShortName = str_replace('Exception', '', $exceptionClassShortName); + $ruleName = lcfirst($ruleClassShortName); + + return $ruleName; } } - diff --git a/library/Exceptions/VersionException.php b/library/Exceptions/VersionException.php index 0ad4d3ef4..8cb690742 100644 --- a/library/Exceptions/VersionException.php +++ b/library/Exceptions/VersionException.php @@ -9,7 +9,6 @@ class VersionException extends ValidationException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be a version', - ) + ), ); } - diff --git a/library/Exceptions/VowelException.php b/library/Exceptions/VowelException.php index e7d5ddd6b..0cc584d56 100644 --- a/library/Exceptions/VowelException.php +++ b/library/Exceptions/VowelException.php @@ -6,12 +6,11 @@ class VowelException extends AlphaException public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must contain only vowels', - self::EXTRA => '{{name}} must contain only vowels and "{{additionalChars}}"' + self::EXTRA => '{{name}} must contain only vowels and "{{additionalChars}}"', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not contain vowels', - self::EXTRA => '{{name}} must not contain vowels or "{{additionalChars}}"' - ) + self::EXTRA => '{{name}} must not contain vowels or "{{additionalChars}}"', + ), ); } - diff --git a/library/Exceptions/WritableException.php b/library/Exceptions/WritableException.php index 63e72c4d3..23f58eae7 100644 --- a/library/Exceptions/WritableException.php +++ b/library/Exceptions/WritableException.php @@ -4,14 +4,12 @@ class WritableException extends ValidationException { - public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} must be writable', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not be writable', - ) + ), ); - } diff --git a/library/Exceptions/XdigitException.php b/library/Exceptions/XdigitException.php index 9ebcca649..3bbf537ce 100644 --- a/library/Exceptions/XdigitException.php +++ b/library/Exceptions/XdigitException.php @@ -6,12 +6,11 @@ class XdigitException extends AlphaException public static $defaultTemplates = array( self::MODE_DEFAULT => array( self::STANDARD => '{{name}} contain only hexadecimal digits', - self::EXTRA => '{{name}} contain only hexadecimal digits and "{{additionalChars}}"' + self::EXTRA => '{{name}} contain only hexadecimal digits and "{{additionalChars}}"', ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}} must not contain hexadecimal digits', - self::EXTRA => '{{name}} must not contain hexadecimal digits or "{{additionalChars}}"' - ) + self::EXTRA => '{{name}} must not contain hexadecimal digits or "{{additionalChars}}"', + ), ); } - diff --git a/library/Exceptions/ZendException.php b/library/Exceptions/ZendException.php index 4ec4800a5..0754a66b6 100644 --- a/library/Exceptions/ZendException.php +++ b/library/Exceptions/ZendException.php @@ -9,7 +9,6 @@ class ZendException extends AbstractNestedException ), self::MODE_NEGATIVE => array( self::STANDARD => '{{name}}', - ) + ), ); } - diff --git a/library/RecursiveTreeIterator.php b/library/RecursiveTreeIterator.php deleted file mode 100644 index 0fe0f59cf..000000000 --- a/library/RecursiveTreeIterator.php +++ /dev/null @@ -1,143 +0,0 @@ -ritFlags = $ritFlags; - } - - private $prefix = array(0 => '', 1 => '| ',2 => ' ', 3 => '|-', 4 => '\-', 5 => ''); - - /** Prefix used to start elements. */ - const PREFIX_LEFT = 0; - - /** Prefix used if $level < depth and hasNext($level) == true. */ - const PREFIX_MID_HAS_NEXT = 1; - - /** Prefix used if $level < depth and hasNext($level) == false. */ - const PREFIX_MID_LAST = 2; - - /** Prefix used if $level == depth and hasNext($level) == true. */ - const PREFIX_END_HAS_NEXT = 3; - - /** Prefix used if $level == depth and hasNext($level) == false. */ - const PREFIX_END_LAST = 4; - - /** Prefix used right in front of the current element. */ - const PREFIX_RIGHT = 5; - - /** - * Set prefix part as used in getPrefix() and stored in $prefix. - * @param $part any PREFIX_* const. - * @param $value new prefix string for specified part. - * @throws OutOfRangeException if 0 > $part or $part > 5. - */ - public function setPrefixPart($part, $value) - { - if (0 > $part || $part > 5) { - throw new OutOfRangeException(); - } - $this->prefix[$part] = (string) $value; - } - - /** @return string to place in front of current element - */ - public function getPrefix() - { - $tree = ''; - for ($level = 0; $level < $this->getDepth(); $level++) { - $tree .= $this->getSubIterator($level)->hasNext() ? $this->prefix[1] : $this->prefix[2]; - } - $tree .= $this->getSubIterator($level)->hasNext() ? $this->prefix[3] : $this->prefix[4]; - - return $this->prefix[0] . $tree . $this->prefix[5]; - } - - /** - * @return string presentation build for current element - */ - public function getEntry() - { - return @(string) parent::current(); - } - - /** - * @return string to place after the current element - */ - public function getPostfix() - { - return ''; - } - - /** - * @return the current element prefixed and postfixed - */ - public function current() - { - if ($this->ritFlags & self::BYPASS_CURRENT) { - return parent::current(); - } else { - return $this->getPrefix() . $this->getEntry() . $this->getPostfix(); - } - } - - /** - * @return the current key prefixed and postfixed - */ - public function key() - { - if ($this->ritFlags & self::BYPASS_KEY) { - return parent::key(); - } else { - return $this->getPrefix() . parent::key() . $this->getPostfix(); - } - } - - /** - * Aggregates the inner iterator - */ - public function __call($func, $params) - { - return call_user_func_array(array($this->getSubIterator(), $func), $params); - } -} diff --git a/library/Rules/AbstractComposite.php b/library/Rules/AbstractComposite.php index 95e9d0708..e9eed1542 100644 --- a/library/Rules/AbstractComposite.php +++ b/library/Rules/AbstractComposite.php @@ -29,7 +29,7 @@ public function setName($name) return parent::setName($name); } - public function addRule($validator, $arguments=array()) + public function addRule($validator, $arguments = array()) { if (!$validator instanceof Validatable) { $this->appendRule(Validator::buildRule($validator, $arguments)); @@ -79,7 +79,7 @@ public function hasRule($validator) if (is_string($validator)) { foreach ($this->rules as $rule) { - if (get_class($rule) == __NAMESPACE__ . '\\' . $validator) { + if (get_class($rule) == __NAMESPACE__.'\\'.$validator) { return true; } } @@ -112,4 +112,3 @@ protected function validateRules($input) return $exceptions; } } - diff --git a/library/Rules/AbstractCountryInfo.php b/library/Rules/AbstractCountryInfo.php index ab31b83c3..847ca977c 100644 --- a/library/Rules/AbstractCountryInfo.php +++ b/library/Rules/AbstractCountryInfo.php @@ -29,7 +29,7 @@ abstract class AbstractCountryInfo extends AbstractRule 'sr', 'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tf', 'tg', 'th', 'tj', 'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'uk', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', - 'wf', 'ws', 'ye', 'yt', 'za', 'zm', 'zw' + 'wf', 'ws', 'ye', 'yt', 'za', 'zm', 'zw', ); public function validate($input) @@ -37,4 +37,3 @@ public function validate($input) return in_array(strtolower($input), $this->tldList); } } - diff --git a/library/Rules/AbstractCtypeRule.php b/library/Rules/AbstractCtypeRule.php index 09d4873dc..dc48ac3a8 100644 --- a/library/Rules/AbstractCtypeRule.php +++ b/library/Rules/AbstractCtypeRule.php @@ -7,8 +7,10 @@ abstract protected function ctypeFunction($input); protected function filterWhiteSpaceOption($input) { - if (!empty($this->additionalChars)) + if (!empty($this->additionalChars)) { $input = str_replace(str_split($this->additionalChars), '', $input); + } + return preg_replace('/\s/', '', $input); } @@ -17,4 +19,3 @@ public function validateClean($input) return $this->ctypeFunction($input); } } - diff --git a/library/Rules/AbstractFilterRule.php b/library/Rules/AbstractFilterRule.php index 2c2eb1529..1ef30ff36 100644 --- a/library/Rules/AbstractFilterRule.php +++ b/library/Rules/AbstractFilterRule.php @@ -9,10 +9,11 @@ abstract class AbstractFilterRule extends AbstractRule abstract protected function validateClean($input); - public function __construct($additionalChars='') + public function __construct($additionalChars = '') { - if (!is_string($additionalChars)) + if (!is_string($additionalChars)) { throw new ComponentException('Invalid list of additional characters to be loaded'); + } $this->additionalChars .= $additionalChars; } @@ -24,12 +25,12 @@ protected function filter($input) public function validate($input) { - if (!is_scalar($input)) + if (!is_scalar($input)) { return false; + } $cleanInput = $this->filter((string) $input); return $cleanInput === '' || $this->validateClean($cleanInput); } } - diff --git a/library/Rules/AbstractRegexRule.php b/library/Rules/AbstractRegexRule.php index c8a3be36b..465e42023 100644 --- a/library/Rules/AbstractRegexRule.php +++ b/library/Rules/AbstractRegexRule.php @@ -10,4 +10,3 @@ public function validateClean($input) return preg_match($this->getPregFormat(), $input); } } - diff --git a/library/Rules/AbstractRelated.php b/library/Rules/AbstractRelated.php index 862d222ed..0eb776d3d 100644 --- a/library/Rules/AbstractRelated.php +++ b/library/Rules/AbstractRelated.php @@ -14,8 +14,7 @@ abstract public function hasReference($input); abstract public function getReferenceValue($input); - public function __construct($reference, Validatable $validator=null, - $mandatory=true) + public function __construct($reference, Validatable $validator = null, $mandatory = true) { $this->setName($reference); $this->reference = $reference; @@ -23,7 +22,8 @@ public function __construct($reference, Validatable $validator=null, $this->mandatory = $mandatory; } - private function decision($type, $hasReference, $input) { + private function decision($type, $hasReference, $input) + { return (!$this->mandatory && !$hasReference) || (is_null($this->validator) || $this->validator->$type($this->getReferenceValue($input))); @@ -31,12 +31,14 @@ private function decision($type, $hasReference, $input) { public function assert($input) { - if ($input === '') + if ($input === '') { return true; + } $hasReference = $this->hasReference($input); - if ($this->mandatory && !$hasReference) + if ($this->mandatory && !$hasReference) { throw $this->reportError($input, array('hasReference' => false)); + } try { return $this->decision('assert', $hasReference, $input); @@ -49,21 +51,25 @@ public function assert($input) public function check($input) { - if ($input === '') + if ($input === '') { return true; + } $hasReference = $this->hasReference($input); - if ($this->mandatory && !$hasReference) + if ($this->mandatory && !$hasReference) { throw $this->reportError($input, array('hasReference' => false)); + } + return $this->decision('check', $hasReference, $input); } public function validate($input) { $hasReference = $this->hasReference($input); - if ($this->mandatory && !$hasReference) + if ($this->mandatory && !$hasReference) { return false; + } + return $this->decision('validate', $hasReference, $input); } } - diff --git a/library/Rules/AbstractRule.php b/library/Rules/AbstractRule.php index 66ecc5af0..da0aa60b2 100644 --- a/library/Rules/AbstractRule.php +++ b/library/Rules/AbstractRule.php @@ -32,8 +32,9 @@ public function addOr() public function assert($input) { - if ($this->__invoke($input)) + if ($this->__invoke($input)) { return true; + } throw $this->reportError($input); } @@ -44,23 +45,29 @@ public function check($input) public function getName() { - if (empty($this->name)) + if (empty($this->name)) { preg_replace('/.*\\\/', '', get_class($this)); + } + return $this->name; } - public function reportError($input, array $extraParams=array()) + public function reportError($input, array $extraParams = array()) { $exception = $this->createException(); $input = ValidationException::stringify($input); $name = $this->name ?: "\"$input\""; $params = array_merge( - get_class_vars(__CLASS__), get_object_vars($this), $extraParams, + get_class_vars(__CLASS__), + get_object_vars($this), + $extraParams, compact('input') ); $exception->configure($name, $params); - if (!is_null($this->template)) + if (!is_null($this->template)) { $exception->setTemplate($this->template); + } + return $exception; } @@ -84,7 +91,6 @@ protected function createException() $exceptionFQN = str_replace('\\Rules\\', '\\Exceptions\\', $currentFQN); $exceptionFQN .= 'Exception'; - return new $exceptionFQN; + return new $exceptionFQN(); } } - diff --git a/library/Rules/AllOf.php b/library/Rules/AllOf.php index cd4b490b6..97a68ecec 100644 --- a/library/Rules/AllOf.php +++ b/library/Rules/AllOf.php @@ -11,7 +11,7 @@ public function assert($input) $summary = array( 'total' => $numRules, 'failed' => $numExceptions, - 'passed' => $numRules - $numExceptions + 'passed' => $numRules - $numExceptions, ); if (!empty($exceptions)) { throw $this->reportError($input, $summary)->setRelated($exceptions); @@ -42,4 +42,3 @@ public function validate($input) return true; } } - diff --git a/library/Rules/Alnum.php b/library/Rules/Alnum.php index 56a3be76d..15e997429 100644 --- a/library/Rules/Alnum.php +++ b/library/Rules/Alnum.php @@ -13,4 +13,3 @@ protected function ctypeFunction($input) return ctype_alnum($input); } } - diff --git a/library/Rules/Alpha.php b/library/Rules/Alpha.php index 87aabf281..c14e23bad 100644 --- a/library/Rules/Alpha.php +++ b/library/Rules/Alpha.php @@ -13,4 +13,3 @@ protected function ctypeFunction($input) return ctype_alpha($input); } } - diff --git a/library/Rules/AlwaysInvalid.php b/library/Rules/AlwaysInvalid.php index d133b20a3..bae7888d6 100644 --- a/library/Rules/AlwaysInvalid.php +++ b/library/Rules/AlwaysInvalid.php @@ -8,4 +8,3 @@ public function validate($input) return false; } } - diff --git a/library/Rules/AlwaysValid.php b/library/Rules/AlwaysValid.php index 48277963d..963e05627 100644 --- a/library/Rules/AlwaysValid.php +++ b/library/Rules/AlwaysValid.php @@ -8,4 +8,3 @@ public function validate($input) return true; } } - diff --git a/library/Rules/Arr.php b/library/Rules/Arr.php index 0414f9375..97804658a 100644 --- a/library/Rules/Arr.php +++ b/library/Rules/Arr.php @@ -14,4 +14,3 @@ public function validate($input) && $input instanceof Countable); } } - diff --git a/library/Rules/Attribute.php b/library/Rules/Attribute.php index 3d45e9c9e..c165d1196 100644 --- a/library/Rules/Attribute.php +++ b/library/Rules/Attribute.php @@ -7,7 +7,7 @@ class Attribute extends AbstractRelated { - public function __construct($reference, Validatable $validator=null, $mandatory=true) + public function __construct($reference, Validatable $validator = null, $mandatory = true) { if (!is_string($reference) || empty($reference)) { throw new ComponentException('Invalid attribute/property name'); @@ -29,4 +29,3 @@ public function hasReference($input) return is_object($input) && property_exists($input, $this->reference); } } - diff --git a/library/Rules/Base.php b/library/Rules/Base.php index 96c05a83f..4426ef74b 100644 --- a/library/Rules/Base.php +++ b/library/Rules/Base.php @@ -8,7 +8,7 @@ class Base extends AbstractRule public $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; public $base; - public function __construct($base=null, $chars=null) + public function __construct($base = null, $chars = null) { if (!is_null($chars)) { $this->chars = $chars; @@ -28,4 +28,3 @@ public function validate($input) return (boolean) preg_match("@^[$valid]+$@", (string) $input); } } - diff --git a/library/Rules/Between.php b/library/Rules/Between.php index dc2f0332b..b2e06314e 100644 --- a/library/Rules/Between.php +++ b/library/Rules/Between.php @@ -8,7 +8,7 @@ class Between extends AllOf public $minValue; public $maxValue; - public function __construct($min=null, $max=null, $inclusive=false) + public function __construct($min = null, $max = null, $inclusive = false) { $this->minValue = $min; $this->maxValue = $max; @@ -25,4 +25,3 @@ public function __construct($min=null, $max=null, $inclusive=false) } } } - diff --git a/library/Rules/Bool.php b/library/Rules/Bool.php index 0eaf6b921..9dcec0490 100644 --- a/library/Rules/Bool.php +++ b/library/Rules/Bool.php @@ -8,4 +8,3 @@ public function validate($input) return is_bool($input); } } - diff --git a/library/Rules/Call.php b/library/Rules/Call.php index 43bc1a024..25955dbe5 100644 --- a/library/Rules/Call.php +++ b/library/Rules/Call.php @@ -13,4 +13,3 @@ public function hasReference($input) return is_callable($this->reference); } } - diff --git a/library/Rules/Callback.php b/library/Rules/Callback.php index d72c21821..490c6f512 100644 --- a/library/Rules/Callback.php +++ b/library/Rules/Callback.php @@ -29,4 +29,3 @@ public function validate($input) return (bool) call_user_func_array($this->callback, $params); } } - diff --git a/library/Rules/Charset.php b/library/Rules/Charset.php index 16674727f..bfaf01f82 100644 --- a/library/Rules/Charset.php +++ b/library/Rules/Charset.php @@ -30,4 +30,3 @@ public function validate($input) return in_array($detectedEncoding, $this->charset, true); } } - diff --git a/library/Rules/Cnh.php b/library/Rules/Cnh.php index 4b4abc3cc..bf7a5bd75 100644 --- a/library/Rules/Cnh.php +++ b/library/Rules/Cnh.php @@ -7,15 +7,14 @@ public function validate($input) { $ret = false; - if ((strlen($input = preg_replace('/[^\d]/', '', $input)) == 11 ) + if ((strlen($input = preg_replace('/[^\d]/', '', $input)) == 11) && (str_repeat($input[1], 11) != $input)) { - $dsc = 0; - for ($i = 0 , $j = 9, $v = 0; $i < 9; ++$i, --$j) { + for ($i = 0, $j = 9, $v = 0; $i < 9; ++$i, --$j) { $v += (int) $input[$i] * $j; } - if (($vl1 = $v % 11) >= 10 ) { + if (($vl1 = $v % 11) >= 10) { $vl1 = 0; $dsc = 2; } @@ -31,4 +30,3 @@ public function validate($input) return $ret; } } - diff --git a/library/Rules/Cnpj.php b/library/Rules/Cnpj.php index e6769e68c..1e10aecfe 100644 --- a/library/Rules/Cnpj.php +++ b/library/Rules/Cnpj.php @@ -28,4 +28,3 @@ public function validate($input) return true; } } - diff --git a/library/Rules/Cntrl.php b/library/Rules/Cntrl.php index 1d62f914a..be67eaeaa 100644 --- a/library/Rules/Cntrl.php +++ b/library/Rules/Cntrl.php @@ -8,4 +8,3 @@ protected function ctypeFunction($input) return ctype_cntrl($input); } } - diff --git a/library/Rules/Consonant.php b/library/Rules/Consonant.php index a8d7f2bd0..13e4e0254 100644 --- a/library/Rules/Consonant.php +++ b/library/Rules/Consonant.php @@ -8,4 +8,3 @@ protected function getPregFormat() return '/^(\s|[b-df-hj-np-tv-zB-DF-HJ-NP-TV-Z])*$/'; } } - diff --git a/library/Rules/Consonants.php b/library/Rules/Consonants.php index 87e23198b..1a8d9700f 100644 --- a/library/Rules/Consonants.php +++ b/library/Rules/Consonants.php @@ -6,7 +6,6 @@ class Consonants extends Consonant public function __construct() { parent::__construct(); - trigger_error("Use consonant instead.", - E_USER_DEPRECATED); + trigger_error("Use consonant instead.", E_USER_DEPRECATED); } } diff --git a/library/Rules/Contains.php b/library/Rules/Contains.php index 5afc625d4..071c51f9c 100644 --- a/library/Rules/Contains.php +++ b/library/Rules/Contains.php @@ -6,7 +6,7 @@ class Contains extends AbstractRule public $containsValue; public $identical; - public function __construct($containsValue, $identical=false) + public function __construct($containsValue, $identical = false) { $this->containsValue = $containsValue; $this->identical = $identical; @@ -39,4 +39,3 @@ protected function validateIdentical($input) return false !== mb_strpos($input, $this->containsValue, 0, mb_detect_encoding($input)); } } - diff --git a/library/Rules/CountryCode.php b/library/Rules/CountryCode.php index 41d178b5d..c9abaa411 100644 --- a/library/Rules/CountryCode.php +++ b/library/Rules/CountryCode.php @@ -21,7 +21,7 @@ class CountryCode extends AbstractRule 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'SS', 'ST', 'SV', 'SX', 'SY', 'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', - 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'ZA', 'ZM', 'ZW' + 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'ZA', 'ZM', 'ZW', ); public function validate($input) @@ -29,4 +29,3 @@ public function validate($input) return in_array(strtoupper($input), $this->countryCodeList); } } - diff --git a/library/Rules/Cpf.php b/library/Rules/Cpf.php index afd90c46b..4f85ec911 100644 --- a/library/Rules/Cpf.php +++ b/library/Rules/Cpf.php @@ -8,19 +8,22 @@ public function validate($input) // Code ported from jsfromhell.com $c = preg_replace('/\D/', '', $input); - if (strlen($c) != 11 || preg_match("/^{$c[0]}{11}$/", $c)) + if (strlen($c) != 11 || preg_match("/^{$c[0]}{11}$/", $c)) { return false; + } for ($s = 10, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--); - if ($c[9] != ((($n %= 11) < 2) ? 0 : 11 - $n)) + if ($c[9] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { return false; + } for ($s = 11, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--); - if ($c[10] != ((($n %= 11) < 2) ? 0 : 11 - $n)) + if ($c[10] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { return false; + } + return true; } } - diff --git a/library/Rules/CreditCard.php b/library/Rules/CreditCard.php index dfedaf572..66b518bdf 100644 --- a/library/Rules/CreditCard.php +++ b/library/Rules/CreditCard.php @@ -33,4 +33,3 @@ private function verifyMod10($input) return ($sum % 10 == 0); } } - diff --git a/library/Rules/Date.php b/library/Rules/Date.php index 58c2f7b85..609199186 100644 --- a/library/Rules/Date.php +++ b/library/Rules/Date.php @@ -7,7 +7,7 @@ class Date extends AbstractRule { public $format = null; - public function __construct($format=null) + public function __construct($format = null) { $this->format = $format; } @@ -27,7 +27,7 @@ public function validate($input) 'r' => 'D, d M Y H:i:s O', ); - if ( in_array($this->format, array_keys($exceptionalFormats)) ) { + if (in_array($this->format, array_keys($exceptionalFormats))) { $this->format = $exceptionalFormats[ $this->format ]; } @@ -37,4 +37,3 @@ public function validate($input) && $input === date($this->format, $dateFromFormat->getTimestamp()); } } - diff --git a/library/Rules/Digit.php b/library/Rules/Digit.php index a6d3065d8..ec0671140 100644 --- a/library/Rules/Digit.php +++ b/library/Rules/Digit.php @@ -13,4 +13,3 @@ protected function ctypeFunction($input) return ctype_digit($input); } } - diff --git a/library/Rules/Digits.php b/library/Rules/Digits.php index 265a8798d..aca820478 100644 --- a/library/Rules/Digits.php +++ b/library/Rules/Digits.php @@ -6,7 +6,6 @@ class Digits extends Digit public function __construct() { parent::__construct(); - trigger_error("Use digit instead.", - E_USER_DEPRECATED); + trigger_error("Use digit instead.", E_USER_DEPRECATED); } } diff --git a/library/Rules/Directory.php b/library/Rules/Directory.php index 96c381e26..2c5e8f012 100644 --- a/library/Rules/Directory.php +++ b/library/Rules/Directory.php @@ -12,4 +12,3 @@ public function validate($input) return (is_string($input) && is_dir($input)); } } - diff --git a/library/Rules/Domain.php b/library/Rules/Domain.php index 8f2025a60..ea146cde0 100644 --- a/library/Rules/Domain.php +++ b/library/Rules/Domain.php @@ -9,33 +9,41 @@ class Domain extends AbstractComposite protected $checks = array(); protected $otherParts; - public function __construct($tldCheck=true) + public function __construct($tldCheck = true) { $this->checks[] = new NoWhitespace(); $this->checks[] = new Contains('.'); $this->checks[] = new Length(3, null); - $this->TldCheck($tldCheck); + $this->tldCheck($tldCheck); $this->otherParts = new AllOf( new Alnum('-'), new Not(new StartsWith('-')), - new OneOf(new Not(new Contains('--')), - new AllOf(new StartsWith('xn--'), - new Callback(function ($str) { - return substr_count($str, "--") == 1; - }))) + new OneOf( + new Not( + new Contains('--') + ), + new AllOf( + new StartsWith('xn--'), + new Callback(function ($str) { + return substr_count($str, "--") == 1; + }) + ) + ) ); } - public function tldCheck($do=true) + public function tldCheck($do = true) { - if($do === true) { + if ($do === true) { $this->tld = new Tld(); } else { $this->tld = new AllOf( - new Not(new StartsWith('-')), - new NoWhitespace(), - new Length(2, null) - ); + new Not( + new StartsWith('-') + ), + new NoWhitespace(), + new Length(2, null) + ); } return true; @@ -43,37 +51,44 @@ public function tldCheck($do=true) public function validate($input) { - - foreach ($this->checks as $chk) - if (!$chk->validate($input)) + foreach ($this->checks as $chk) { + if (!$chk->validate($input)) { return false; + } + } if (count($parts = explode('.', $input)) < 2 - || !$this->tld->validate(array_pop($parts))) + || !$this->tld->validate(array_pop($parts))) { return false; + } - foreach ($parts as $p) - if (!$this->otherParts->validate($p)) + foreach ($parts as $p) { + if (!$this->otherParts->validate($p)) { return false; + } + } return true; } public function assert($input) { - $e = array(); - foreach ($this->checks as $chk) + foreach ($this->checks as $chk) { $this->collectAssertException($e, $chk, $input); + } - if (count($parts = explode('.', $input)) >= 2) + if (count($parts = explode('.', $input)) >= 2) { $this->collectAssertException($e, $this->tld, array_pop($parts)); + } - foreach ($parts as $p) + foreach ($parts as $p) { $this->collectAssertException($e, $this->otherParts, $p); + } - if (count($e)) + if (count($e)) { throw $this->reportError($input)->setRelated($e); + } return true; } @@ -89,17 +104,18 @@ protected function collectAssertException(&$exceptions, $validator, $input) public function check($input) { - - foreach ($this->checks as $chk) + foreach ($this->checks as $chk) { $chk->check($input); + } - if (count($parts = explode('.', $input)) >= 2) + if (count($parts = explode('.', $input)) >= 2) { $this->tld->check(array_pop($parts)); + } - foreach ($parts as $p) + foreach ($parts as $p) { $this->otherParts->check($p); + } return true; } } - diff --git a/library/Rules/Each.php b/library/Rules/Each.php index edcc6af12..95a09223f 100644 --- a/library/Rules/Each.php +++ b/library/Rules/Each.php @@ -10,8 +10,7 @@ class Each extends AbstractRule public $itemValidator; public $keyValidator; - public function __construct(Validatable $itemValidator = null, - Validatable $keyValidator=null) + public function __construct(Validatable $itemValidator = null, Validatable $keyValidator = null) { $this->itemValidator = $itemValidator; $this->keyValidator = $keyValidator; @@ -100,4 +99,3 @@ public function validate($input) return true; } } - diff --git a/library/Rules/Email.php b/library/Rules/Email.php index 1d6bb3f47..eae907164 100644 --- a/library/Rules/Email.php +++ b/library/Rules/Email.php @@ -8,4 +8,3 @@ public function validate($input) return is_string($input) && filter_var($input, FILTER_VALIDATE_EMAIL); } } - diff --git a/library/Rules/EndsWith.php b/library/Rules/EndsWith.php index 13e791b91..75c6ed2ae 100644 --- a/library/Rules/EndsWith.php +++ b/library/Rules/EndsWith.php @@ -6,7 +6,7 @@ class EndsWith extends AbstractRule public $endValue; public $identical; - public function __construct($endValue, $identical=false) + public function __construct($endValue, $identical = false) { $this->endValue = $endValue; $this->identical = $identical; @@ -27,7 +27,7 @@ protected function validateEquals($input) return end($input) == $this->endValue; } else { return mb_strripos($input, $this->endValue, -1, $enc = mb_detect_encoding($input)) - === mb_strlen($input, $enc) - mb_strlen($this->endValue, $enc) ; + === mb_strlen($input, $enc) - mb_strlen($this->endValue, $enc); } } @@ -41,4 +41,3 @@ protected function validateIdentical($input) } } } - diff --git a/library/Rules/Equals.php b/library/Rules/Equals.php index 1f856b655..2d3d84b5e 100644 --- a/library/Rules/Equals.php +++ b/library/Rules/Equals.php @@ -6,13 +6,13 @@ class Equals extends AbstractRule public $compareIdentical = false; public $compareTo = null; - public function __construct($compareTo, $compareIdentical=false) + public function __construct($compareTo, $compareIdentical = false) { $this->compareTo = $compareTo; $this->compareIdentical = $compareIdentical; } - public function reportError($input, array $extraParams=array()) + public function reportError($input, array $extraParams = array()) { return parent::reportError($input, $extraParams); } @@ -26,4 +26,3 @@ public function validate($input) } } } - diff --git a/library/Rules/Even.php b/library/Rules/Even.php index 065afde93..49cfc7365 100644 --- a/library/Rules/Even.php +++ b/library/Rules/Even.php @@ -5,7 +5,6 @@ class Even extends AbstractRule { public function validate($input) { - return ( (int) $input % 2 === 0); + return ((int) $input % 2 === 0); } } - diff --git a/library/Rules/Exists.php b/library/Rules/Exists.php index 245b4d4b7..cf628b135 100644 --- a/library/Rules/Exists.php +++ b/library/Rules/Exists.php @@ -4,7 +4,6 @@ class Exists extends AbstractRule { - public function validate($input) { if ($input instanceof \SplFileInfo) { @@ -13,6 +12,4 @@ public function validate($input) return (is_string($input) && file_exists($input)); } - } - diff --git a/library/Rules/File.php b/library/Rules/File.php index 256d768d3..868c303fb 100644 --- a/library/Rules/File.php +++ b/library/Rules/File.php @@ -4,7 +4,6 @@ class File extends AbstractRule { - public function validate($input) { if ($input instanceof \SplFileInfo) { @@ -13,6 +12,4 @@ public function validate($input) return (is_string($input) && is_file($input)); } - } - diff --git a/library/Rules/Float.php b/library/Rules/Float.php index 74721846b..d207b904b 100644 --- a/library/Rules/Float.php +++ b/library/Rules/Float.php @@ -8,4 +8,3 @@ public function validate($input) return is_float(filter_var($input, FILTER_VALIDATE_FLOAT)); } } - diff --git a/library/Rules/Graph.php b/library/Rules/Graph.php index a23263b6a..a97b8700d 100644 --- a/library/Rules/Graph.php +++ b/library/Rules/Graph.php @@ -8,4 +8,3 @@ protected function ctypeFunction($input) return ctype_graph($input); } } - diff --git a/library/Rules/HexRgbColor.php b/library/Rules/HexRgbColor.php index e9c247ab4..7bd4fdfd7 100644 --- a/library/Rules/HexRgbColor.php +++ b/library/Rules/HexRgbColor.php @@ -7,24 +7,23 @@ class HexRgbColor extends AbstractRule { public function validate($input) { - if(v::oneOf(v::object(), v::arr(), v::nullValue(), v::not(v::string()))->validate($input)){ + if (v::oneOf(v::object(), v::arr(), v::nullValue(), v::not(v::string()))->validate($input)) { return false; } - - if(!v::startsWith('#')->validate($input)){ - $input = '#' . $input; + + if (!v::startsWith('#')->validate($input)) { + $input = '#'.$input; } - + $length = strlen($input) - 1; - - if($length != 3 && $length != 6){ + + if ($length != 3 && $length != 6) { return false; } - + $hexdec = hexdec(substr($input, 1)); - + return v::xdigit()->validate(substr($input, 1)) && $hexdec < 16777216 && $hexdec >= 0; } } - diff --git a/library/Rules/Hexa.php b/library/Rules/Hexa.php index 624363a38..f9fc2df40 100644 --- a/library/Rules/Hexa.php +++ b/library/Rules/Hexa.php @@ -6,8 +6,7 @@ class Hexa extends AbstractRule public function __construct() { parent::__construct(); - trigger_error("Use xdigits instead.", - E_USER_DEPRECATED); + trigger_error("Use xdigits instead.", E_USER_DEPRECATED); } public function validate($input) @@ -15,4 +14,3 @@ public function validate($input) return ctype_xdigit($input); } } - diff --git a/library/Rules/In.php b/library/Rules/In.php index afb47634f..2ddc6874d 100644 --- a/library/Rules/In.php +++ b/library/Rules/In.php @@ -6,13 +6,13 @@ class In extends AbstractRule public $haystack; public $compareIdentical; - public function __construct($haystack, $compareIdentical=false) + public function __construct($haystack, $compareIdentical = false) { $this->haystack = $haystack; $this->compareIdentical = $compareIdentical; } - public function reportError($input, array $extraParams=array()) + public function reportError($input, array $extraParams = array()) { return parent::reportError($input, $extraParams); } @@ -36,4 +36,3 @@ public function validate($input) return mb_stripos($this->haystack, $input, 0, $enc) !== false; } } - diff --git a/library/Rules/Instance.php b/library/Rules/Instance.php index 38f9c9dff..fb3229c17 100644 --- a/library/Rules/Instance.php +++ b/library/Rules/Instance.php @@ -10,7 +10,7 @@ public function __construct($instanceName) $this->instanceName = $instanceName; } - public function reportError($input, array $extraParams=array()) + public function reportError($input, array $extraParams = array()) { return parent::reportError($input, $extraParams); } @@ -20,4 +20,3 @@ public function validate($input) return $input instanceof $this->instanceName; } } - diff --git a/library/Rules/Int.php b/library/Rules/Int.php index c565ae7d8..68321887d 100644 --- a/library/Rules/Int.php +++ b/library/Rules/Int.php @@ -8,4 +8,3 @@ public function validate($input) return is_numeric($input) && (int) $input == $input; } } - diff --git a/library/Rules/Ip.php b/library/Rules/Ip.php index 59f632eaa..1883a6681 100644 --- a/library/Rules/Ip.php +++ b/library/Rules/Ip.php @@ -9,12 +9,12 @@ class Ip extends AbstractRule public $networkRange; - public function __construct($ipOptions=null) + public function __construct($ipOptions = null) { if (is_int($ipOptions)) { $this->ipOptions = $ipOptions; - return ; + return; } $this->networkRange = $this->parseRange($ipOptions); @@ -24,7 +24,7 @@ protected function parseRange($input) { if ($input === null || $input == '*' || $input == '*.*.*.*' || $input == '0.0.0.0-255.255.255.255') { - return null; + return; } $range = array('min' => null, 'max' => null, 'mask' => null); @@ -53,7 +53,7 @@ protected function parseRange($input) protected function fillAddress(&$input, $char = '*') { while (substr_count($input, '.') < 3) { - $input .= '.' . $char; + $input .= '.'.$char; } } @@ -76,7 +76,7 @@ protected function parseRangeUsingCidr($input, &$range) if ($isAddressMask && $this->verifyAddress($input[1])) { $range['mask'] = sprintf('%032b', ip2long($input[1])); - return ; + return; } if ($isAddressMask || $input[1] < 8 || $input[1] > 30) { @@ -97,7 +97,7 @@ protected function verifyAddress($address) $address, FILTER_VALIDATE_IP, array( - 'flags' => $this->ipOptions + 'flags' => $this->ipOptions, ) ); } @@ -127,4 +127,3 @@ protected function belongsToSubnet($input) return ($input & $range['mask']) === ($min & $range['mask']); } } - diff --git a/library/Rules/Json.php b/library/Rules/Json.php index 308c53d67..bdd704a7f 100644 --- a/library/Rules/Json.php +++ b/library/Rules/Json.php @@ -8,4 +8,3 @@ public function validate($input) return (bool) (json_decode($input)); } } - diff --git a/library/Rules/Key.php b/library/Rules/Key.php index af8f3c5f3..247901ef8 100644 --- a/library/Rules/Key.php +++ b/library/Rules/Key.php @@ -6,7 +6,7 @@ class Key extends AbstractRelated { - public function __construct($reference, Validatable $referenceValidator=null, $mandatory=true) + public function __construct($reference, Validatable $referenceValidator = null, $mandatory = true) { if (!is_string($reference) || empty($reference)) { throw new ComponentException('Invalid array key name'); @@ -24,4 +24,3 @@ public function hasReference($input) return is_array($input) && array_key_exists($this->reference, $input); } } - diff --git a/library/Rules/LeapDate.php b/library/Rules/LeapDate.php index 50eafbb24..f0f6fcf20 100644 --- a/library/Rules/LeapDate.php +++ b/library/Rules/LeapDate.php @@ -26,4 +26,3 @@ public function validate($input) return $date->format('m-d') == '02-29'; } } - diff --git a/library/Rules/LeapYear.php b/library/Rules/LeapYear.php index 4780ebbd1..6d6fd15e1 100644 --- a/library/Rules/LeapYear.php +++ b/library/Rules/LeapYear.php @@ -22,4 +22,3 @@ public function validate($year) return (bool) date('L', $date); } } - diff --git a/library/Rules/Length.php b/library/Rules/Length.php index 32d2daf09..9227e46ee 100644 --- a/library/Rules/Length.php +++ b/library/Rules/Length.php @@ -3,7 +3,6 @@ use Countable; use Respect\Validation\Exceptions\ComponentException; -use Respect\Validation\Rules\AbstractRule; class Length extends AbstractRule { @@ -11,12 +10,12 @@ class Length extends AbstractRule public $maxValue; public $inclusive; - public function __construct($min=null, $max=null, $inclusive=true) + public function __construct($min = null, $max = null, $inclusive = true) { $this->minValue = $min; $this->maxValue = $max; $this->inclusive = $inclusive; - $paramValidator = new OneOf(new Numeric, new NullValue); + $paramValidator = new OneOf(new Numeric(), new NullValue()); if (!$paramValidator->validate($min)) { throw new ComponentException( sprintf('%s is not a valid numeric length', $min) @@ -82,4 +81,3 @@ protected function validateMax($length) return $length < $this->maxValue; } } - diff --git a/library/Rules/Lowercase.php b/library/Rules/Lowercase.php index 10b110836..8f48ad644 100644 --- a/library/Rules/Lowercase.php +++ b/library/Rules/Lowercase.php @@ -8,4 +8,3 @@ public function validate($input) return $input === mb_strtolower($input, mb_detect_encoding($input)); } } - diff --git a/library/Rules/MacAddress.php b/library/Rules/MacAddress.php index 0553b28f0..4491faf0f 100644 --- a/library/Rules/MacAddress.php +++ b/library/Rules/MacAddress.php @@ -8,4 +8,3 @@ public function validate($input) return !empty($input) && preg_match('/^(([0-9a-fA-F]{2}-){5}|([0-9a-fA-F]{2}:){5})[0-9a-fA-F]{2}$/', $input); } } - diff --git a/library/Rules/Max.php b/library/Rules/Max.php index 12d3c6339..338887cd9 100644 --- a/library/Rules/Max.php +++ b/library/Rules/Max.php @@ -6,7 +6,7 @@ class Max extends AbstractRule public $maxValue; public $inclusive; - public function __construct($maxValue, $inclusive=false) + public function __construct($maxValue, $inclusive = false) { $this->maxValue = $maxValue; $this->inclusive = $inclusive; @@ -21,4 +21,3 @@ public function validate($input) } } } - diff --git a/library/Rules/Min.php b/library/Rules/Min.php index 7b68f7e36..414e81ad4 100644 --- a/library/Rules/Min.php +++ b/library/Rules/Min.php @@ -6,7 +6,7 @@ class Min extends AbstractRule public $inclusive; public $minValue; - public function __construct($minValue, $inclusive=false) + public function __construct($minValue, $inclusive = false) { $this->minValue = $minValue; $this->inclusive = $inclusive; @@ -21,4 +21,3 @@ public function validate($input) } } } - diff --git a/library/Rules/MinimumAge.php b/library/Rules/MinimumAge.php index 7ba830526..65cde574e 100644 --- a/library/Rules/MinimumAge.php +++ b/library/Rules/MinimumAge.php @@ -8,7 +8,7 @@ class MinimumAge extends AbstractRule public $age = null; public $format = null; - public function __construct($age, $format=null) + public function __construct($age, $format = null) { $this->age = $age; $this->format = $format; @@ -33,4 +33,3 @@ public function validate($input) } } } - diff --git a/library/Rules/Multiple.php b/library/Rules/Multiple.php index 2111a9469..33fbf214f 100644 --- a/library/Rules/Multiple.php +++ b/library/Rules/Multiple.php @@ -19,4 +19,3 @@ public function validate($input) return ($input % $this->multipleOf == 0); } } - diff --git a/library/Rules/Negative.php b/library/Rules/Negative.php index 3cdd48fbf..f4650bea2 100644 --- a/library/Rules/Negative.php +++ b/library/Rules/Negative.php @@ -8,4 +8,3 @@ public function validate($input) return $input < 0; } } - diff --git a/library/Rules/NfeAccessKey.php b/library/Rules/NfeAccessKey.php index e18a5caf4..9656b0c17 100644 --- a/library/Rules/NfeAccessKey.php +++ b/library/Rules/NfeAccessKey.php @@ -10,10 +10,9 @@ */ class NfeAccessKey extends AbstractRule { - /** * @see Manual de Integração do Contribuinte v4.0.1 (http://www.nfe.fazenda.gov.br) - * @param string $aK access key + * @param string $aK access key * @return boolean */ public function validate($aK) @@ -21,7 +20,7 @@ public function validate($aK) if (strlen($aK) !== 44) { return false; } - + $w = array(); for ($i = 0, $z = 5, $m = 43; $i <= $m; $i++) { $z = ($i < $m) ? ($z - 1) == 1 ? 9 : ($z - 1) : 0; @@ -29,7 +28,8 @@ public function validate($aK) } for ($i = 0, $s = 0, $k = 44; $i < $k; ++$i) { - $s += $aK{ $i } * $w[ $i ]; + $s += $aK{ $i } + * $w[ $i ]; } $s -= (11 * floor($s / 11)); @@ -37,6 +37,4 @@ public function validate($aK) return $v == $aK{ 43 }; } - } - diff --git a/library/Rules/NoWhitespace.php b/library/Rules/NoWhitespace.php index f8e2bd272..81cd2fe2e 100644 --- a/library/Rules/NoWhitespace.php +++ b/library/Rules/NoWhitespace.php @@ -8,4 +8,3 @@ public function validate($input) return is_null($input) || !preg_match('#\s#', $input); } } - diff --git a/library/Rules/NoneOf.php b/library/Rules/NoneOf.php index 2f7c98775..e9167c0c7 100644 --- a/library/Rules/NoneOf.php +++ b/library/Rules/NoneOf.php @@ -21,9 +21,8 @@ public function validate($input) if ($rule->validate($input)) { return false; } - } + return true; } } - diff --git a/library/Rules/Not.php b/library/Rules/Not.php index 48b323b0b..3d546049c 100644 --- a/library/Rules/Not.php +++ b/library/Rules/Not.php @@ -60,4 +60,3 @@ protected function absorbComposite(AbstractComposite $rule) return $clone; } } - diff --git a/library/Rules/NotEmpty.php b/library/Rules/NotEmpty.php index a9cc3af79..f4f55ac75 100644 --- a/library/Rules/NotEmpty.php +++ b/library/Rules/NotEmpty.php @@ -12,4 +12,3 @@ public function validate($input) return !empty($input); } } - diff --git a/library/Rules/NullValue.php b/library/Rules/NullValue.php index 2fbf15819..a92e07147 100644 --- a/library/Rules/NullValue.php +++ b/library/Rules/NullValue.php @@ -8,4 +8,3 @@ public function validate($input) return is_null($input); } } - diff --git a/library/Rules/Numeric.php b/library/Rules/Numeric.php index 65b67841a..aaf823e5a 100644 --- a/library/Rules/Numeric.php +++ b/library/Rules/Numeric.php @@ -8,4 +8,3 @@ public function validate($input) return is_numeric($input); } } - diff --git a/library/Rules/Object.php b/library/Rules/Object.php index 73e7e5c8c..d57a84c8c 100644 --- a/library/Rules/Object.php +++ b/library/Rules/Object.php @@ -8,4 +8,3 @@ public function validate($input) return is_object($input); } } - diff --git a/library/Rules/Odd.php b/library/Rules/Odd.php index e8cfdc544..1026e7029 100644 --- a/library/Rules/Odd.php +++ b/library/Rules/Odd.php @@ -8,4 +8,3 @@ public function validate($input) return ((int) $input % 2 !== 0); } } - diff --git a/library/Rules/OneOf.php b/library/Rules/OneOf.php index e7bc88fe3..8009cb730 100644 --- a/library/Rules/OneOf.php +++ b/library/Rules/OneOf.php @@ -11,7 +11,6 @@ public function assert($input) $exceptions = $this->validateRules($input); $numRules = count($validators); $numExceptions = count($exceptions); - $numPassed = $numRules - $numExceptions; if ($numExceptions === $numRules) { throw $this->reportError($input)->setRelated($exceptions); } @@ -51,4 +50,3 @@ public function check($input) return false; } } - diff --git a/library/Rules/PerfectSquare.php b/library/Rules/PerfectSquare.php index eb6601676..c053cb958 100644 --- a/library/Rules/PerfectSquare.php +++ b/library/Rules/PerfectSquare.php @@ -8,4 +8,3 @@ public function validate($input) return is_numeric($input) && sqrt($input) * sqrt($input) == $input; } } - diff --git a/library/Rules/Phone.php b/library/Rules/Phone.php index 0f7215e1f..14229cabc 100644 --- a/library/Rules/Phone.php +++ b/library/Rules/Phone.php @@ -7,4 +7,4 @@ public function validate($input) { return !empty($input) && preg_match('/^[+]?([\d]{0,3})?[\(\.\-\s]?(([\d]{1,3})[\)\.\-\s]*)?(([\d]{3,5})[\.\-\s]?([\d]{4})|([\d]{2}[\.\-\s]?){4})$/', $input); } -} \ No newline at end of file +} diff --git a/library/Rules/Positive.php b/library/Rules/Positive.php index ec75192e0..179dd0053 100644 --- a/library/Rules/Positive.php +++ b/library/Rules/Positive.php @@ -8,4 +8,3 @@ public function validate($input) return $input > 0; } } - diff --git a/library/Rules/PrimeNumber.php b/library/Rules/PrimeNumber.php index 47c15d587..d6ecc7e6b 100644 --- a/library/Rules/PrimeNumber.php +++ b/library/Rules/PrimeNumber.php @@ -8,7 +8,7 @@ public function validate($input) if (is_numeric($input) && $input > 0) { $cont = 0; - for ($i=1; $i<=$input; $i++) { + for ($i = 1; $i <= $input; $i++) { if (($input % $i) == 0) { $cont = $cont + 1; } @@ -19,7 +19,6 @@ public function validate($input) } else { $input = 0; } - } else { $input = 0; } @@ -27,4 +26,3 @@ public function validate($input) return (boolean) $input; } } - diff --git a/library/Rules/Prnt.php b/library/Rules/Prnt.php index 503b128ea..8a83f55de 100644 --- a/library/Rules/Prnt.php +++ b/library/Rules/Prnt.php @@ -8,4 +8,3 @@ protected function ctypeFunction($input) return ctype_print($input); } } - diff --git a/library/Rules/Punct.php b/library/Rules/Punct.php index c2c8dfe9d..a0ff7d7df 100644 --- a/library/Rules/Punct.php +++ b/library/Rules/Punct.php @@ -8,4 +8,3 @@ protected function ctypeFunction($input) return ctype_punct($input); } } - diff --git a/library/Rules/Readable.php b/library/Rules/Readable.php index cb55b72ab..a9b5ca437 100644 --- a/library/Rules/Readable.php +++ b/library/Rules/Readable.php @@ -4,7 +4,6 @@ class Readable extends AbstractRule { - public function validate($input) { if ($input instanceof \SplFileInfo) { @@ -13,6 +12,4 @@ public function validate($input) return (is_string($input) && is_readable($input)); } - } - diff --git a/library/Rules/Regex.php b/library/Rules/Regex.php index 9739aa1c3..ade463168 100644 --- a/library/Rules/Regex.php +++ b/library/Rules/Regex.php @@ -15,4 +15,3 @@ public function validate($input) return (bool) preg_match($this->regex, $input); } } - diff --git a/library/Rules/Roman.php b/library/Rules/Roman.php index 6a1477838..4d4953e4e 100644 --- a/library/Rules/Roman.php +++ b/library/Rules/Roman.php @@ -8,4 +8,3 @@ public function validate($input) return (boolean) preg_match('/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/', $input); } } - diff --git a/library/Rules/Sf.php b/library/Rules/Sf.php index 407563edf..f3ca67e67 100644 --- a/library/Rules/Sf.php +++ b/library/Rules/Sf.php @@ -6,7 +6,6 @@ use Respect\Validation\Exceptions\ComponentException; use Symfony\Component\Validator\Validation; use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\ConstraintViolation; class Sf extends AbstractRule { @@ -14,13 +13,13 @@ class Sf extends AbstractRule public $name; private $constraint; - public function __construct($name, $params=array()) + public function __construct($name, $params = array()) { $this->name = ucfirst($name); $this->constraint = $this->createSymfonyConstraint($this->name, $params); } - private function createSymfonyConstraint($constraintName, $constraintConstructorParameters=array()) + private function createSymfonyConstraint($constraintName, $constraintConstructorParameters = array()) { $fullClassName = sprintf(self::SYMFONY_CONSTRAINT_NAMESPACE, $constraintName); try { @@ -63,4 +62,3 @@ public function validate($input) return true; } } - diff --git a/library/Rules/Slug.php b/library/Rules/Slug.php index 7a7d9e00c..29102000f 100644 --- a/library/Rules/Slug.php +++ b/library/Rules/Slug.php @@ -20,4 +20,3 @@ public function validate($input) return true; } } - diff --git a/library/Rules/Space.php b/library/Rules/Space.php index bae3c857e..4a8de18ed 100644 --- a/library/Rules/Space.php +++ b/library/Rules/Space.php @@ -8,4 +8,3 @@ protected function ctypeFunction($input) return ctype_space($input); } } - diff --git a/library/Rules/StartsWith.php b/library/Rules/StartsWith.php index 726671660..fd24ed5eb 100644 --- a/library/Rules/StartsWith.php +++ b/library/Rules/StartsWith.php @@ -6,7 +6,7 @@ class StartsWith extends AbstractRule public $startValue; public $identical; - public function __construct($startValue, $identical=false) + public function __construct($startValue, $identical = false) { $this->startValue = $startValue; $this->identical = $identical; @@ -39,4 +39,3 @@ protected function validateIdentical($input) return 0 === mb_strpos($input, $this->startValue, 0, mb_detect_encoding($input)); } } - diff --git a/library/Rules/String.php b/library/Rules/String.php index 242e6f444..3e2e2a668 100644 --- a/library/Rules/String.php +++ b/library/Rules/String.php @@ -8,4 +8,3 @@ public function validate($input) return is_string($input); } } - diff --git a/library/Rules/SymbolicLink.php b/library/Rules/SymbolicLink.php index 8ffc543e0..2152fee6b 100644 --- a/library/Rules/SymbolicLink.php +++ b/library/Rules/SymbolicLink.php @@ -4,7 +4,6 @@ class SymbolicLink extends AbstractRule { - public function validate($input) { if ($input instanceof \SplFileInfo) { @@ -13,6 +12,4 @@ public function validate($input) return (is_string($input) && is_link($input)); } - } - diff --git a/library/Rules/Tld.php b/library/Rules/Tld.php index b78a61618..93f13f836 100644 --- a/library/Rules/Tld.php +++ b/library/Rules/Tld.php @@ -29,7 +29,7 @@ class Tld extends AbstractRule 'sr', 'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tf', 'tg', 'th', 'tj', 'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'uk', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', - 'wf', 'ws', 'ye', 'yt', 'za', 'zm', 'zw' + 'wf', 'ws', 'ye', 'yt', 'za', 'zm', 'zw', ); public function validate($input) @@ -37,4 +37,3 @@ public function validate($input) return in_array(strtolower($input), $this->tldList); } } - diff --git a/library/Rules/Uploaded.php b/library/Rules/Uploaded.php index a54db8edc..4bb926c05 100644 --- a/library/Rules/Uploaded.php +++ b/library/Rules/Uploaded.php @@ -4,7 +4,6 @@ class Uploaded extends AbstractRule { - public function validate($input) { if ($input instanceof \SplFileInfo) { @@ -13,6 +12,4 @@ public function validate($input) return (is_string($input) && is_uploaded_file($input)); } - } - diff --git a/library/Rules/Uppercase.php b/library/Rules/Uppercase.php index 4b6da999b..e86343f9b 100644 --- a/library/Rules/Uppercase.php +++ b/library/Rules/Uppercase.php @@ -8,4 +8,3 @@ public function validate($input) return $input === mb_strtoupper($input, mb_detect_encoding($input)); } } - diff --git a/library/Rules/Version.php b/library/Rules/Version.php index 91bace6b2..7288e6b2c 100644 --- a/library/Rules/Version.php +++ b/library/Rules/Version.php @@ -13,4 +13,3 @@ public function validate($input) return (bool) preg_match($pattern, $input); } } - diff --git a/library/Rules/Vowel.php b/library/Rules/Vowel.php index 4755dae26..d8910a7ea 100644 --- a/library/Rules/Vowel.php +++ b/library/Rules/Vowel.php @@ -8,4 +8,3 @@ protected function getPregFormat() return '/^(\s|[aeiouAEIOU])*$/'; } } - diff --git a/library/Rules/Vowels.php b/library/Rules/Vowels.php index 1936ca444..a92b71fcd 100644 --- a/library/Rules/Vowels.php +++ b/library/Rules/Vowels.php @@ -6,7 +6,6 @@ class Vowels extends Vowel public function __construct() { parent::__construct(); - trigger_error("Use consonant instead.", - E_USER_DEPRECATED); + trigger_error("Use vowel instead.", E_USER_DEPRECATED); } } diff --git a/library/Rules/When.php b/library/Rules/When.php index ecfc8f349..8eda07364 100644 --- a/library/Rules/When.php +++ b/library/Rules/When.php @@ -43,4 +43,3 @@ public function check($input) } } } - diff --git a/library/Rules/Writable.php b/library/Rules/Writable.php index a50772133..070668802 100644 --- a/library/Rules/Writable.php +++ b/library/Rules/Writable.php @@ -4,7 +4,6 @@ class Writable extends AbstractRule { - public function validate($input) { if ($input instanceof \SplFileInfo) { @@ -13,6 +12,4 @@ public function validate($input) return (is_string($input) && is_writable($input)); } - } - diff --git a/library/Rules/Xdigit.php b/library/Rules/Xdigit.php index 21366fabc..795577455 100644 --- a/library/Rules/Xdigit.php +++ b/library/Rules/Xdigit.php @@ -8,4 +8,3 @@ public function ctypeFunction($input) return ctype_xdigit($input); } } - diff --git a/library/Rules/Zend.php b/library/Rules/Zend.php index ce31abb99..625c1b09f 100644 --- a/library/Rules/Zend.php +++ b/library/Rules/Zend.php @@ -9,7 +9,7 @@ class Zend extends AbstractRule protected $messages = array(); protected $zendValidator; - public function __construct($validator, $params=array()) + public function __construct($validator, $params = array()) { if (is_object($validator)) { return $this->zendValidator = $validator; @@ -57,4 +57,3 @@ public function validate($input) return $validator->isValid($input); } } - diff --git a/library/Validatable.php b/library/Validatable.php index ea08dfe12..d231ed974 100644 --- a/library/Validatable.php +++ b/library/Validatable.php @@ -10,7 +10,7 @@ public function check($input); public function getName(); - public function reportError($input, array $relatedExceptions=array()); + public function reportError($input, array $relatedExceptions = array()); public function setName($name); @@ -18,4 +18,3 @@ public function setTemplate($template); public function validate($input); } - diff --git a/library/Validator.php b/library/Validator.php index 1aa42f654..44eb2e1d2 100644 --- a/library/Validator.php +++ b/library/Validator.php @@ -8,120 +8,129 @@ use Respect\Validation\Rules\AllOf; /** - * @method static \Respect\Validation\Validator allOf() - * @method static \Respect\Validation\Validator alnum(string $additionalChars = null) - * @method static \Respect\Validation\Validator alpha(string $additionalChars = null) - * @method static \Respect\Validation\Validator alwaysInvalid() - * @method static \Respect\Validation\Validator alwaysValid() - * @method static \Respect\Validation\Validator arr() - * @method static \Respect\Validation\Validator attribute(string $reference, Validatable $validator = null, bool $mandatory = true) - * @method static \Respect\Validation\Validator base() - * @method static \Respect\Validation\Validator between(int $min = null, int $max = null, bool $inclusive = false) - * @method static \Respect\Validation\Validator bool() - * @method static \Respect\Validation\Validator call() - * @method static \Respect\Validation\Validator callback(mixed $callback) - * @method static \Respect\Validation\Validator charset(array $charset) - * @method static \Respect\Validation\Validator cnh() - * @method static \Respect\Validation\Validator cnpj() - * @method static \Respect\Validation\Validator consonant(string $additionalChars = null) - * @method static \Respect\Validation\Validator contains(mixed $containsValue, bool $identical = false) - * @method static \Respect\Validation\Validator countryCode() - * @method static \Respect\Validation\Validator cpf() - * @method static \Respect\Validation\Validator creditCard() - * @method static \Respect\Validation\Validator date(string $format = null) - * @method static \Respect\Validation\Validator digit(string $additionalChars = null) - * @method static \Respect\Validation\Validator directory() - * @method static \Respect\Validation\Validator domain() - * @method static \Respect\Validation\Validator each(Validatable $itemValidator = null, Validatable $keyValidator = null) - * @method static \Respect\Validation\Validator email() - * @method static \Respect\Validation\Validator endsWith(mixed $endValue, bool $identical = false) - * @method static \Respect\Validation\Validator equals(mixed $compareTo, bool $compareIdentical=false) - * @method static \Respect\Validation\Validator even() - * @method static \Respect\Validation\Validator executable() - * @method static \Respect\Validation\Validator exists() - * @method static \Respect\Validation\Validator file() - * @method static \Respect\Validation\Validator float() - * @method static \Respect\Validation\Validator graph(string $additionalChars = null) - * @method static \Respect\Validation\Validator hexRgbColor() - * @method static \Respect\Validation\Validator in(array $haystack, bool $compareIdentical = false) - * @method static \Respect\Validation\Validator instance(string $instanceName) - * @method static \Respect\Validation\Validator int() - * @method static \Respect\Validation\Validator ip(array $ipOptions = null) - * @method static \Respect\Validation\Validator json() - * @method static \Respect\Validation\Validator key(string $reference, Validatable $referenceValidator = null, bool $mandatory = true) - * @method static \Respect\Validation\Validator leapDate(mixed $format) - * @method static \Respect\Validation\Validator leapYear() - * @method static \Respect\Validation\Validator length(int $min=null, int $max=null, bool $inclusive = true) - * @method static \Respect\Validation\Validator lowercase() - * @method static \Respect\Validation\Validator macAddress() - * @method static \Respect\Validation\Validator max(int $maxValue, bool $inclusive = false) - * @method static \Respect\Validation\Validator min(int $minValue, bool $inclusive = false) - * @method static \Respect\Validation\Validator minimumAge(int $age) - * @method static \Respect\Validation\Validator multiple(int $multipleOf) - * @method static \Respect\Validation\Validator negative() - * @method static \Respect\Validation\Validator no($useLocale = false) - * @method static \Respect\Validation\Validator noneOf() - * @method static \Respect\Validation\Validator not(Validatable $rule) - * @method static \Respect\Validation\Validator notEmpty() - * @method static \Respect\Validation\Validator noWhitespace() - * @method static \Respect\Validation\Validator nullValue() - * @method static \Respect\Validation\Validator numeric() - * @method static \Respect\Validation\Validator object() - * @method static \Respect\Validation\Validator odd() - * @method static \Respect\Validation\Validator oneOf() - * @method static \Respect\Validation\Validator perfectSquare() - * @method static \Respect\Validation\Validator phone() - * @method static \Respect\Validation\Validator positive() - * @method static \Respect\Validation\Validator postalCode($countryCode) - * @method static \Respect\Validation\Validator primeNumber() - * @method static \Respect\Validation\Validator prnt(string $additionalChars = null) - * @method static \Respect\Validation\Validator punct(string $additionalChars = null) - * @method static \Respect\Validation\Validator readable() - * @method static \Respect\Validation\Validator regex($regex) - * @method static \Respect\Validation\Validator roman() - * @method static \Respect\Validation\Validator sf(string $name, array $params = null) - * @method static \Respect\Validation\Validator slug() - * @method static \Respect\Validation\Validator space(string $additionalChars = null) - * @method static \Respect\Validation\Validator startsWith(mixed $startValue, bool $identical = false) - * @method static \Respect\Validation\Validator string() - * @method static \Respect\Validation\Validator symbolicLink() - * @method static \Respect\Validation\Validator tld() - * @method static \Respect\Validation\Validator uploaded() - * @method static \Respect\Validation\Validator uppercase() - * @method static \Respect\Validation\Validator version() - * @method static \Respect\Validation\Validator vowel() - * @method static \Respect\Validation\Validator when(Validatable $if, Validatable $then, Validatable $when) - * @method static \Respect\Validation\Validator writable() - * @method static \Respect\Validation\Validator xdigit(string $additionalChars = null) - * @method static \Respect\Validation\Validator yes($useLocale = false) - * @method static \Respect\Validation\Validator zend(mixed $validator, array $params = null) + * @method static Validator allOf() + * @method static Validator alnum(string $additionalChars = null) + * @method static Validator alpha(string $additionalChars = null) + * @method static Validator alwaysInvalid() + * @method static Validator alwaysValid() + * @method static Validator arr() + * @method static Validator attribute(string $reference, Validatable $validator = null, bool $mandatory = true) + * @method static Validator base() + * @method static Validator between(int $min = null, int $max = null, bool $inclusive = false) + * @method static Validator bool() + * @method static Validator call() + * @method static Validator callback(mixed $callback) + * @method static Validator charset(array $charset) + * @method static Validator cnh() + * @method static Validator cnpj() + * @method static Validator consonant(string $additionalChars = null) + * @method static Validator contains(mixed $containsValue, bool $identical = false) + * @method static Validator countryCode() + * @method static Validator cpf() + * @method static Validator creditCard() + * @method static Validator date(string $format = null) + * @method static Validator digit(string $additionalChars = null) + * @method static Validator directory() + * @method static Validator domain() + * @method static Validator each(Validatable $itemValidator = null, Validatable $keyValidator = null) + * @method static Validator email() + * @method static Validator endsWith(mixed $endValue, bool $identical = false) + * @method static Validator equals(mixed $compareTo, bool $compareIdentical=false) + * @method static Validator even() + * @method static Validator executable() + * @method static Validator exists() + * @method static Validator file() + * @method static Validator float() + * @method static Validator graph(string $additionalChars = null) + * @method static Validator hexRgbColor() + * @method static Validator in(array $haystack, bool $compareIdentical = false) + * @method static Validator instance(string $instanceName) + * @method static Validator int() + * @method static Validator ip(array $ipOptions = null) + * @method static Validator json() + * @method static Validator key(string $reference, Validatable $referenceValidator = null, bool $mandatory = true) + * @method static Validator leapDate(mixed $format) + * @method static Validator leapYear() + * @method static Validator length(int $min=null, int $max=null, bool $inclusive = true) + * @method static Validator lowercase() + * @method static Validator macAddress() + * @method static Validator max(int $maxValue, bool $inclusive = false) + * @method static Validator min(int $minValue, bool $inclusive = false) + * @method static Validator minimumAge(int $age) + * @method static Validator multiple(int $multipleOf) + * @method static Validator negative() + * @method static Validator no($useLocale = false) + * @method static Validator noneOf() + * @method static Validator not(Validatable $rule) + * @method static Validator notEmpty() + * @method static Validator noWhitespace() + * @method static Validator nullValue() + * @method static Validator numeric() + * @method static Validator object() + * @method static Validator odd() + * @method static Validator oneOf() + * @method static Validator perfectSquare() + * @method static Validator phone() + * @method static Validator positive() + * @method static Validator postalCode($countryCode) + * @method static Validator primeNumber() + * @method static Validator prnt(string $additionalChars = null) + * @method static Validator punct(string $additionalChars = null) + * @method static Validator readable() + * @method static Validator regex($regex) + * @method static Validator roman() + * @method static Validator sf(string $name, array $params = null) + * @method static Validator slug() + * @method static Validator space(string $additionalChars = null) + * @method static Validator startsWith(mixed $startValue, bool $identical = false) + * @method static Validator string() + * @method static Validator symbolicLink() + * @method static Validator tld() + * @method static Validator uploaded() + * @method static Validator uppercase() + * @method static Validator version() + * @method static Validator vowel() + * @method static Validator when(Validatable $if, Validatable $then, Validatable $when) + * @method static Validator writable() + * @method static Validator xdigit(string $additionalChars = null) + * @method static Validator yes($useLocale = false) + * @method static Validator zend(mixed $validator, array $params = null) */ class Validator extends AllOf { - + /** + * @param string $ruleName + * @param array $arguments + * + * @return Validator + */ public static function __callStatic($ruleName, $arguments) { if ('allOf' === $ruleName) { return static::buildRule($ruleName, $arguments); } - $validator = new static; + $validator = new static(); return $validator->__call($ruleName, $arguments); } - public static function buildRule($ruleSpec, $arguments=array()) + /** + * @param mixed $ruleSpec + * @param array $arguments + * + * @return Validatable + */ + public static function buildRule($ruleSpec, $arguments = array()) { if ($ruleSpec instanceof Validatable) { return $ruleSpec; } try { - $validatorFqn = 'Respect\\Validation\\Rules\\' . ucfirst($ruleSpec); + $validatorFqn = 'Respect\\Validation\\Rules\\'.ucfirst($ruleSpec); $validatorClass = new ReflectionClass($validatorFqn); - $validatorInstance = $validatorClass->newInstanceArgs( - $arguments - ); + $validatorInstance = $validatorClass->newInstanceArgs($arguments); return $validatorInstance; } catch (ReflectionException $e) { @@ -129,6 +138,12 @@ public static function buildRule($ruleSpec, $arguments=array()) } } + /** + * @param string $method + * @param array $arguments + * + * @return self + */ public function __call($method, $arguments) { if ('not' === $method) { @@ -143,13 +158,22 @@ public function __call($method, $arguments) return $this->addRule(static::buildRule($method, $arguments)); } - public function reportError($input, array $extraParams=array()) + + /** + * @param mixed $input + * @param array $extraParams + * + * @return AllOfException + */ + public function reportError($input, array $extraParams = array()) { - $exception = new AllOfException; + $exception = new AllOfException(); $input = AllOfException::stringify($input); - $name = $this->getName() ? : "\"$input\""; + $name = $this->getName() ?: "\"$input\""; $params = array_merge( - $extraParams, get_object_vars($this), get_class_vars(__CLASS__) + $extraParams, + get_object_vars($this), + get_class_vars(__CLASS__) ); $exception->configure($name, $params); if (!is_null($this->template)) { @@ -162,8 +186,7 @@ public function reportError($input, array $extraParams=array()) /** * Create instance validator * - * @static - * @return \Respect\Validation\Validator + * @return Validator */ public static function create() { @@ -172,4 +195,3 @@ public static function create() return $ref->newInstanceArgs(func_get_args()); } } -