Commit graph

36 commits

Author SHA1 Message Date
Henrique Moody
cfeb01e89e
Bump respect/coding-standard from 4 to 5 2025-12-18 19:03:39 +01:00
Henrique Moody
7f66bcea10
Bump PHP support from 8.1 to 8.5
We want to release version 3.0 as fresh as possible, without having to
maintain backward compatibility with the previous versions. Because that
version will be on for some time, we decided it will be best to support
only PHP version 8.5 or higher.

Acked-by: Alexandre Gomes Gaigalas <alganet@gmail.com>
2025-12-18 19:03:38 +01:00
Henrique Moody
0066786fa7
Remove deprecated methods check() and validate()
We want to release version 3.0 as fresh as possible, without having to
maintain backward compatibility with the previous versions.

Acked-by: Alexandre Gomes Gaigalas <alganet@gmail.com>
2025-12-18 17:29:02 +01:00
Henrique Moody
7cec227520
Create "Attribute" rule
With this change, any rule can be used as a PHP attribute. I have wanted
to implement this feature for a while, as it allows you to bind the
validation to a specific property and just validate the object
afterwards.
2024-12-13 03:49:29 +01:00
Henrique Moody
ea605b61b6
Simplify InvalidRuleConstructorException
The message wasn't looking very user friendly, so I changed it a little
bit.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-24 18:06:38 +01:00
Henrique Moody
81befe8fa1
Move core rules into the "Core" namespace
That helps organize the code better, making it easier to spot the core
rule. It also helps not allow the Factory to load those rules, as the
new namespace is not registered in it.

Note that the "AbstractAge", "AbstractRelated", and "AbstractRule" were
not moved. I want to do that only when I refactor them.

After I moved classes, I realized that "Comparison" and "FilteredString"
had no tests. I created the tests, and while I did that, I spotted two
bugs:

* The "Equals" rule was failing when comparing non-scalar wth scalar
  values;

* The "Equals" and "Identical" rules were not working correctly because
  "Comparison" was converting their values.

I fixed those bugs in this commit.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-03 16:12:58 +01:00
Henrique Moody
2c56575ce3
Make it easier to create "InvalidRuleConstructorException"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-02-23 02:27:41 +01:00
Henrique Moody
a45a0a26ab
Use PHP ISO Codes in the "LanguageCode" rule
Since we now have PHP ISO Codes as a dependency[1], it doesn't make
sense to keep dealing with this data ourselves.

[1]: 04b2722d02

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-02-22 19:27:49 +01:00
Henrique Moody
e341fef5c0
Update the validation engine of envelop-based rules
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-02-22 18:41:09 +01:00
Henrique Moody
26e9fb9d59
Allow templates to have raw and translatable params
In some cases, a user would like to show the parameter just as it is,
and in other cases, they need to translate a specific parameter. This
change creates that capability by adding a template-style modifier to a
parameter in the template.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-02-14 18:08:13 +01:00
Henrique Moody
02b70bf1cb
Move Template to the Message namespace
That way, everything related to messages would stay in the same
namespace.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-02-09 19:50:25 +01:00
Henrique Moody
84f1d3296e
Remove "@throws" annotations
I don't find much use for those, and it's hard to be consistent with all
places that could throw an exception.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-01-29 23:51:42 +01:00
Henrique Moody
e4f2c8154a
Use PHP attributes to define templates
Creating a specific exception for each rule adds a painful overhead. If
you want to make a custom message for your rule, you will need to create
an exception and then register that exception namespace to be able to
use it—all that is just for customizing the message of your rule.

Having different namespaces also implies that you need to fetch the
exception of the rule from another directory to change it. As Uncle Bob
said, "Classes that change together belong together. Classes that are
not reused together should not be grouped."

This commit will drastically change this library, moving all the
templates from the exceptions to the rules. Consequently, the Factory
becomes much simpler, and the library gets a bit smaller, too.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-01-29 23:43:57 +01:00
Henrique Moody
9a13c9fb03
Update coding standards
This change will bring many breaking changes. The good thing is that we
can finally use more modern resources available in PHP.

I can imagine that's not a popular change since it will bring many
breaking changes to users, but we shouldn't be stuck in time because of
that. Using some of those features will make it easier to contribute to
the project. At least, I hope so.

There are still some useless doc-blocks, and we're not using "readonly"
properties when we could. I aim to send those changes soon.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-01-28 00:22:41 +01:00
Alexandre Gomes Gaigalas
ab3732f91f Use SPDX IDs for licensing
SPDX IDs are shorter than licensing notes previously used, and
adhere better to FOSS standards. It is also machine-readable.
2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas
15f148da24 Dusting off. See CHANGELOG.md for more details on this commit 2023-02-13 03:59:11 -03:00
Henrique Moody
b78f602f0e
Revert "Use "sokil/php-isocodes" on LanguageCode"
This reverts commit 5450ef86a8.
2021-03-19 15:12:44 +01:00
Henrique Moody
5450ef86a8
Use "sokil/php-isocodes" on LanguageCode
Since we already have that library as a dependency of our repository, it
makes sense to use it as a source of language codes instead of keeping a
list of currencies ourselves.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2021-02-06 15:53:11 +01:00
Henrique Moody
3145426472
Update version of "respect/coding-standard"
With that update, we will be fully following PSR-12.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-07-21 22:54:41 +02:00
The Respect Panda
6eeacfce5a Update list of language codes 2020-05-31 00:11:47 +00:00
Henrique Moody
83b515d0a3
Configure GitHub workflow to update language codes
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-05-26 18:33:23 +02:00
Henrique Moody
2d0f56d9cb
Merge branch '1.1'
This commit will revert the update of subdivision codes [1] since the
way we store this data is very different from the merged branch.

[1]: 8b8f7db713

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-29 23:17:53 +02:00
Henrique Moody
c51931679c
Update list of language code
This commit will also create a Bash script to update that list in the
future.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-28 08:02:57 +02:00
Henrique Moody
ef8a8f4b27
Turn LICENSE file into plain/text
There is no need for that file to be a Markdown, and it can be a plain
text file.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-23 16:21:34 +02:00
Henrique Moody
c60ca7937b
Update the Coding Standards
This commit will add a couple of rules that we already use but also
introduce new ones and make sure all the code is in accordance with the
new coding standards.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-17 19:52:26 +01:00
Henrique Moody
99b912ff87
Apply "SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-09 14:19:22 +01:00
Henrique Moody
7e884cc0f4
Apply "SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-09 14:09:29 +01:00
Henrique Moody
c30603759e
Apply "SlevomatCodingStandard.TypeHints.TypeHintDeclaration"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-09 14:09:28 +01:00
Henrique Moody
ee1d49a2cf
Apply "Squiz.PHP.CommentedOutCode"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-09 14:08:41 +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
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
Henrique Moody
5d0ecabfdc
Declare visibility for constants
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-27 16:12:05 +02:00
Henrique Moody
ccf60f0ee3
Method validate() should always return a boolean 2018-01-28 17:38:36 +01:00
Henrique Moody
ef975629f3
Changes on PHP-CS-Fixer configuration
Because of `declare(strict_types=1)` some changes were necessary.
2018-01-04 17:59:37 +01:00
Henrique Moody
f34a34c0b2
Always use mbstring functions 2016-10-30 10:45:30 +01:00
Emmerson
621b4707b5 Create "LanguageCode" rule 2015-10-26 23:12:21 -03:00