Commit graph

554 commits

Author SHA1 Message Date
Henrique Moody 66f5475463
Update PHP support
Due to the current status of the development of the library, it seems
like we will be supporting version 1.1 for a long time. Even when we
release version 2.0 we will still give support for version 1.1 for a
while.

This commit will make sure that version 1.1 is fully supported for PHP
7.2 and 7.3. Also, it will remove the support for HHVM since it will not
keep the compatibility with PHP anymore [1].

In order to make that happen, this commit will create a TestCase from
Validation so we can use the same API to create mocks in both PHPUnit
versions 4.0 and 5.0.

During the development of this commit, I noticed that PHPUnit 4.0 had
issues to mock "SplFileInfo" and for that reason, this commit will also
replace those mocks by "SplFileInfo" instances.

[1]: https://hhvm.com/blog/2018/09/12/end-of-php-support-future-of-hack.html

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-12-02 11:09:24 +01:00
Brian Johnson f8c90fa368
Fix Regex for Canadian postal code
Removes the errant space in the CA PostalCode regex.
This space was introduced by 5a067fa.

It also adds unit tests for the CA PostalCode to validate
the fix.

Reviewed-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
2018-11-04 22:58:45 +01:00
ong-ar 892b39e5ff
Update Korean postal code validation
The Korea Postal code system changed from a 6-digit postal code system
to a 5-digit postal code system on August 1, 2015 [1] [2].

This commit makes sure that the "PostalCode" rule validates Korean
postal codes correctly.

[1]: http://www.fedex.com/ky/koreapostalcode/index.html
[2]: http://www.epost.go.kr/roadAreaCdEng.retrieveLnEngAreaCdList.comm

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-10 20:51:31 +02:00
Konstantin c9850f4ec7
Make sure that "Email" only validates strings
There shouldn't be possible to consider a non-string value as a valid
email anyways, but the real problem is that the "RFCValidation" from
"egulias/email-validator" casts the input as a string which makes PHP
trigger an error.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-09 05:28:51 +02:00
Henrique Moody 5a067faec7
Update "PostalCode" list
Updated the whole list according to the last version found on
geonames.org.

The script that I executed to generate the list is:

curl -L http://download.geonames.org/export/dump/countryInfo.txt |
  sed 's,\t,\;,g' |
  sort -u |
  cut -d ';' -f 1,15 |
  sed -E "/^#/d; /^[A-Z]{2}\;$/d; s,([A-Z]{2})\;(.+),'\1' => '/\2/'\,,g"

After generating the list I few changes had to be made since some of the
postal codes in the list were manually updated because they were not
correct.

This change was made because James Macon reported that "110231" was
not recognized as a valid Colombian postal code.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-08-29 22:30:50 +02:00
Henrique Moody a039d6d4b9
Fix wrong behavior of "Date" rule
The validation was considering "99" as a valid month and neither
date_parse_from_format() [1] or DateTime::createFromFormat() [2] would
complain about that.

The solution for that was to use checkdate() [3] to verify whether the
date is valid or not. Also, an extra step was added to the validation
that a date that only contains a day would return false since a day
without a month and year is impossible to validate.

Apparently, there is no problem while validation when it comes to time,
therefore nothing needed to be added for this validation.

[1]: http://php.net/date_parse_from_format
[2]: http://php.net/datetime.createFromFormat
[3]: http://php.net/checkdate

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-08-29 21:46:53 +02:00
Andrei Drulchenko 19d6ec8939 fix IntVal() leading zero behavior 2018-08-01 16:06:54 +03:00
Henrique Moody 47f21596a5
Fix casting error in AbstractInterval classes
The classes that are children of "AbstractInterval" convert their values
before comparing them.

Because PHP tries to convert values when making comparisons and an
"DateTime" object cannot be converted to integer or float some
validations would result into PHP triggering an error like:

> Object of class DateTime could not be converted to int
> Object of class DateTime could not be converted to float

This commit prevents that to happen by verifying if both compared values
are scalar or not before comparing them with each other.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-07-28 05:01:58 +02:00
Axel Wargnier 4f3aa90d1f Fix postalCode for Portugal (PT) 2018-07-25 12:33:08 +02:00
Wojciech Frącz 83bb6e3fc9
Fix wrong behavior when using templates
When a template is set for a chain of rules, does not really matter
which messages the chain can have, the only message to be used should be
the one based on the defined template.

This commit set the same template of a parent rule to its children's
exception. Our first thought was to set the template to its children
however that would mean that if another rule would be added to the chain
we would have to set it as well. Doing that to the children's exception
make sure we only do that once.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-07-02 07:57:21 +02:00
Islam Elshobokshy e70c201691
Make clear that "Alnum" rule accepts whitespaces
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-07-01 14:27:41 +02:00
Sebastian 8fc2484428
Fix postal code for The Netherlands
Postal code for NL allows for a space between the digits and the
letters.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-29 01:10:31 +01:00
Henrique Moody 4fdd2da19e
Fix wrong behavior with nested exceptions
Use the same condition to not include child exception into the iterator
to also not show the message of the main exception when using
"getFullMessage()".

The method created to validate that condition should probably be in the
"ValidationException" itself, but this commit is meant to be a bug fix,
which will be released in a PATH version, and creating this public
method would imply that a MINOR version should be released.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-29 00:50:27 +01:00
Adam Benson f5ca4a298a
Fix "IntVal" considering boolean values as valid
The commit 54d17ab tried to fix the that "IntVal" would pass with values
that are not considered as an integer, but it does not change

Even thought the commit 54d17ab fixes part of the wrong behaviour it
left out the filter for boolean values.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-28 22:09:42 +01:00
Henrique Moody 54d17abcee
Do not consider any float as integer
Values like "500.00" or 1.0 should not be considered as integer values
even though there is no data loss when they're converted to integer.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-23 21:15:38 +02:00
Henrique Moody ee9e69776a
Merge branch '1.0' into 1.1 2018-01-02 22:47:22 +01:00
Henrique Moody c931e2504b
Change conditions for Domain validation
Domains can have `--` as long as they don't start or end with `-` in its
parts.
2018-01-02 22:24:43 +01:00
Henrique Moody 37a71de7d0
Try to find template from default templates first
When executing `ValidationException::setTemplate()` using a template
key, it does not try to select the template, but instead it uses the
template key as the template itself.

In order to fix this behaviour, there is now a check for a key with the
defined template. In case the template was not found, use the defined
template as the template itself.
2018-01-02 21:56:07 +01:00
Henrique Moody d072b4de6a
Remove "malkusch/bav" as dependency
And was that, without warning that the "malkusch/bav" package was
removed from Packagist. This commit removes it as dependency but do not
remove any class that uses it in case there is a user loading the
package from a VCS repository with Composer.
2018-01-02 21:45:22 +01:00
Henrique Moody 22f1f14430
Merge branch '1.0' into 1.1 2017-10-17 12:15:51 +02:00
Henrique Moody 14572537fe
Improve "Phone" rule
- Only allow spaces and not "\t" or "\n";
- Once the number has a "(", it needs a ")".
2017-10-17 09:51:09 +02:00
RCooLeR 191ee47fc0
Update regex of "Phone" rule
Now regex also matches +1 (555) 555 5555
2017-10-17 08:58:47 +02:00
Henrique Moody 631affdbf2
Merge branch '1.0' into 1.1 2017-10-16 10:39:15 +02:00
Henrique Moody 658764a47f
Skip MimetypeTest when in HHVM 2017-10-16 10:16:47 +02:00
Henrique Moody 5ab87d1dd9
Merge branch '1.0' into 1.1 2017-03-14 10:44:11 +01:00
Henrique Moody dc869ac375
Only return "name" as is if it's a string 2017-03-14 10:28:03 +01:00
Henrique Moody 03f4abbd08
Merge branch '1.0' into 1.1 2017-01-26 15:39:48 +01:00
Renato Moura e4ae02fe94
Fix "Cnpj" rule 2017-01-25 17:41:21 +01:00
Henrique Moody 710e807a68
Merge branch '1.0' into 1.1 2016-10-29 15:29:17 +02:00
Henrique Moody f82fcf0762
Prevent "Regex" to process non-string inputs 2016-10-29 15:21:14 +02:00
Henrique Moody e457f19dbd
Merge branch '1.0' into 1.1 2016-09-20 08:44:39 +02:00
Henrique Moody 98050476c6
Always return a valid exception
If calling the method `getExceptionForPath()` when the exception was
nested but had no child it was returning null. This commit ensures that
it always return a valid exception.
2016-09-19 18:22:39 +02:00
Henrique Moody 3fa5bc0489
Merge branch '1.0' into 1.1 2016-09-19 11:24:33 +02:00
Emmerson d0a98ae5d3
Date rule accepting scalar and DateTimeInterface 2016-09-19 10:13:01 +02:00
Henrique Moody c79d8fdf4f
Change file mode of "Image" rule 2016-09-19 09:32:42 +02:00
Gabriel Pedro a772d7f89a
Replace CNH validation algorithm
The old algorithm not working with some CNH values, e.g 00641829409.

You can even do some checking on
http://www.detran.pr.gov.br/modules/catasg/servicos-detalhes.php?tema=motorista&id=239.

Original algo can be found on
http://forum.imasters.com.br/topic/400293-validate-br.
2016-09-18 13:25:18 +02:00
Henrique Moody edf4e49ac6
Merge branch '1.0' into 1.1 2016-09-17 21:30:00 +02:00
Henrique Moody 4bcc4027f8
Try to use the getRelatedByName() method first
Then using the `findMessages()` method, tries to use the method
`getRelatedByName()` before using the `findRelated()` method.

This change was made because since on `KeyNested` rule you may have
names with '.' we'll never get the proper exception using
`findRelated()`.
2016-09-17 21:11:55 +02:00
Henrique Moody 98443bad0c
Get the proper exception when using findMessage() 2016-09-17 21:04:24 +02:00
Henrique Moody 494b67871f
Fix wrong behaviour on AbstractRelated
When you define the name for an `AbstractRelated` instance, you expect
that it also define the name for its child. But, when the child already
had a name the `AbstractRelated` was overwriting its name with the
`reference`.
2016-09-17 20:23:38 +02:00
Henrique Moody 6d0e3a2422
Merge branch '1.0' into 1.1 2016-09-13 11:32:43 +02:00
Henrique Moody 7e88a7a0c8
Always check the type then executing KeyNested 2016-09-12 18:06:10 +02:00
Henrique Moody cc179f9209 Merge branch '1.0' into 1.1 2016-08-03 10:53:00 +02:00
Henrique Moody e5fdd87a16 Rename "Iterable" to "IterableType" 2016-08-03 10:43:33 +02:00
Tomasz Regdos 73a9ff40eb Fix Pesel validator when first char is zero 2016-07-01 16:22:12 +02:00
Henrique Moody 3e1988f9c1 Merge branch '1.0' into 1.1 2016-05-05 13:03:25 +02:00
Emmerson d9a4c78b16 Fixes 'KeySet' rule when input is not array type 2016-05-05 13:01:04 +02:00
Kennedy Tedesco cca733919c Throw an exception when age is not an integer 2016-04-23 21:43:19 -03:00
Augusto Pascutti 9460a4c237 Ensure namespace separator on appended prefixes
Appending a prefix to search new rules under required that the namespace
(prefix) being added always ended with a trailing namespace character so
rules could successfully be found under it. This ensures that the
separator is always present.

Changes a test for a rule which does not implement Respect's interface
to an actual class so we don't need to declare one to use as a stub.
2016-04-23 21:20:54 -03:00
Henrique Moody bb0e40a08e Set template for the only rule in the chain
When there is just one rule in the chain and the there is a defined
template for that, the expected behaviour when using the `check()`
method is to see the exception message with the defined template.
2016-04-08 13:39:57 -03:00