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

feat: add php sniffer for contact methods #1594

Closed
wants to merge 25 commits into from

Conversation

leogermani
Copy link
Contributor

@leogermani leogermani commented Aug 2, 2024

All Submissions:

Changes proposed in this Pull Request:

In the effort of consolidating our data flows, we want to enforce that every contact update goes through the same route, starting at Newspack_Newsletters_Contacts class to make sure we have the propper logging.

However, we can't make all the internal methods private or protected.

This PHP Sniffer helps us avoid adding any new code that will bypass our intended flow. We'll need to add this sniffers to other Newspack plugins as well. - TBD how to do that

How to test the changes in this Pull Request:

  1. checkout this branch
  2. run ./vendor/bin/phpcs
  3. Confirm you see some error in 2 files. (These errors are fixed in Add/logging #1574)
  4. Does the message look good?
  5. Try to add a method to one of the forbidden methods anywhere in the code.
  6. Make sure the sniffer catches it

PS - the linting errors in the CI job are expected until we merge #1574

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

leogermani and others added 22 commits July 9, 2024 11:21
feat: refactor add_contact and put async sign up behind a flag
In the last PR this method was forgotten
…ector

feat: add methods that were in mailchimp data connector
@leogermani leogermani self-assigned this Aug 2, 2024
@leogermani leogermani requested a review from a team as a code owner August 2, 2024 20:21
Copy link
Member

@miguelpeixe miguelpeixe left a comment

Choose a reason for hiding this comment

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

Super cool!

One issue caught by the linter is from src/blocks/subscribe/index.php, which doesn't call the forbidden method from a class. This causes the sniffer to throw a misleading error:

FILE: /home/circleci/project/src/blocks/subscribe/index.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 501 | ERROR | Method
     |       | Newspack_Newsletters_Subscription::add_contact()
     |       | should not be called from class
     |       | NewspackNewslettersContactsMethodsSniff. These methods
     |       | are for internal use only. Use methods in
     |       | Newspack_Newsletters_Contacts class instead.
     |       | (..NewspackNewslettersContactsMethods.ForbiddenContactsMethods)
----------------------------------------------------------------------

Given it includes the filename, it's not too bad, but is there a way to catch that and adjust the messaging?

@leogermani
Copy link
Contributor Author

Super cool!

One issue caught by the linter is from src/blocks/subscribe/index.php, which doesn't call the forbidden method from a class. This causes the sniffer to throw a misleading error:

FILE: /home/circleci/project/src/blocks/subscribe/index.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 501 | ERROR | Method
     |       | Newspack_Newsletters_Subscription::add_contact()
     |       | should not be called from class
     |       | NewspackNewslettersContactsMethodsSniff. These methods
     |       | are for internal use only. Use methods in
     |       | Newspack_Newsletters_Contacts class instead.
     |       | (..NewspackNewslettersContactsMethods.ForbiddenContactsMethods)
----------------------------------------------------------------------

Given it includes the filename, it's not too bad, but is there a way to catch that and adjust the messaging?

Thanks!

Yes, we could get the filename and add to the error message if we are not inside a class. But looking at it, I think it makes more sense to make it simpler and more generic. 99425a4 does it

@github-actions github-actions bot added [Status] Approved Ready to merge and removed [Status] Needs Review labels Aug 6, 2024
Base automatically changed from epic/consolidate-data-flows to trunk August 12, 2024 18:30
@leogermani
Copy link
Contributor Author

We forgot to merge this to the epic before merging the epic to trunk and now, because of Squash, it was easier to rebuild this PR in a new branch -> #1611

@leogermani leogermani closed this Aug 13, 2024
@leogermani leogermani mentioned this pull request Aug 13, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] Approved Ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants