Commit graph

2012 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
Henrique Moody df3f1c0ea7
Add "CREDITS" section to PHPT files
All the PHP files have the "@author" annotation to make clear which
people have contributed to that specific file, however, there is no such
thing in the PHPT files.

This commit will add the "CREDITS" section to the PHPT files. The list
of authors is created from the output of the `git blame` command.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-11-30 09:25:42 +01:00
Danilo Correa 54e3f99ec4
Apply contribution guidelines to "When" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-11-25 19:21:29 +01:00
Henrique Moody 9e7571fb98
Add missing "@author" annotations
This commit will make sure that every class, interface, or trait will
have the "@author" annotation in it.

In order to create a list of authors, I used the "git blame" command,
which means that if someone changed or even created the file but does
not have any remaining line will not be shown in the list; it's a
trade-off worth but it is worth it. The other way to do it would be
carefully checking each file.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-11-25 18:08:44 +01:00
Henrique Moody 2e29b9e8c7
Fix "@author" annotations
Some classes and one trait had some mismatch values for their "@author"
annotation and this commit will fix the mismatch putting the correct
authors.

I used the "git blame" command to find out which people changed the file
and created a list based on that information.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-11-25 18:04:59 +01:00
Henrique Moody 93e177a4c0
Make second argument of "AbstractEnvelope" optional
The argument "parameters" which is meant to give the wrapped rule's
exception some extra information does not always need to be defined, for
example when the exception does not need any parameter.

The current version of "AbstractEnvelope" required that argument and the
rules that are extending this class are passing an empty array.

This commit will make the "parameters" argument optional. As an extra,
it will make sure the tests from the children of "AbstractEnvelope" are
also covering their parent.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-11-25 15:30:40 +01:00
Danilo Benevides 9595b3fd6c
Apply contribution guidelines to "LanguageCode" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-11-25 13:27:06 +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
Danilo Correa d6699a3daf
Apply contribution guidelines to "VideoUrl" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Co-authored-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
Co-authored-by: Danilo Correa <danilosilva87@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-26 00:00:45 +02:00
Danilo Correa c871291a55
Apply contribution guidelines to "Writable" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Co-authored-by: Danilo Correa <danilosilva87@gmail.com>
Co-authored-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
2018-10-26 00:00:07 +02:00
Emmerson Siqueira 299551dea3
Add support to Twitch on "VideoUrl" rule (#1154)
Co-authored-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
2018-10-23 16:50:30 +02:00
Henrique Moody 4e045e75b4
Execute PHP 7.3 on Travis
Because "friendsofphp/php-cs-fixer" does not support PHP 7.3 this commit
will also add "--ignore-platform-reqs" argument to Composer when it is
being executed.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-15 11:28:46 +02:00
Henrique Moody c99f3818b7
Use variadics "AbstractFilterRule" rule
Since the library doesn't need to give support to version 5.4 or less of
PHP using variadics in the constructor of "AbstractFilterRule" seems
better than doing the whole validation.

This commit will also apply the contribution guidelines to
"AbstractFilterRule" and use a better naming for it.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-15 09:41:01 +02:00
Michael Weimann 6730576fe4
Add support for specific versions of UUID
This commit will allow validation of UUIDs with versions 1, 3, 4 and 5.

Version 2 was not implemented since its adoption is not that broad and
we couldn't find many details about it.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
2018-10-12 11:37:42 +02:00
Linus Metzler 48b06254c4 Fix license identifier
Currently the license identifier (BSD Style) does not comform to the
SPDX list of valid identifiers https://spdx.org/licenses/. Having a
valid identifier helps automated license checking tools verify your
package.

I took the liberty of setting the license to BSD-3-Clause. If you want
to allow multiple licenses, you could use a SPDX expression e.g.
(BSD-2-Clause OR BSD-3-Clause).
2018-10-11 14:18:10 +02: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
Henrique Moody d9628a89dd
Merge branch '1.1' 2018-10-09 06:38:43 +02:00
Henrique Moody 203f8e7e9d
Update TLD list with version 2018100800 from IANA
As it seems, the TLDs "goodhands", "jlc", "panerai", "statoil",
"telecity", and "vista" were removed from the list.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-09 06:03:51 +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
Danilo Correa fbbab77b24
Apply contribution guidelines to "Version" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-03 00:04:39 +02:00
Danilo Correa 69a01249da
Apply contribution guidelines to "Fibonacci" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-03 00:04:39 +02:00
Danilo Correa 4200704bdc
Apply contribution guidelines to "File" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-03 00:04:39 +02:00
Danilo Correa 23656c9030
Apply contribution guidelines to "Finite" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-03 00:04:39 +02:00
Danilo Correa 0be63bd313
Apply contribution guidelines to "FalseVal" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-03 00:04:38 +02:00
Danilo Correa eb232247da
Apply contribution guidelines to "Factor" rule 2018-10-03 00:04:38 +02:00
Danilo Correa b399bfe1c1
Create Composer scripts to help during development
This commit will create Composer scripts for commands that are
frequently used during the development of the library.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-03 00:04:10 +02:00
Moritz 03ea1b75f6
Create "Isbn" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-02 17:32:08 +02:00
Danilo Correa 4106589e7f
Apply contribution guidelines to "Extension" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-24 21:28:20 +02:00
Danilo Correa 1b4a904871
Apply contribution guidelines to "Luhn" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-24 21:23:17 +02:00
Henrique Moody 478e248dad
Remove unnecessary inheritance from "Yes" rule
The "Yes" rule extends "Regex" rule. The only reasons why that is useful
is because "Yes" uses regular expressions to validate the inputs.

However, the "Yes" rule is way more complex simply validating a regular
expressing and having "Regex" as its parent is also a little bit
misleading.

This commit will:

* Remove unnecessary inheritance from "Yes" rule;

* Improve the documentation of the "Yes" rule;

* Enhance the unit tests of the "Yes" rule.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-16 19:40:48 +02:00
Henrique Moody ea683e691d
Remove "AbstractRegexRule" class
The "AbstractRegexRule" seems like an unnecessary overhead on top of the
"AbstractFilterRule". In fact, the "Phone" and "Uuid" rule should not
even be children of "AbstractFilterRule".

This commit will remove the "AbstractRegexRule" and replace it with
"AbstractFilterRule" on the rules that are depending on it. As for the
rules that don't depend on it it will replace by "AbstractRule" like
most of the other rules.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-16 18:32:39 +02:00
Danilo Correa 907e24fb8f
Apply contribution guidelines to "MacAddress" rule
This commit will also replace the usage of "mac" to "MAC" since it is an
acronym.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-16 18:26:51 +02:00
Danilo Correa e2e9197f29
Apply contribution guidelines to "Mimetype" rule
This commit will also replace the usage of "mime" to "MIME" since it is
an acronym.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-16 18:15:57 +02:00
Cameron Hall fd13b03d18
Apply contribution guidelines to "Yes" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-16 17:25:26 +02:00
Henrique Moody 35f3dd63af
Remove "AbstractCtypeRule" class
The "AbstractCtypeRule" class is an abstraction that is purely an
overhead on top of the "AbstractFilterRule". Not having a real reason to
exist I thought would be better to just remove it and replace its usage
by "AbstractFilterRule".

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-14 09:08:56 +02:00
Danilo Correa d5724c0d9a
Remove "image_5.phpt" file
This file should have been removed by when the contribution guidelines
were applied to "Image" but for some reason, we missed that.

Reference: 861216c690
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-14 08:58:39 +02:00
Danilo Correa aedf261958
Apply contribution guidelines to "Readable" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-14 08:58:39 +02:00
Danilo Correa 083ccec068
Apply contribution guidelines to "LeapYear" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-14 08:41:14 +02:00
Danilo Correa 5b6184d4e2
Apply contribution guidelines to "NotOptional" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-14 08:40:32 +02:00
Henrique Moody 9283c8ecd9
Do not accept whitespace by default in "Digit" rule
The "Digit" rule is meant to validate digits. However, by default, it
also considers any whitespace character (spaces, new lines, tabs, etc)
as valid.

Since the rule also accepts a list of characters to ignore during the
validation it seemed logical to me to leave the responsibility of
allowing whitespace characters on the hands of the one who uses the
rule.

The messages of the exception are not really consistent, this commit
will also fix that.

It's also clear that the "AbstractCtypeRule" is an unnecessary overhead
since it is only a proxy for "AbstractFilterRule". That one can and
should even be removed after this commit is applied especially because
this commit will also remove the method "filterWhiteSpaceOption" which
is the only substantial difference between "AbstractCtypeRule" and
"AbstractFilterRule".

This commit will also apply our guidelines to the "Digit" rule since we
want to do that to all the rules we have.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-12 10:00:17 +02:00
Henrique Moody 27bd5d204d
Do not accept whitespace by default in "Alpha" rule
The intent of the "Alpha" rule is to validate alphabetic values.
However, it also considers any whitespace character (by default). That
causes some confusion, and unless you check its code or tests, you would
never expect that behavior.

Because of that confusion, I decided to make "Alpha" to not consider
whitespace characters as valid, and since in the constructor of this
rule it's possible to add extra characters to the validation it makes
sense to let the user decide whether they want whitespaces, tabs, new
lines, etc. or not.

This rule, as the same as "Alnum" previously, extends
"AbstractCtypeRule" pretty much to only make it easier to consider any
whitespaces as valid, therefore I saw no reason to keep extending it.
Now "Alpha" extends the "AbstractFilterRule" which is the parent of
"AbstractCtypeRule".

I also took the opportunity to apply our contribution guidelines to
"Alpha" since we want to apply that to all the rules.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-11 11:38:15 +02:00
Henrique Moody 3601adf6db
Create "FilteredValidationException" class
All the classes that were extending "AbstractFilterRule" were throwing
exceptions that were extending "AlphaException". That can cause some
issues when the user has a validation chain with "Alpha" and another
child of "AbstractFilterRule" and expects "AlphaException" specifically.

This commit creates "FilteredValidationException" that can be used as
the parent of the exceptions thrown by rules that extend the class
"AbstractFilterRule".

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-11 11:02:17 +02:00
Danilo Correa 24040c9473 Apply contribution guidelines to "NotBlank" rule 2018-09-10 21:00:53 -03:00
Danilo Correa 0e67549dd9
Apply contribution guidelines to "Pesel" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-10 14:51:52 +02:00
Danilo Benevides 2bb6f66251
Apply contribution guidelines to "LeapDate" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-10 14:51:52 +02:00
Danilo Correa 73a0107349
Apply contribution guidelines to "PhpLabel" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-10 08:18:15 +02:00
Danilo Correa 30993fc4a0
Apply contribution guidelines to "Pis" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-10 08:16:25 +02:00
Danilo Correa e832a99d4c
Apply contribution guidelines to "StringVal" rule
Also creates a "ToStringStub" class to help on testing objects that can
be converted to string.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-06 08:41:12 +02:00
Danilo Correa c7fbded457
Apply contribution guidelines to "NumericVal" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-06 08:41:11 +02:00
Danilo Correa 17f8c50f54
Apply contribution guidelines to "Length" rule
Because of the type hinting some validation could be removed from the
"length" constructor.

While applying the contribution guidelines we could also see some
duplicated logic in the "extractLength" method and that the rule was
validating

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-06 08:41:11 +02:00