mirror of
https://github.com/Respect/Validation.git
synced 2024-06-04 14:52:17 +02:00
Update PHP-CS-Fixer settings
This commit is contained in:
parent
f2bb77bb8e
commit
4d72af312f
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
.php_cs.cache
|
||||
.couscous/
|
||||
composer.lock
|
||||
Makefile
|
||||
|
|
28
.php_cs
28
.php_cs
|
@ -8,26 +8,16 @@ $finder = Symfony\CS\Finder\DefaultFinder::create()
|
|||
->in('tests');
|
||||
|
||||
return Symfony\CS\Config\Config::create()
|
||||
->level(\Symfony\CS\FixerInterface::PSR2_LEVEL)
|
||||
->level(\Symfony\CS\FixerInterface::SYMFONY_LEVEL)
|
||||
->fixers(array(
|
||||
// All items of the @param, @throws, @return, @var, and @type phpdoc
|
||||
// tags must be aligned vertically.
|
||||
'phpdoc_params',
|
||||
// Convert double quotes to single quotes for simple strings.
|
||||
'single_quote',
|
||||
// Group and seperate @phpdocs with empty lines.
|
||||
'phpdoc_separation',
|
||||
// An empty line feed should precede a return statement.
|
||||
'return',
|
||||
// PHP arrays should use the PHP 5.4 short-syntax.
|
||||
'short_array_syntax',
|
||||
// Remove trailing whitespace at the end of blank lines.
|
||||
'whitespacy_lines',
|
||||
// Removes extra empty lines.
|
||||
'extra_empty_lines',
|
||||
// Unused use statements must be removed.
|
||||
'unused_use',
|
||||
// Ordering use statements.
|
||||
'empty_return',
|
||||
'multiline_spaces_before_semicolon',
|
||||
'newline_after_open_tag',
|
||||
'no_useless_else',
|
||||
'no_useless_return',
|
||||
'ordered_use',
|
||||
'phpdoc_order',
|
||||
'short_array_syntax',
|
||||
))
|
||||
->setUsingCache(true)
|
||||
->finder($finder);
|
||||
|
|
|
@ -36,8 +36,8 @@ class BetweenException extends NestedValidationException
|
|||
return static::GREATER;
|
||||
} elseif (!$this->getParam('maxValue')) {
|
||||
return static::LOWER;
|
||||
} else {
|
||||
return static::BOTH;
|
||||
}
|
||||
|
||||
return static::BOTH;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,8 @@ class IpException extends ValidationException
|
|||
{
|
||||
if (!$this->getParam('networkRange')) {
|
||||
return static::STANDARD;
|
||||
} else {
|
||||
return static::NETWORK_RANGE;
|
||||
}
|
||||
|
||||
return static::NETWORK_RANGE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@ class LanguageCodeException extends ValidationException
|
|||
],
|
||||
self::MODE_NEGATIVE => [
|
||||
self::STANDARD => '{{name}} must not be a valid language',
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
@ -36,8 +36,8 @@ class LengthException extends ValidationException
|
|||
return static::GREATER;
|
||||
} elseif (!$this->getParam('maxValue')) {
|
||||
return static::LOWER;
|
||||
} else {
|
||||
return static::BOTH;
|
||||
}
|
||||
|
||||
return static::BOTH;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param string $path
|
||||
* @param ValidationException $exception
|
||||
*
|
||||
* @return ValidationException
|
||||
|
@ -248,7 +248,7 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
*/
|
||||
private function isRelated($name, ValidationException $exception)
|
||||
{
|
||||
return ($exception->getId() === $name || $exception->getName() === $name);
|
||||
return $exception->getId() === $name || $exception->getName() === $name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,7 +34,7 @@ class RecursiveExceptionIterator implements RecursiveIterator, Countable
|
|||
return false;
|
||||
}
|
||||
|
||||
return ($this->current() instanceof NestedValidationException);
|
||||
return $this->current() instanceof NestedValidationException;
|
||||
}
|
||||
|
||||
public function getChildren()
|
||||
|
|
|
@ -106,7 +106,7 @@ class ValidationException extends InvalidArgumentException implements ExceptionI
|
|||
}
|
||||
}
|
||||
|
||||
return (@json_encode($value, (JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)) ?: $value);
|
||||
return @json_encode($value, (JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)) ?: $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -243,9 +243,9 @@ class ValidationException extends InvalidArgumentException implements ExceptionI
|
|||
{
|
||||
if (!empty($this->template)) {
|
||||
return $this->template;
|
||||
} else {
|
||||
return $this->template = $this->buildTemplate();
|
||||
}
|
||||
|
||||
return $this->template = $this->buildTemplate();
|
||||
}
|
||||
|
||||
public function hasParam($name)
|
||||
|
@ -299,7 +299,7 @@ class ValidationException extends InvalidArgumentException implements ExceptionI
|
|||
|
||||
public function hasCustomTemplate()
|
||||
{
|
||||
return (true === $this->customTemplate);
|
||||
return true === $this->customTemplate;
|
||||
}
|
||||
|
||||
public function setTemplate($template)
|
||||
|
|
|
@ -23,10 +23,10 @@ abstract class AbstractSearcher extends AbstractRule
|
|||
}
|
||||
|
||||
if ($input === null || $input === '') {
|
||||
return ($input == $this->haystack);
|
||||
return $input == $this->haystack;
|
||||
}
|
||||
|
||||
return (false !== mb_stripos($this->haystack, $input, 0, mb_detect_encoding($input)));
|
||||
return false !== mb_stripos($this->haystack, $input, 0, mb_detect_encoding($input));
|
||||
}
|
||||
|
||||
protected function validateIdentical($input)
|
||||
|
@ -36,10 +36,10 @@ abstract class AbstractSearcher extends AbstractRule
|
|||
}
|
||||
|
||||
if ($input === null || $input === '') {
|
||||
return ($input === $this->haystack);
|
||||
return $input === $this->haystack;
|
||||
}
|
||||
|
||||
return (false !== mb_strpos($this->haystack, $input, 0, mb_detect_encoding($input)));
|
||||
return false !== mb_strpos($this->haystack, $input, 0, mb_detect_encoding($input));
|
||||
}
|
||||
|
||||
public function validate($input)
|
||||
|
|
|
@ -20,7 +20,7 @@ class Bank extends AbstractWrapper
|
|||
*
|
||||
* The country code is not case sensitive.
|
||||
*
|
||||
* @param string $countryCode The ISO 639-1 country code.
|
||||
* @param string $countryCode The ISO 639-1 country code
|
||||
* @param Factory $factory
|
||||
*/
|
||||
public function __construct($countryCode, Factory $factory = null)
|
||||
|
|
|
@ -20,8 +20,8 @@ class BankAccount extends AbstractWrapper
|
|||
*
|
||||
* The country code is not case sensitive.
|
||||
*
|
||||
* @param string $countryCode The ISO 639-1 country code.
|
||||
* @param string $bank The bank.
|
||||
* @param string $countryCode The ISO 639-1 country code
|
||||
* @param string $bank The bank
|
||||
* @param Factory $factory
|
||||
*/
|
||||
public function __construct($countryCode, $bank, Factory $factory = null)
|
||||
|
|
|
@ -35,6 +35,6 @@ class Base extends AbstractRule
|
|||
{
|
||||
$valid = substr($this->chars, 0, $this->base);
|
||||
|
||||
return (boolean) preg_match("@^[$valid]+$@", (string) $input);
|
||||
return (bool) preg_match("@^[$valid]+$@", (string) $input);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class Bic extends AbstractWrapper
|
|||
*
|
||||
* The country code is not case sensitive.
|
||||
*
|
||||
* @param string $countryCode The ISO 639-1 country code.
|
||||
* @param string $countryCode The ISO 639-1 country code
|
||||
* @param Factory $factory
|
||||
*/
|
||||
public function __construct($countryCode, Factory $factory = null)
|
||||
|
|
|
@ -40,7 +40,7 @@ class CreditCard extends AbstractRule
|
|||
];
|
||||
|
||||
/**
|
||||
* @param string $brand Optional credit card brand.
|
||||
* @param string $brand Optional credit card brand
|
||||
*/
|
||||
public function __construct($brand = null)
|
||||
{
|
||||
|
|
|
@ -51,6 +51,6 @@ class Date extends AbstractRule
|
|||
|
||||
$info = date_parse_from_format($this->format, $inputString);
|
||||
|
||||
return ($info['error_count'] === 0 && $info['warning_count'] === 0);
|
||||
return $info['error_count'] === 0 && $info['warning_count'] === 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@ class Directory extends AbstractRule
|
|||
return $input->isDir();
|
||||
}
|
||||
|
||||
return (is_string($input) && is_dir($input));
|
||||
return is_string($input) && is_dir($input);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,6 @@ class Even extends AbstractRule
|
|||
{
|
||||
public function validate($input)
|
||||
{
|
||||
return ((int) $input % 2 === 0);
|
||||
return (int) $input % 2 === 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@ class Executable extends AbstractRule
|
|||
return $input->isExecutable();
|
||||
}
|
||||
|
||||
return (is_string($input) && is_executable($input));
|
||||
return is_string($input) && is_executable($input);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@ class Exists extends AbstractRule
|
|||
$input = $input->getPathname();
|
||||
}
|
||||
|
||||
return (is_string($input) && file_exists($input));
|
||||
return is_string($input) && file_exists($input);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,13 +39,13 @@ class Extension extends AbstractRule
|
|||
public function validate($input)
|
||||
{
|
||||
if ($input instanceof SplFileInfo) {
|
||||
return ($input->getExtension() == $this->extension);
|
||||
return $input->getExtension() == $this->extension;
|
||||
}
|
||||
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (pathinfo($input, PATHINFO_EXTENSION) == $this->extension);
|
||||
return pathinfo($input, PATHINFO_EXTENSION) == $this->extension;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@ class FalseVal extends AbstractRule
|
|||
return true;
|
||||
}
|
||||
|
||||
return (false === filter_var($input, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
|
||||
return false === filter_var($input, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@ class File extends AbstractRule
|
|||
return $input->isFile();
|
||||
}
|
||||
|
||||
return (is_string($input) && is_file($input));
|
||||
return is_string($input) && is_file($input);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,6 @@ class Image extends AbstractRule
|
|||
return false;
|
||||
}
|
||||
|
||||
return (0 === strpos($this->fileInfo->file($input), 'image/'));
|
||||
return 0 === strpos($this->fileInfo->file($input), 'image/');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,6 @@ class Imei extends AbstractRule
|
|||
$sum += ($number % 10) + intval($number / 10);
|
||||
}
|
||||
|
||||
return ((ceil($sum / 10) * 10) - $sum == $numbers[14]);
|
||||
return (ceil($sum / 10) * 10) - $sum == $numbers[14];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ class Ip extends AbstractRule
|
|||
|
||||
protected function verifyAddress($address)
|
||||
{
|
||||
return (boolean) filter_var(
|
||||
return (bool) filter_var(
|
||||
$address,
|
||||
FILTER_VALIDATE_IP,
|
||||
[
|
||||
|
|
|
@ -21,6 +21,6 @@ class Json extends AbstractRule
|
|||
|
||||
json_decode($input);
|
||||
|
||||
return (json_last_error() === JSON_ERROR_NONE);
|
||||
return json_last_error() === JSON_ERROR_NONE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ class KeySet extends AllOf
|
|||
unset($input[$keyRule->reference]);
|
||||
}
|
||||
|
||||
return (count($input) == 0);
|
||||
return count($input) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -66,7 +66,7 @@ class Length extends AbstractRule
|
|||
}
|
||||
|
||||
if (is_int($input)) {
|
||||
return strlen((string)$input);
|
||||
return strlen((string) $input);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -58,6 +58,6 @@ class Mimetype extends AbstractRule
|
|||
return false;
|
||||
}
|
||||
|
||||
return ($this->fileInfo->file($input) == $this->mimetype);
|
||||
return $this->fileInfo->file($input) == $this->mimetype;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ class Multiple extends AbstractRule
|
|||
public function validate($input)
|
||||
{
|
||||
if ($this->multipleOf == 0) {
|
||||
return ($input == 0);
|
||||
return $input == 0;
|
||||
}
|
||||
|
||||
return ($input % $this->multipleOf == 0);
|
||||
return $input % $this->multipleOf == 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class NfeAccessKey extends AbstractRule
|
|||
|
||||
$w = [];
|
||||
for ($i = 0, $z = 5, $m = 43; $i <= $m; ++$i) {
|
||||
$z = ($i < $m) ? ($z - 1) == 1 ? 9 : ($z - 1) : 0;
|
||||
$z = ($i < $m) ? ($z - 1) == 1 ? 9 : ($z - 1) : 0;
|
||||
$w[] = $z;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class Not extends AbstractRule
|
|||
|
||||
public function validate($input)
|
||||
{
|
||||
return (false == $this->rule->validate($input));
|
||||
return false == $this->rule->validate($input);
|
||||
}
|
||||
|
||||
public function assert($input)
|
||||
|
|
|
@ -15,6 +15,6 @@ class NotOptional extends AbstractRule
|
|||
{
|
||||
public function validate($input)
|
||||
{
|
||||
return (false === in_array($input, [null, ''], true));
|
||||
return false === in_array($input, [null, ''], true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,6 @@ class Odd extends AbstractRule
|
|||
{
|
||||
public function validate($input)
|
||||
{
|
||||
return ((int) $input % 2 !== 0);
|
||||
return (int) $input % 2 !== 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class Pesel extends AbstractRule
|
|||
$targetControlNumber = $input[10];
|
||||
$calculateControlNumber = 0;
|
||||
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
for ($i = 0; $i < 10; ++$i) {
|
||||
$calculateControlNumber += $input[$i] * $weights[$i];
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class PrimeNumber extends AbstractRule
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($input != 2 && ($input % 2) == 0) {
|
||||
if ($input != 2 && ($input % 2) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,6 @@ class Readable extends AbstractRule
|
|||
return $input->isReadable();
|
||||
}
|
||||
|
||||
return (is_string($input) && is_readable($input));
|
||||
return is_string($input) && is_readable($input);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,14 +87,14 @@ class Size extends AbstractRule
|
|||
private function isValidSize($size)
|
||||
{
|
||||
if (null !== $this->minValue && null !== $this->maxValue) {
|
||||
return ($size >= $this->minValue && $size <= $this->maxValue);
|
||||
return $size >= $this->minValue && $size <= $this->maxValue;
|
||||
}
|
||||
|
||||
if (null !== $this->minValue) {
|
||||
return ($size >= $this->minValue);
|
||||
return $size >= $this->minValue;
|
||||
}
|
||||
|
||||
return ($size <= $this->maxValue);
|
||||
return $size <= $this->maxValue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,6 @@ class SymbolicLink extends AbstractRule
|
|||
return $input->isLink();
|
||||
}
|
||||
|
||||
return (is_string($input) && is_link($input));
|
||||
return is_string($input) && is_link($input);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,8 +38,7 @@ class Tld extends AbstractRule
|
|||
'cooking', 'cool', 'corsica', 'country', 'coupons', 'courses', 'credit',
|
||||
'creditcard', 'cricket', 'crown', 'crs', 'cruises', 'cuisinella', 'cw',
|
||||
'cymru', 'cyou', 'dabur', 'dad', 'dance', 'date', 'dating', 'datsun',
|
||||
'day', 'dclk', 'deals', 'degree', 'delivery', 'democrat', 'dental', 'dentist'
|
||||
, 'desi', 'design', 'dev', 'diamonds', 'diet', 'digital', 'direct', 'directory',
|
||||
'day', 'dclk', 'deals', 'degree', 'delivery', 'democrat', 'dental', 'dentist', 'desi', 'design', 'dev', 'diamonds', 'diet', 'digital', 'direct', 'directory',
|
||||
'discount', 'dnp', 'docs', 'dog', 'doha', 'domains', 'doosan', 'download',
|
||||
'drive', 'durban', 'dvag', 'earth', 'eat', 'education', 'email', 'emerck',
|
||||
'energy', 'engineer', 'engineering', 'enterprises', 'epson', 'equipment',
|
||||
|
|
|
@ -15,6 +15,6 @@ class TrueVal extends AbstractRule
|
|||
{
|
||||
public function validate($input)
|
||||
{
|
||||
return (true === filter_var($input, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
|
||||
return true === filter_var($input, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,6 @@ class Type extends AbstractRule
|
|||
return is_callable($input);
|
||||
}
|
||||
|
||||
return ($this->availableTypes[$lowerType] === gettype($input));
|
||||
return $this->availableTypes[$lowerType] === gettype($input);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@ class Uploaded extends AbstractRule
|
|||
$input = $input->getPathname();
|
||||
}
|
||||
|
||||
return (is_string($input) && is_uploaded_file($input));
|
||||
return is_string($input) && is_uploaded_file($input);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ class VideoUrl extends AbstractRule
|
|||
public function validate($input)
|
||||
{
|
||||
if (isset($this->services[$this->serviceKey])) {
|
||||
return (preg_match($this->services[$this->serviceKey], $input) > 0);
|
||||
return preg_match($this->services[$this->serviceKey], $input) > 0;
|
||||
}
|
||||
|
||||
foreach ($this->services as $pattern) {
|
||||
|
|
|
@ -19,6 +19,6 @@ class Writable extends AbstractRule
|
|||
return $input->isWritable();
|
||||
}
|
||||
|
||||
return (is_string($input) && is_writable($input));
|
||||
return is_string($input) && is_writable($input);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ require 'vendor/autoload.php';
|
|||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
$object = new \stdClass;
|
||||
$object = new \stdClass();
|
||||
$object->email = 'Not an email';
|
||||
$object->password = 'Ale xandre';
|
||||
|
||||
|
@ -19,7 +19,7 @@ try {
|
|||
print_r($exception->getMessages());
|
||||
print_r($exception->findMessages([
|
||||
'email' => 'Error: {{name}}',
|
||||
'noWhitespace' => 'Error: {{name}}'
|
||||
'noWhitespace' => 'Error: {{name}}',
|
||||
]));
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -9,7 +9,7 @@ use Respect\Validation\Validator as v;
|
|||
$input = [
|
||||
'user_name' => 'MyName111',
|
||||
'user_surname' => 'MySurname111',
|
||||
'user_tel' => 'asd123'
|
||||
'user_tel' => 'asd123',
|
||||
];
|
||||
|
||||
$rules = [
|
||||
|
@ -18,7 +18,7 @@ $rules = [
|
|||
v::key('user_tel', v::phone())->setName('Phone number'),
|
||||
];
|
||||
|
||||
try{
|
||||
try {
|
||||
v::allOf($rules)->setName('Validation Form')->assert($input);
|
||||
} catch (NestedValidationException $exception) {
|
||||
print_r($exception->findMessages(array_keys($input)));
|
||||
|
|
|
@ -7,12 +7,12 @@ use Respect\Validation\Exceptions\PhoneException;
|
|||
use Respect\Validation\Validator as v;
|
||||
|
||||
$work = new stdClass();
|
||||
$work->number = "+61.(03) 4546 5498";
|
||||
$work->number = '+61.(03) 4546 5498';
|
||||
$work->countryCode = 61;
|
||||
$work->primary = true;
|
||||
|
||||
$personal = new stdClass();
|
||||
$personal->number = "+61.0406 464 890";
|
||||
$personal->number = '+61.0406 464 890';
|
||||
$personal->country = 61;
|
||||
$personal->primary = false;
|
||||
|
||||
|
@ -31,7 +31,6 @@ try {
|
|||
->keyNested('phoneNumbers.work.number', v::phone(), false)
|
||||
->keyNested('phoneNumbers.work.primary', v::boolType(), false)
|
||||
->check($validateThis);
|
||||
|
||||
} catch (PhoneException $exception) {
|
||||
echo $exception->getMainMessage();
|
||||
}
|
||||
|
|
|
@ -4,7 +4,8 @@ require 'vendor/autoload.php';
|
|||
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
v::callableType()->validate(function () {});
|
||||
v::callableType()->validate(function () {
|
||||
});
|
||||
v::callableType()->validate('trim');
|
||||
v::callableType()->validate(v::callableType(), 'validate');
|
||||
?>
|
||||
|
|
|
@ -12,7 +12,8 @@ use Respect\Validation\Exceptions\CallableTypeException;
|
|||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
$x = function () {};
|
||||
$x = function () {
|
||||
};
|
||||
v::not(v::callableType())->check($x);
|
||||
} catch (CallableTypeException $e) {
|
||||
echo $e->getMainMessage().PHP_EOL;
|
||||
|
|
|
@ -9,25 +9,25 @@ use Respect\Validation\Validator as v;
|
|||
try {
|
||||
v::languageCode('alpha-3')->check('pt');
|
||||
} catch (LanguageCodeException $e) {
|
||||
echo $e->getMainMessage() . PHP_EOL;
|
||||
echo $e->getMainMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::languageCode()->assert('eng');
|
||||
} catch (AllOfException $e) {
|
||||
echo $e->getFullMessage() . PHP_EOL;
|
||||
echo $e->getFullMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::not(v::languageCode())->assert('en');
|
||||
} catch (AllOfException $e) {
|
||||
echo $e->getFullMessage() . PHP_EOL;
|
||||
echo $e->getFullMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::not(v::languageCode())->check('pt');
|
||||
} catch (LanguageCodeException $e) {
|
||||
echo $e->getMainMessage() . PHP_EOL;
|
||||
echo $e->getMainMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -49,31 +49,26 @@ abstract class RuleTestCase extends \PHPUnit_Framework_TestCase
|
|||
$ruleMocked
|
||||
->expects($this->any())
|
||||
->method('validate')
|
||||
->willReturn($expectedResult)
|
||||
;
|
||||
->willReturn($expectedResult);
|
||||
|
||||
if ($expectedResult) {
|
||||
$ruleMocked
|
||||
->expects($this->any())
|
||||
->method('check')
|
||||
->willReturn($expectedResult)
|
||||
;
|
||||
->willReturn($expectedResult);
|
||||
$ruleMocked
|
||||
->expects($this->any())
|
||||
->method('assert')
|
||||
->willReturn($expectedResult)
|
||||
;
|
||||
->willReturn($expectedResult);
|
||||
} else {
|
||||
$ruleMocked
|
||||
->expects($this->any())
|
||||
->method('check')
|
||||
->willThrowException(new ValidationException('Exception for '.$mockClassName.':check() method'))
|
||||
;
|
||||
->willThrowException(new ValidationException('Exception for '.$mockClassName.':check() method'));
|
||||
$ruleMocked
|
||||
->expects($this->any())
|
||||
->method('assert')
|
||||
->willThrowException(new ValidationException('Exception for '.$mockClassName.':assert() method'))
|
||||
;
|
||||
->willThrowException(new ValidationException('Exception for '.$mockClassName.':assert() method'));
|
||||
}
|
||||
|
||||
return $ruleMocked;
|
||||
|
|
|
@ -100,14 +100,14 @@ class ValidationExceptionTest extends \PHPUnit_Framework_TestCase
|
|||
[123.456, '123.456'],
|
||||
[[], '{ }'],
|
||||
[[false], '{ false }'],
|
||||
[[1,2,3,4,5,6,7,8,9,10], '{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }'],
|
||||
[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], '{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }'],
|
||||
[range(1, 80), '{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ... }'],
|
||||
[
|
||||
['foo' => true, 'bar' => ['baz' => 123, 'qux' => [1, 2, 3]]],
|
||||
'{ "foo": true, "bar": { "baz": 123, "qux": { 1, 2, 3 } } }',
|
||||
],
|
||||
[
|
||||
['foo' => true, 'bar' => ['baz' => 123, 'qux' => ['norf' => [1,2,3]]]],
|
||||
['foo' => true, 'bar' => ['baz' => 123, 'qux' => ['norf' => [1, 2, 3]]]],
|
||||
'{ "foo": true, "bar": { "baz": 123, "qux": { "norf": ... } } }',
|
||||
],
|
||||
[[[], 'foo'], '{ { }, "foo" }'],
|
||||
|
|
|
@ -36,9 +36,9 @@ class FactoryTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertSame(
|
||||
$expectedNamespace,
|
||||
array_pop($currentRulePrefixes),
|
||||
'Appended namespace rule was not found as expected into the prefix list.' . PHP_EOL .
|
||||
'Appended namespace rule was not found as expected into the prefix list.'.PHP_EOL.
|
||||
sprintf(
|
||||
'Appended "%s", current list is ' . PHP_EOL . '%s',
|
||||
'Appended "%s", current list is '.PHP_EOL.'%s',
|
||||
$namespace,
|
||||
implode(PHP_EOL, $factory->getRulePrefixes())
|
||||
)
|
||||
|
@ -58,9 +58,9 @@ class FactoryTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertContains(
|
||||
$expectedNamespace,
|
||||
array_shift($currentRulePrefixes),
|
||||
'Prepended namespace rule was not found as expected into the prefix list.' . PHP_EOL .
|
||||
'Prepended namespace rule was not found as expected into the prefix list.'.PHP_EOL.
|
||||
sprintf(
|
||||
'Prepended "%s", current list is ' . PHP_EOL . '%s',
|
||||
'Prepended "%s", current list is '.PHP_EOL.'%s',
|
||||
$namespace,
|
||||
implode(PHP_EOL, $factory->getRulePrefixes())
|
||||
)
|
||||
|
@ -72,12 +72,12 @@ class FactoryTest extends \PHPUnit_Framework_TestCase
|
|||
return [
|
||||
'Namespace with trailing separator' => [
|
||||
'namespace' => 'My\\Validation\\Rules\\',
|
||||
'expected' => 'My\\Validation\\Rules\\'
|
||||
'expected' => 'My\\Validation\\Rules\\',
|
||||
],
|
||||
'Namespace without trailing separator' => [
|
||||
'namespace' => 'My\\Validation\\Rules',
|
||||
'expected' => 'My\\Validation\\Rules\\'
|
||||
]
|
||||
'expected' => 'My\\Validation\\Rules\\',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -218,7 +218,7 @@ class AbstractCompositeTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$compositeRuleMock = $this->getMockForAbstractClass('Respect\\Validation\\Rules\\AbstractComposite', [
|
||||
$simpleRuleMock,
|
||||
$anotherSimpleRuleMock
|
||||
$anotherSimpleRuleMock,
|
||||
]);
|
||||
|
||||
$this->assertCount(2, $compositeRuleMock->getRules());
|
||||
|
|
|
@ -47,14 +47,14 @@ class AllOfTest extends \PHPUnit_Framework_TestCase
|
|||
public function testValidationShouldWorkIfAllRulesReturnTrue()
|
||||
{
|
||||
$valid1 = new Callback(function () {
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
});
|
||||
$valid2 = new Callback(function () {
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
});
|
||||
$valid3 = new Callback(function () {
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
});
|
||||
$o = new AllOf($valid1, $valid2, $valid3);
|
||||
$this->assertTrue($o->__invoke('any'));
|
||||
$this->assertTrue($o->check('any'));
|
||||
|
@ -108,14 +108,14 @@ class AllOfTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerStaticDummyRules()
|
||||
{
|
||||
$theInvalidOne = new Callback(function () {
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$valid1 = new Callback(function () {
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
});
|
||||
$valid2 = new Callback(function () {
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
});
|
||||
|
||||
return [
|
||||
[$theInvalidOne, $valid1, $valid2],
|
||||
|
|
|
@ -44,8 +44,8 @@ class CallTest extends \PHPUnit_Framework_TestCase
|
|||
public function testCallbackValidatorShouldAcceptClosures()
|
||||
{
|
||||
$v = new Call(function () {
|
||||
return [];
|
||||
}, new ArrayVal());
|
||||
return [];
|
||||
}, new ArrayVal());
|
||||
$this->assertTrue($v->assert('test'));
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,8 @@ class CallableTypeTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForCallable()
|
||||
{
|
||||
return [
|
||||
[function () {}],
|
||||
[function () {
|
||||
}],
|
||||
['trim'],
|
||||
[__METHOD__],
|
||||
[[$this, __FUNCTION__]],
|
||||
|
|
|
@ -81,7 +81,7 @@ class ConsonantTest extends \PHPUnit_Framework_TestCase
|
|||
['d'],
|
||||
['w'],
|
||||
['y'],
|
||||
['y',''],
|
||||
['y', ''],
|
||||
['bcdfghklmnp'],
|
||||
['bcdfghklm np'],
|
||||
['qrst'],
|
||||
|
|
|
@ -31,7 +31,7 @@ class EachTest extends RuleTestCase
|
|||
$intStack->push(4);
|
||||
$intStack->push(5);
|
||||
|
||||
$stdClass = new \stdClass;
|
||||
$stdClass = new \stdClass();
|
||||
$stdClass->name = 'Emmerson';
|
||||
$stdClass->age = 22;
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ class ExistsTest extends PHPUnit_Framework_TestCase
|
|||
$file = vfsStream::newFile('2kb.txt')->withContent(LargeFileContent::withKilobytes(2))->at($root);
|
||||
|
||||
return [
|
||||
[$file]
|
||||
[$file],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Respect\Validation\Rules;
|
|||
* @group rule
|
||||
* @covers Respect\Validation\Rules\IterableType
|
||||
*/
|
||||
class IterableTest extends RuleTestCase
|
||||
class IterableTypeTest extends RuleTestCase
|
||||
{
|
||||
public function providerForValidInput()
|
||||
{
|
||||
|
|
|
@ -190,7 +190,7 @@ class KeySetTest extends PHPUnit_Framework_TestCase
|
|||
[''],
|
||||
[null],
|
||||
[0],
|
||||
[new \stdClass()]
|
||||
[new \stdClass()],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,14 +21,14 @@ class NoneOfTest extends \PHPUnit_Framework_TestCase
|
|||
public function testValid()
|
||||
{
|
||||
$valid1 = new Callback(function () {
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$valid2 = new Callback(function () {
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$valid3 = new Callback(function () {
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$o = new NoneOf($valid1, $valid2, $valid3);
|
||||
$this->assertTrue($o->validate('any'));
|
||||
$this->assertTrue($o->assert('any'));
|
||||
|
@ -41,14 +41,14 @@ class NoneOfTest extends \PHPUnit_Framework_TestCase
|
|||
public function testInvalid()
|
||||
{
|
||||
$valid1 = new Callback(function () {
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$valid2 = new Callback(function () {
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$valid3 = new Callback(function () {
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
});
|
||||
$o = new NoneOf($valid1, $valid2, $valid3);
|
||||
$this->assertFalse($o->validate('any'));
|
||||
$this->assertFalse($o->assert('any'));
|
||||
|
|
|
@ -79,7 +79,7 @@ class NotTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
return [
|
||||
[new IntVal()],
|
||||
[new AllOf(new Numeric, new IntVal)],
|
||||
[new AllOf(new Numeric(), new IntVal())],
|
||||
[new Not(new Not(new IntVal()))],
|
||||
[Validator::intVal()->setName('Bar')],
|
||||
[Validator::noneOf(Validator::numeric(), Validator::intVal())],
|
||||
|
|
|
@ -21,14 +21,14 @@ class OneOfTest extends \PHPUnit_Framework_TestCase
|
|||
public function testValid()
|
||||
{
|
||||
$valid1 = new Callback(function () {
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$valid2 = new Callback(function () {
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
});
|
||||
$valid3 = new Callback(function () {
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$o = new OneOf($valid1, $valid2, $valid3);
|
||||
$this->assertTrue($o->validate('any'));
|
||||
$this->assertTrue($o->assert('any'));
|
||||
|
@ -41,14 +41,14 @@ class OneOfTest extends \PHPUnit_Framework_TestCase
|
|||
public function testInvalid()
|
||||
{
|
||||
$valid1 = new Callback(function () {
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$valid2 = new Callback(function () {
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$valid3 = new Callback(function () {
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$o = new OneOf($valid1, $valid2, $valid3);
|
||||
$this->assertFalse($o->validate('any'));
|
||||
$this->assertFalse($o->assert('any'));
|
||||
|
|
|
@ -29,7 +29,7 @@ class PeselTest extends RuleTestCase
|
|||
[$rule, '50083014540'],
|
||||
[$rule, '69090515504'],
|
||||
[$rule, '21120209256'],
|
||||
[$rule, '01320613891']
|
||||
[$rule, '01320613891'],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ class PeselTest extends RuleTestCase
|
|||
[$rule, '690905155.4'],
|
||||
[$rule, '21120209251'],
|
||||
[$rule, '21120209250'],
|
||||
[$rule, '01320613890']
|
||||
[$rule, '01320613890'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,8 @@ class ResourceTypeTest extends \PHPUnit_Framework_TestCase
|
|||
['String'],
|
||||
[123],
|
||||
[[]],
|
||||
[function () {}],
|
||||
[function () {
|
||||
}],
|
||||
[new \stdClass()],
|
||||
[null],
|
||||
];
|
||||
|
|
|
@ -70,7 +70,7 @@ class RomanTest extends \PHPUnit_Framework_TestCase
|
|||
[' '],
|
||||
['IIII'],
|
||||
['IVVVX'],
|
||||
['CCDC'], //
|
||||
['CCDC'],
|
||||
['MXM'],
|
||||
['XIIIIIIII'],
|
||||
['MIMIMI'],
|
||||
|
|
|
@ -66,7 +66,8 @@ class ScalarValTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
return [
|
||||
[[]],
|
||||
[function () {}],
|
||||
[function () {
|
||||
}],
|
||||
[new \stdClass()],
|
||||
[null],
|
||||
[tmpfile()],
|
||||
|
|
|
@ -59,7 +59,7 @@ class SfTest extends \PHPUnit_Framework_TestCase
|
|||
v::sf($constraintName)->assert($invalidConstraintValue);
|
||||
} catch (\Respect\Validation\Exceptions\AllOfException $exception) {
|
||||
$fullValidationMessage = $exception->getFullMessage();
|
||||
$expectedValidationException = <<<EOF
|
||||
$expectedValidationException = <<<'EOF'
|
||||
- Time
|
||||
EOF;
|
||||
|
||||
|
|
|
@ -80,7 +80,8 @@ class TypeTest extends \PHPUnit_Framework_TestCase
|
|||
['array', []],
|
||||
['bool', true],
|
||||
['boolean', false],
|
||||
['callable', function () {}],
|
||||
['callable', function () {
|
||||
}],
|
||||
['double', 0.8],
|
||||
['float', 1.0],
|
||||
['int', 42],
|
||||
|
|
Loading…
Reference in a new issue