Commit graph

9 commits

Author SHA1 Message Date
Henrique Moody
0d4a5fe2be
Enable validating private properties of parent classes
All validators related to object properties only consider the properties
of the object being validated, not those of its parent object. That's
because PHP reflection only gets the properties visible to the current
class (public or protected). The problem with that is that when there's
a private property in the parent class, we're completely unaware of it.

This commit will modify those rules by retrieving properties from the
parent class, ensuring we capture all properties that require
validation.
2025-12-23 16:44:04 +01:00
Henrique Moody
bf9b970e24
Move important value objects to the root namespace
The `Id`, `Name`, and `Path` value objects are not only message-related
concerns, they're part of the core of the library, hence it makes sense
to place them at the root namespace.
2025-12-21 11:14:47 +01:00
Henrique Moody
137c74c5b3
Change how we trace the path of results
Currently, we’re using scalar values to trace paths. The problem with
that approach is that we can’t create a reliable hierarchy with them, as
we can’t know for sure when a path is the same for different rules. By
using an object, we can easily compare and create a parent-child
relationship with it.

While making these changes, I deemed it necessary to also create objects
to handle Name and Id, which makes the code simpler and more robust. By
having Name and Path, we can create specific stringifiers that allow us
to customise how we render those values.

I didn’t manage to make those changes atomically, which is why this
commit makes so many changes. I found myself moving back and forth, and
making all those changes at once was the best solution I found.
2025-12-20 22:19:17 +01:00
Henrique Moody
cfeb01e89e
Bump respect/coding-standard from 4 to 5 2025-12-18 19:03:39 +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
Fabio Ribeiro
0e8ac1817b
Rename Result->isValid method 2025-03-31 21:29:37 +02:00
Henrique Moody
94d53df8ea
Allow to use certain rules as class attributes
There are a few cases in which we want to validate the object as a
whole, and that validation could be attached to the class as a PHP
attribute. This commit enables that capability and changes a few rules
to be class attributes.
2025-01-16 10:27:16 +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
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