Fix attributes collecting#249
Conversation
|
BTW, could someone fix psalm issue? :) |
|
@xepozz here it is diff --git a/src/Attribute/Embedded.php b/src/Attribute/Embedded.php
index eb80e82..a568ad8 100644
--- a/src/Attribute/Embedded.php
+++ b/src/Attribute/Embedded.php
@@ -18,14 +18,14 @@ use Yiisoft\Validator\ValidationContext;
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
final class Embedded extends GroupRule
{
+ /**
+ * @psalm-param Closure(mixed, ValidationContext):bool|null $when
+ */
public function __construct(
private string $referenceClassName,
string $message = 'This value is not a valid.',
bool $skipOnEmpty = false,
bool $skipOnError = false,
- /**
- * @psalm-param Closure(mixed, ValidationContext):bool|null
- */
?Closure $when = null,
) {
parent::__construct($message, $skipOnEmpty, $skipOnError, $when);
diff --git a/src/Rule/GroupRule.php b/src/Rule/GroupRule.php
index 46dfccb..31f4ea6 100644
--- a/src/Rule/GroupRule.php
+++ b/src/Rule/GroupRule.php
@@ -27,7 +27,7 @@ abstract class GroupRule implements ParametrizedRuleInterface, BeforeValidationI
private bool $skipOnEmpty = false,
private bool $skipOnError = false,
/**
- * @psalm-param Closure(mixed, ValidationContext):bool|null
+ * @var Closure(mixed, ValidationContext):bool|null
*/
private ?Closure $when = null,
) {
|
| return $this->collectAttributes($classMeta); | ||
| } | ||
|
|
||
| // TODO: use Generator to collect attributes |
There was a problem hiding this comment.
I've mentioned it in the PR description
|
Looks way better than current HasOne and HasMany 👍 |
|
@xepozz seems there are issues not only with Psalm: https://github.com/yiisoft/validator/runs/7368352855?check_suite_focus=true |
|
This one includes #244, right? |
|
Also it seems it will solve #193, right? |
|
Not sure about the last one, but the first has to be removed after the merge |
Seems nested attributes don't work below 8.1 php version |
|
|
PHP 8.1 specific tests should be separated and marked as such. |
# Conflicts: # src/DataSet/AttributeDataSet.php # src/Rule/AtLeast.php # src/Rule/Boolean.php # src/Rule/CompareTo.php # src/Rule/Composite.php # src/Rule/Count.php # src/Rule/Each.php # src/Rule/Email.php # src/Rule/HasLength.php # src/Rule/InRange.php # src/Rule/Ip.php # src/Rule/Json.php # src/Rule/Nested.php # src/Rule/Number.php # src/Rule/Regex.php # src/Rule/Required.php # src/Rule/Subset.php # src/Rule/Url.php
| return $this->collectAttributes($classMeta); | ||
| } | ||
|
|
||
| // TODO: use Generator to collect attributes |
There was a problem hiding this comment.
Why if we return ruleset as array? We would not gain anything, I think.
There was a problem hiding this comment.
Validator may fail on one of any rules and not continue to check others.
As far as I know, it's still converts all iterables to array and after check them one by one, but we need to change it.
|
👍 |
HasOneandHasManywere replaced withEmbeddedI've added TODO about collecting attributes in lazy mode. It may be useful because of using
Reflectionto get rules collection.