Commit graph

74 commits

Author SHA1 Message Date
Henrique Moody
7db3bea8a6
Enhance LintSpdxCommand with contributor tracking and header normalization
Improves SPDX header linting to ensure consistent license metadata across
the codebase.

Key changes:

- Enforce deterministic tag ordering (License-Identifier, FileCopyrightText,
  FileContributor) to ensure consistency, prevent merge conflicts, and
  simplify code reviews

- Add contributor alias mapping to consolidate contributors with multiple
  emails or name variations (e.g., "nickl-" → "Nick Lombard")

- Add --contributions-strategy option with "blame" (current code authors)
  and "log" (all historical contributors) to support different attribution
  philosophies

- Add optional path argument to lint specific files or directories

- Add --fix option to automatically correct header issues

Assisted-by: Claude Code (claude-opus-4-5-20251101)
2026-02-03 15:23:20 +01:00
Henrique Moody
4390e4feb6
Simplify how we load and save files in data/
We had different ways of saving and loading files from `data/`, so I decided to
unify them to simplify things. I repurposed the `DomainInfo` class and named it
`DataLoader`, so we can use the same class to load anything from the `data/`
directory.
2026-01-26 20:28:29 +01:00
Henrique Moody
819d734a00
Check for mismatches in the mixin classes
When we change the contract of a validator, or create a new one, we need to
ensure that the mixin for the validator is present and matches the validator's
constructor.

This commit changes the current class that generates those mixin classes,
converting it into a linter so we can run it in the GitHub workflow to check for
missing changes.
2026-01-26 20:14:09 +01:00
Henrique Moody
0190f3e109
Group lint-related commands together
Since we have so many lint-related commands now, it makes sense to group
them together to it's easier to spot them.
2026-01-26 20:14:09 +01:00
Alexandre Gomes Gaigalas
bd48bdcda4 Lint Changelog format in validator docs
Introduces a Markdown linter for checking the Changelog format.

"See Also" was transformed into a section to make it easier to
handle it with the `Content` class. The "Related" linter was
simplified to reflect that change too.

An additional "alignment" parameter was added to markdown table
generators, allowing the padding and headers to be explicitly
marked with a specific left (-1), middle (0) or right(1)
alignment.

Existing files were fixed using the `fix` option after the
changes.
2026-01-26 19:11:00 +00:00
Alexandre Gomes Gaigalas
a91517108e Lint SPDX conventions
The `reuse lint` command only checks for REUSE compliance, which
will accept all sorts of SPDX headers.

In this project, however, we have also other conventions. For
example, we require all PHP and docs files from the project
to have a specific license (not just any license) and also a
specific File Copyright Text (not just any copyright).

This commit introduces a command to solve this problem, validating
the headers more thoroughly.

The introduced command also does some dogfooding, using validators
from the library itself to perform some of its tasks, namely: Call,
Each, Contains, Templated and Named, showcasing potential different
use cases for the project.
2026-01-26 16:07:09 +00:00
Alexandre Gomes Gaigalas
d9cdc118b2 Introduce REUSE compliance
This commit introduces REUSE compliance by annotating all files
with SPDX information and placing the reused licences in the
LICENSES folder.

We additionally removed the docheader tool which is made obsolete
by this change.

The main LICENSE and copyright text of the project is now not under
my personal name anymore, and it belongs to "The Respect Project
Contributors" instead.

This change restores author names to several files, giving the
appropriate attribution for contributions.
2026-01-21 06:28:11 +00:00
Alexandre Gomes Gaigalas
3270c1f72c Make all remaining validators serializable
This commit concludes the effort to make all current validators
serializable by fixing the remaining ones.

The ability to use `finfo` instances on some filesystem validators
was removed. `Image` was refactored to be a readonly class.

A command was added to the main `composer qa` flow that checks
if all validators are covered by smoke tests (which are currently
used by benchmarks and serialization tests). Therefore, this commit
also ensures that every validator has a benchmark.
2026-01-19 11:04:35 +00:00
Henrique Moody
d2198dfd01
Replace isValid() calls with assert()
There's more value on showing how `assert()` displays the validation
messages than simply showing if `isValid()` returns `true` or `false`.

However, that increases the chances of having outdated documentation, so
I created a doc linter that updates the Markdown files with the
correct message.
2026-01-13 23:37:06 -07:00
Henrique Moody
98150c7065
Add doc linter to check outdated templates
We don't often change the tempaltes of validators, but when we do it's
extremely important that the documentation of the validators match the
exact template the validator has.
2026-01-13 23:37:06 -07:00
Henrique Moody
7aef3763f2
Add doc linter to check related validators
This commit ensures that if validator A has a direct link to validator
B, validator B will have a direct link to validator A too.
2026-01-13 23:37:06 -07:00
Henrique Moody
d38736d167
Add doc linter to check validator constructors
When we make changes to the code, renaming variables, or adding
parameters to a validator, it's easy to forget to update the
documentation.

With this change, we avoid having a disparity between the documentation
and the code.
2026-01-13 23:37:05 -07:00
Henrique Moody
098c973a2a
Add GitHub action to lint documentation files
When we make changes to the category of a validator, it's easy to forget
to update overall list of validators. This commit a GitHub actions that
will run a console command to check if the documentation it up-to-date.

The job will fail when we need to change the document, but the console
command will fix the issues, so there isn't a lot of friction there.
2026-01-13 23:37:05 -07:00
Henrique Moody
7892a7c902
Port Bash scripts to PHP
It makes more sense to use PHP to generate PHP code than to use Bash. I
love writing Bash scripts, but I know it's not for everyone, and they
can become quite complex. Porting them to PHP code also lowers the
barrier for people to change them.

While I was making those changes, I also noticed a problem with how we
save the domain suffixes. We're converting all of them to ASCII, so we
are not preserving languages such as Chinese, Thai, and Hebrew, which
use non-ASCII characters.
2026-01-06 10:06:22 +01:00
Henrique Moody
81310cc4d9
Rename namespace Rules to Validators
Since that namespace contains our “validators”, naming it as such makes
much more sense.
2026-01-05 17:36:35 +01:00
Henrique Moody
54ac76adce
Rename Rule to Validator
The name "rule" has always been confusing to me. It can be when you talk
about "validation rules", but it’s a very verbose way to describe it,
and it doesn’t work all the time.

This commit will rename the interface `Rule` to `Validator`, but it will
also rename the concept of "rule" to "validator".
2026-01-05 17:36:34 +01:00
Henrique Moody
1a2c52079f
Rename Validator to ValidatorBuilder
The `Validator` class implements the Builder patterns, because it builds
a complex validator within a chain. This is a major breaking change, as
the `Validator` class is the foundation of the library. However, that’s
something relatively easy to replace everywhere.
2026-01-05 11:57:40 +01:00
Henrique Moody
0a45eaf9e4
Create All rule and all prefix
This rule behaves similarly to ``Each, but the difference is that it
presents the messages in a simpler manner. This allows users to have a
simpler message when validating all items in an array or iterable
value.

I’m also introducing the `all` prefix, making it easier for users to
apply the `All` rule in combination with other rules.
2026-01-04 12:23:01 +01:00
Henrique Moody
562d98d805
Refactor the NotEmpty rule
Since we have the ability to use `not` as a prefix, having rules that
validate negative behaviour makes them a bit inflexible, verbose, and
harder to understand.

This commit will refactor the `NotEmpty`, and rename it to `Falsy`. It
will no longer trim strings, because Blank does a much better job at it;
it only simulates the behaviour of PHP’s native `empty()` function.

Because `Falsy`, `Blank`, and `Undef` have similar behaviour, I created
a page to demonstrate the difference and show when the user should use
one or the other.

Assisted-by: Cursor (claude-4.5-opus-high)
2025-12-29 12:48:35 +01:00
Henrique Moody
951c16e8e6
Refactor the NotEmoji rule
Since we have the ability to use `not` as a prefix, having rules that
validate negative behaviour makes them a bit inflexible, verbose, and
harder to understand.

This commit will refactor the `NotEmoji` and rename it to `Emoji`. It
will no longer check if the string contains emojis, but rather if the
string is an emoji or not. I’m also adding support to more emojis, since
the rule was a bit outdated.

This change will make the validator more strict, but will make it useful
in other scenarios. However, later on, I would like to create a rule
called `has` which, could use a validator like `Emoji` to check if the
input _has_ emojis.

Assisted-by: Cursor (claude-4.5-opus-high)
2025-12-29 11:16:25 +01:00
Henrique Moody
7046560f77
Invert the behaviour of NotUndef
Since we have the ability to use `not` as a prefix, having rules that
start with not becomes a bit inflexible, verbose, and harder to
understand.

This commit will refactor the `NotUndef` rule by inverting its behaviour
and renaming it to `Undef`.
2025-12-27 18:49:46 +01:00
Henrique Moody
338c186803
Invert the behaviour of NotBlank
Since we have the ability to use `not` as a prefix, having rules that
start with not becomes a bit inflexible, verbose, and harder to
understand.

This commit will refactor the `NotBlank` rule by inverting its behaviour
and renaming it to `Blank`. Although this is a breaking change, users
will not feel it because "NotBlank" will still be available by using the
`not` prefix followed by the `Blank` rule.
2025-12-27 17:18:30 +01:00
Henrique Moody
8e77021ce7
Reformat documentation files
There was some inconsistent Markdown, and some links were out of sync.
2025-12-27 17:03:25 +01:00
Henrique Moody
e56836c4f1
Remove deprecated rules
We want to release version 3.0 as fresh as possible, without having to
maintain backward compatibility with the previous versions. Apart from
that, for some rules, it's impossible to be compatible with older
versions.

Acked-by: Alexandre Gomes Gaigalas <alganet@gmail.com>
2025-12-18 17:22:51 +01:00
Henrique Moody
a3c197f600
Handle names via the Named rule
Because of how the validation engine works now [1], there's no reason to
keep adding names to each rule. Instead, create a single rule that
handles naming rules with a few other accessories. This change is not
necessarily simple, but it shrinks the `Rule` interface, and it's more
aligned with how the library works right now.

Personally, I think this API is much more straightforward than the
`setName()` method, as it's way more explicit about which rule we're
naming. Because of this change, the behaviour changed slightly, but it's
for the best.

Because of this change, I managed to remove a lot of code, but
unfortunately, it's quite a big-bang commit. It would be too complicated
to make it atomic since names are an intrinsic part of the library.

[1]: 238f2d506a
2024-12-26 23:10:19 +01:00
Henrique Moody
1d1da7f099
Create "Templated" rule
Because of how the validation engine works, there's no reason to keep
adding templates to each rule. Instead, creating a single rule that
handles templating rules will simplify the library greatly and shrink
the `Rule` interface.

Personally, I think this API is much more straightforward than the
`setTemplate()` method, as it's way more explicit which rule is being
templated.
2024-12-26 14:40:09 +01:00
Henrique Moody
74c018bced
Make mixins smarter and with a shorter name
To make PHPStan recognize methods when we call Validator with static and
non-static rule names, I added a few methods from `Validator` to the
`ChainedValidator` interface[1]. However, this didn't work so well
because there could have been more methods from `Validator`.

This commit will rename the mixins to better names, but it will also
make the `Chain` (old `ChainedValidator` to have a `@mixin` on itself of
the `Validator` class.

[1]: a974c0c834
2024-12-18 19:54:44 +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
4a16ad3d09
Allow templates to be callables
There are a few use cases in which you would like to have a custom
exception but, at the same time, reuse the message or exception that
validation might give you.

This commit creates a new feature that allows users to define a callable
that will generate an exception when it fails.
2024-12-11 17:50:47 +01:00
Henrique Moody
e6af762fe4
Rename "Validatable" to "Rule"
Besides the interface's name, everything already calls this type "Rule",
not "Validatable." This commit puts a stone on it and renames the
interface for better naming.
2024-12-05 19:32:14 +01:00
Henrique Moody
3833ad70f8
Improve the "Feature Guide" documentation
Because the document was quite big already, I split the exception
handling part to another document.
2024-12-05 00:21:34 +01:00
Henrique Moody
a974c0c834
Run PHPStan in PHPT files
We were not running PHPStan on those files because of the strict types
declaration. However, I decided it would be better not to have strict
types on those files than not to run PHPStan issues.

Not surprisingly, there were several issues. Some issues were impacting
how user-friendly the library is.
2024-11-29 01:39:41 +01:00
Henrique Moody
4fd26e39bb
Rename "NotOptional" to "NotUndef"
Since I've already renamed the "Optional" rule to "UnderOf," it makes
sense to rename this rule too.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-05-06 20:45:27 +02:00
Henrique Moody
d7dc0f2b4e
Refactor the "NullOr" rule and related classes
This commit will rename the "Nullable" rule to "NullOr" while soft
deprecating the old name. It should work the same as the previous one
but with a different name. It will also prefix the result ID, allowing
more message customization.

While working on it, I realized that the prefix "nullOr" had a typo,
and it was using "nullOf" instead. I fixed that, too.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-26 01:55:50 +01:00
Henrique Moody
707dcae65f
Refactor the "UndefOr" rule and related classes
This commit will rename the "Optional" rule to"UndefOr" while soft
deprecating the old name. It should work the same as the previous one
but with a different name. It will also prefix the result ID, allowing
more message customization.

While working on it, I realized that the prefix "undefOr" had a typo,
and it was using "undefOf" instead. I fixed that, too.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-26 01:35:36 +01:00
Henrique Moody
97b243daa1
Allow building rules using prefixes
Although helpful, the changes in the Min, Max, and Length rules made
using those rules more verbose. This commit will simplify their use by
allowing users to use them as prefixes.

Because I was creating prefixes for those rules, I made other cool
prefixes. Doing that is scary because it will generate more code to
support, and I would have liked to avoid that. However, that's a
valuable addition, and it's worth the risk.

I might reconsider that in the future, but for now, that looks like a
good idea.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-24 16:58:24 +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
27d7db5cc6
Use PHP ISO Codes in the "CurrencyCode" 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:23:01 +01:00
Henrique Moody
fcb6ea5fdb
Fix broken documentation links
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-02-19 11:34:26 +01:00
Henrique Moody
04b2722d02
Remove ISO 3166-2 data in favor of PHP ISO codes
Keeping the list of ISO 3166-2 up-to-date requires some maintenance. At
the same time, PHP ISO Codes maintains an up-to-date database with even
more ISO codes we could use in this library.

This change doesn't fully use all resources of PHP ISO Codes, but it
already removes some unnecessary code from the repository.

We've already used this library, but it was heavy because it included
all the localizations in it. Now, the package is much smaller (5.0M).

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-02-13 21:53:46 +01:00
Alexandre Gomes Gaigalas
7c28d2c1f4 Update sorting order on public suffix data 2023-02-19 00:44:41 -03:00
Alexandre Gomes Gaigalas
ce9608d0a8 Auto update postal code list
- For this particular updater, a list of exceptions to the rules
   downloaded by geonames is included in POSTAL_CODES_EXTRA, for
   cases in which we seem to do better than geonames itself based
   on previous user reports.
 - Added an option to also validate formatting of the postal codes.
 - Combined multiple PR bots into a single one.
2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas
e2b6138bf6 Add PublicDomainSuffix Rule
- List will be auto-updated from https://publicsuffix.org/list/public_suffix_list.dat
 - Updated AbstractSearcher rules to be case insensitive
 - Updated PR creator bots
 - Docs and tests
2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas
6173757f63 Use PHP files and setup a runtime cache for CountryInfo
Previously, we were loading country info from a JSON file. This
changes it to use PHP files instead. It also caches these resources
across calls avoiding these files to be loaded more than once
per process.
2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas
ef4778b456 Remove version info from Tld.php
We currently use a GitHub action to automate updating this file.

That action has the ability to ignore making the PR if the file
didn't changed.

Having the version number, which changed a line, was causing
several useless PR.

Users can still check if Tld.php changed by seeing the git log,
and a manual note should be issued by the maintainer on the
CHANGELOG.md file when a release containing such changes is
made.
2023-02-19 00:19:09 -03:00
Alexandre Gomes Gaigalas
f080f7da08 Improve auto-updaters and pull requesters, auto-tld fix 2023-02-15 00:49:09 -03:00
Alexandre Gomes Gaigalas
74dee73f65 Update updater workflows, remove countries outside ISO-3366-2, cleanup 2023-02-15 00:29:10 -03:00
Alexandre Gomes Gaigalas
1e2f75287c Change update_subdivision_codes to work with salsa/iso-codes, updates data 2023-02-15 00:01:32 -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
4c21a7ffc9
Revert "Use "sokil/php-isocodes" on SubdivisionCode"
This reverts commit 9c9c76ebfb.
2021-03-19 15:12:45 +01:00