Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Label attribute #643

Merged
merged 13 commits into from
Dec 31, 2023
Merged

Add the Label attribute #643

merged 13 commits into from
Dec 31, 2023

Conversation

dood-
Copy link
Contributor

@dood- dood- commented Dec 24, 2023

Q A
Is bugfix?
New feature? ✔️
Breaks BC?
Fixed issues #633

Copy link

what-the-diff bot commented Dec 24, 2023

PR Summary

  • Introduction of PHP Attribute for Property Labels

    • A new PHP attribute has been introduced to designate custom property labels, which can be used in error messages. This attribute is defined in the new Label class located in the Helper folder.
  • Incorporation of Label Handling in Code

    • Label information is now fetched and stored during the parsing of objects with the updated ObjectParser.php file. Moreover, the labels are appropriately incorporated into error messages with the newly introduced setLabel and getAttributeLabel methods in the ValidationContext.php file.
  • Implementation of LabelsProviderInterface in ObjectDataSet

    • The ObjectDataSet.php file has been updated to provide label information by implementing LabelsProviderInterface.
  • Validator Update for Label Usage

    • The Validator.php file now checks if labels are available by examining if the DataSet implements LabelsProviderInterface. If available, these labels are set in the validation context.
  • Testing of New Features

    • New tests have been added in the ObjectParserTest.php and ValidationContextTest.php files to ensure the correct operation of label fetching, storing, and usage.
  • Guide Update

    • The configuring-rules-via-php-attributes.md guidance document has been updated with an example showcasing the use of the Label attribute for custom labels.
  • Inclusion of New Interfaces and Classes

    • Introduction of the new LabelsProviderInterface, which defines the blueprint for classes that provide attribute labels.
  • Label Demonstrations in Test Objects

    • The ObjectForTestingCache1.php and ObjectForTestingDisabledCache.php files now include examples of properties having Label attributes assigned.

All these changes seek to provide greater flexibility and configurability in error messages with the help of custom property labels.

Copy link

codecov bot commented Dec 24, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (493a2d1) 94.45% compared to head (428c142) 94.49%.
Report is 3 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #643      +/-   ##
============================================
+ Coverage     94.45%   94.49%   +0.04%     
- Complexity      776      781       +5     
============================================
  Files            91       91              
  Lines          2361     2379      +18     
============================================
+ Hits           2230     2248      +18     
  Misses          131      131              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vjik vjik added the status:code review The pull request needs review. label Dec 24, 2023
@vjik vjik requested a review from a team December 24, 2023 17:30
Copy link
Member

@vjik vjik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need test when validated object implements LabelsProviderInterface with and without Label attributes usage.

src/Helper/Label.php Outdated Show resolved Hide resolved
src/LabelsProviderInterface.php Outdated Show resolved Hide resolved
@samdark samdark added the pr:request for unit tests Unit tests are needed. label Dec 24, 2023
@samdark samdark removed the pr:request for unit tests Unit tests are needed. label Dec 25, 2023
@samdark samdark requested a review from vjik December 25, 2023 09:55
src/DataSet/ObjectDataSet.php Outdated Show resolved Hide resolved
src/DataSet/ObjectDataSet.php Outdated Show resolved Hide resolved
src/DataSet/ObjectDataSet.php Show resolved Hide resolved
src/LabelsProviderInterface.php Show resolved Hide resolved
src/ValidationContext.php Show resolved Hide resolved
@samdark
Copy link
Member

samdark commented Dec 26, 2023

👍 overall.

@arogachev arogachev self-requested a review December 26, 2023 12:23
CHANGELOG.md Outdated Show resolved Hide resolved
docs/guide/en/configuring-rules-via-php-attributes.md Outdated Show resolved Hide resolved
src/Helper/ObjectParser.php Outdated Show resolved Hide resolved
src/Helper/ObjectParser.php Outdated Show resolved Hide resolved
tests/Helper/ObjectParserTest.php Outdated Show resolved Hide resolved
tests/Helper/ObjectParserTest.php Outdated Show resolved Hide resolved
tests/Helper/ObjectParserTest.php Outdated Show resolved Hide resolved
tests/ValidatorTest.php Outdated Show resolved Hide resolved
tests/ValidatorTest.php Outdated Show resolved Hide resolved
src/Validator.php Outdated Show resolved Hide resolved
@samdark samdark merged commit 3e6ebb9 into yiisoft:master Dec 31, 2023
28 of 33 checks passed
@samdark
Copy link
Member

samdark commented Dec 31, 2023

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:code review The pull request needs review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add PHP attribute that set property label for usage in error messages.
4 participants