Closed dood- closed 4 months ago
Q | A |
---|---|
Is bugfix? | ❌ |
New feature? | ✔️ |
Breaks BC? | ❌ |
Fixed issues | #630 |
Attention: Patch coverage is 93.25843%
with 6 lines
in your changes are missing coverage. Please review.
Project coverage is 94.72%. Comparing base (
e019e5c
) to head (43e9f45
).
Files | Patch % | Lines |
---|---|---|
src/Rule/Count.php | 0.00% | 3 Missing :warning: |
src/Rule/Length.php | 0.00% | 3 Missing :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
New Label Features Introduced the feature of labels in error messages. This improvement allows custom labels to be used in classes, enhancing error readability by providing more specific descriptions. This will help update error messages on the application resulting in a more user-friendly interface.
New Method for Label Retrieve
Addition of a getLabels()
method enabling easy access to the labels of class properties, which will aid in greater error specificity.
Modification of Various Validation Rules
Updated various validation rules both in files like Each.php
, Email.php
, In.php
, Ip.php
, Json.php
, Length.php
, Nested.php
, Number.php
, OneOf.php
, Regex.php
, Required.php
, etc., and their corresponding "Rule Handler" files. These modifications equip each rule with a 'label' parameter to provide more lucid error messages, leading to an improved user experience.
Adjustments in Defined Classes
Changes in defined classes including StringValue
, StringValueHandler
, Subset
, SubsetHandler
, CountableLimitHandlerTrait
, TrueValue
, TrueValueHandler
, Url
, UrlHandler
, ValidationContext
, Validator
and more. These changes result in improved handling and processing of error messages in various conditions.
Changes and Additions in Test Classes
Numerous test classes like ConfigTest
, ObjectDataSetTest
, RulesDumperTest
, AtLeastTest
, BooleanValueTest
, CompositeTest
and others, were updated. Modifications vary from changing default error messages, templates to adding the 'label' parameter. These alterations ensure comprehensive testing of the new feature, guaranteeing reliable functionality and performance.
Default Messages Enhanced in Rule Tests
Numerous rule test files such as CountTest.php
, EachTest.php
, EmailTest.php
, EqualTest.php
, GreaterThanTest.php
and so on were updated. The improvement enables error messages to use a label placeholder instead of hard-coded values. This brings flexibility in error messages, making them more informative and helpful to users.
Updates to Documentation The documentation has been updated to guide configuring rules via PHP attributes, promoting clarity for users.
Implementation of Debug Collector The addition of a new feature for the debug collector aims at enhancing debugging capabilities.
Please note this is a high overview of the changes and not a granular breakdown.
Since I added a new placeholder {label}
, perhaps it is better to make the placeholder {attribute}
always be replaced by the name of the property?
@vjik, @arogachev what do you think?
No, I can't imagine such a case and I agree with @vjik. @dood- would you please adjust the name to be {attribute}
? Thanks.
@samdark, @vjik If we leave "The value" as a default value, then there is a problem with displaying the attribute names of arrays.
Here is a test for an example: https://github.com/yiisoft/validator/blob/1e73321d83d197b0effb16e5d2c32a95d60913e4/tests/Rule/OneOfTest.php#L172-L180
We can not specify a Label attribute for the array or implement the LabelsProviderInterface, so the placeholder value will always be "The value"
If we leave "The value" as a default value
There will be no default value.
Will be one attribute {attribute}
. Value of this placeholder by priority:
1) Translated label (if label exist). 2) Translated attribute.
For case with arrays always will be used translated attribute.
If necessary, I can remove Attribute::TARGET_CLASS from the Label attribute. I also fixed the error messages when using "StopOnError". There, instead of the attribute name, a number was displayed
If necessary, I can remove Attribute::TARGET_CLASS from the Label attribute.
Yes, makes sense.
Also need kill mutants from mutation testing.
Is it possible to disable mutants for a specific php version or just use @infection-ignore-all?
I guess @vjik meant fixing tests so there are no mutants, not ignoring these.
Thanks for you great work! I will review this as well.
Thank you!