Skip to content

Export constant docblocks and class constants - #311

Open
sanketio wants to merge 2 commits into
WordPress:masterfrom
sanketio:feat/export-constants
Open

sanketio wants to merge 2 commits into
WordPress:masterfrom
sanketio:feat/export-constants

Conversation

@sanketio

Copy link
Copy Markdown

Constants were exported without their documentation, and class constants were not exported at all. Now each constant carries its DocBlock in doc, and each class gets a constants list. For example, WP_Theme_JSON::LATEST_SCHEMA:

{
  "name": "LATEST_SCHEMA", "line": 1078, "end_line": 1078, "value": "3",
  "doc": {
    "description": "The latest version of the schema in use.",
    "tags": [ { "name": "since", "content": "5.8.0" }, … ]
  }
}

Every corpus-diff hunk is one of these two added keys.

Testing

  • vendor/bin/phpunit (with WP_TESTS_DIR set): 172 tests pass on PHP 7.4 and 8.3; the new Export_Constants tests fail on master.
  • wp parser export wp-content/plugins/phpdoc-parser/tests/phpunit/tests/export/constants.inc out.json: in out.json, TEST_DEFINED_CONSTANT (define()) and TEST_CONST_CONSTANT (const) have doc.description set, and classes[0].constants[0] is TEST_CLASS_CONSTANT with value "2" and doc.description "A class constant."
  • wp parser export wp-includes/class-wp-theme-json.php out.json: LATEST_SCHEMA matches the example above.

Possible follow-ups (happy to work on these if they're useful):

  1. Importing constants into the docs, which would complete Include constants in exports #269.
  2. Exporting constant visibility once classes that specify visibility on class constants can't be parsed #224 is resolved.

Part of #269

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant