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

PhpStorm - Add IDE hints for civicrm_api4() $entity and $action params #27171

Closed
wants to merge 2 commits into from

Conversation

colemanw
Copy link
Member

Overview

Builds on @totten's work in #27168 to add IDE type hints for the civicrm_api4() function.

Before

No hints

After

image

image

Technical Details

Also simplifies the ConformanceTest::getEntitiesLoTech method.

@totten when I was working on this I noticed a couple oddities. I had to use a lo-tech way of gathering entity names because the container hasn't been built by the time this is called. I wonder if that's actually necessary? Because the other oddity I noticed is that the list of services in .phpstorm.meta.php is incomplete. It doesn't include the action_object_provider service for example (which is the one we'd use for gathering APIv4 entities).

Seems like the ideal time for Civi\PhpStorm\Generator to run would be just after the container is built. Then it wouldn't be missing any services, and could actually make use of them without crashing.

Before: Getting entity names was hard and the conformanceTest struggled
After: It's easier, as every entity class has a public getEntityName method
@civibot
Copy link

civibot bot commented Aug 25, 2023

Thank you for contributing to CiviCRM! ❤️ We will need to test and review the PR. 👷

Introduction for new contributors
  • If this is your first PR, an admin will greenlight automated testing with the command ok to test or add to whitelist.
  • A series of tests will automatically run. You can see the results at the bottom of this page (if there are any problems, it will include a link to see what went wrong).
  • A demo site will be built where anyone can try out a version of CiviCRM that includes your changes.
  • If this process needs to be repeated, an admin will issue the command test this please to rerun tests and build a new demo site.
  • Before this PR can be merged, it needs to be reviewed. Please keep in mind that reviewers are volunteers, and their response time can vary from a few hours to a few weeks depending on their availability and their knowledge of this particular part of CiviCRM.
  • A great way to speed up this process is to "trade reviews" with someone - find an open PR that you feel able to review, and leave a comment like "I'm reviewing this now, could you please review mine?" (include a link to yours). You don't have to wait for a response to get started (and you don't have to stop at one!) the more you review, the faster this process goes for everyone 😄
  • To ensure that you are credited properly in the final release notes, please add yourself to contributor-key.yml
  • For more information about contributing, see CONTRIBUTING.md.
Quick links for reviewers

@totten
Copy link
Member

totten commented Aug 25, 2023

(@colemanw) It doesn't include the action_object_provider service for example (which is the one we'd use for gathering APIv4 entities). ... Seems like the ideal time for Civi\PhpStorm\Generator to run would be just after the container is built. Then it wouldn't be missing any services, and could actually make use of them without crashing.

Right, I forgot that compile() does a lot of work after hook_container. I'll try moving it to a later compilation pass. That should capture more services.

(There is an important constraint in how late we can move it -- once compiled, the Definitions and aliases become un-inspectable.)

Another thing to consider - tapping into the container-lifecycle makes sense for the service-list. But it maybe making things harder for api4; e.g. you had to do the lo-tech scan here instead of the typical Entity.get. We could split into multiple files -- then create different generators (listening to different events, writing to different files). Ex:

  • Civi\PhpStorm\ServiceMetadata ==> .phpstorm.meta.php/services.php -- Runs during late compilation phase.
  • Civi\PhpStorm\Api4Metadata ==> .phpstorm.meta.php/api4.php -- Runs after system flush. Runs after CustomGroup actions.
  • Civi\PhpStorm\RouteMetadata ==> .phpstorm.meta.php/routes.php -- Runs after system flush. (But doesn't run after CustomGroup actions.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants