Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
33f24aa
Modernize parser to PHP 8.1+ with phpstan/phpdoc-parser
johnbillion Jul 13, 2025
bab69d9
Fix Posts-to-Posts activation conflicts in CI environment
johnbillion Jul 13, 2025
6859dc2
Fix Posts-to-Posts dependency conflicts by removing Composer packages
johnbillion Jul 13, 2025
464b774
Fix PHP warnings and improve parser robustness
johnbillion Jul 13, 2025
293472e
Remove composer.lock and add to .gitignore for multi-PHP version comp…
johnbillion Jul 13, 2025
9090ed8
Add GitHub workflow for import functionality testing
johnbillion Jul 14, 2025
d8bb856
Update import test workflow syntax for wp-env
johnbillion Jul 14, 2025
0b769b2
Fix import test workflow to only run on push to master branch
johnbillion Jul 14, 2025
724595d
Add timeout and fix cleanup in import test workflow
johnbillion Jul 14, 2025
13779bc
Fix unit test workflow to only run on push to master branch
johnbillion Jul 14, 2025
cf2e1f7
Add debug step to troubleshoot parser command registration
johnbillion Jul 14, 2025
a24f818
Fix CI: Use npm run setup to start WordPress and install dependencies
johnbillion Sep 8, 2025
a8d579f
Remove --quick flag from documentation and usage
johnbillion Sep 8, 2025
c3090fb
This isn't needed.
johnbillion Sep 8, 2025
25a9933
This isn't needed.
johnbillion Sep 8, 2025
97dca4d
Trim this waaay down.
johnbillion Sep 8, 2025
85344a1
Tidying up.
johnbillion Sep 8, 2025
9f3f33e
Run the tests on 8.1-8.4.
johnbillion Sep 8, 2025
49691ee
Don't know why this got added.
johnbillion Sep 8, 2025
8970642
Loads more tidying up to minimise changed lines.
johnbillion Sep 8, 2025
71c5073
More trimming.
johnbillion Sep 8, 2025
dc6f646
Extract the end_line for legacy format.
dd32 Sep 9, 2025
bc5ee7e
The namespace is 'global' instead of null in legacy. The aliases key …
dd32 Sep 9, 2025
02e5cf1
Add extra parsing for @see, @since, and a fallback for @return.
dd32 Sep 9, 2025
d6efa80
This namespace is also global.
dd32 Sep 9, 2025
f675a38
Only include the uses key if it finds something.
dd32 Sep 9, 2025
1636500
Add support for @var type parsing.
dd32 Sep 9, 2025
f5e43cb
Better @since parsing where a description is included.
dd32 Sep 9, 2025
372fb97
Add @type, add support for '(int|null|string)' types.
dd32 Sep 9, 2025
0fac9af
Docblock summary is the first lines before a empty line, the descript…
dd32 Sep 9, 2025
f45bd00
Parsing for "@see https://blahblah This contains the content"
dd32 Sep 9, 2025
4fc0c75
Add markdown parsing..
dd32 Sep 9, 2025
4316f30
Tests: Test that summary spread over multiple lines is exported.
dd32 Sep 11, 2025
78acc8d
Tests: Add @see tests.
dd32 Sep 11, 2025
4f74be5
Don't HTML Encode quote entities.
dd32 Sep 11, 2025
0a88224
Tests: Add a test (and hack) for typed arrays.
dd32 Sep 11, 2025
b76a36e
Reintroduce the Parsedown library and use that for markup. AI was wro…
dd32 Sep 11, 2025
357757c
Markdown: always parse full content, lists, etc.
dd32 Sep 11, 2025
2dc00ab
Tests: Cover more markdown in details. Broken.
dd32 Sep 11, 2025
5e30d00
Add a better error message for an invalid export path.
johnbillion Dec 19, 2025
299b91b
Add a wrapper command for running the JSON export.
johnbillion Dec 19, 2025
9652531
Merge remote-tracking branch 'dd32/modernize-parser-php8' into modern…
johnbillion Dec 19, 2025
fe6fa4a
Tweak the `@type` handling and add test coverage.
johnbillion Dec 19, 2025
2ef34a8
Correct these assertions.
johnbillion Dec 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/import-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Import Test

on:
pull_request:
push:
branches: [ master ]
workflow_dispatch:

jobs:
test-import:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
php:
- '8.1'
- '8.2'
- '8.3'
- '8.4'

env:
WP_ENV_PHP_VERSION: ${{ matrix.php }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Install
run: npm ci

- name: Setup Environment
run: |
npm run setup

- name: Wait for WordPress to be ready
run: |
timeout 60 bash -c 'until curl -s http://localhost:8888 > /dev/null; do sleep 2; done'

- name: Activate plugins
run: |
npm run wp-env run cli -- -- wp plugin activate phpdoc-parser posts-to-posts

- name: Run sample import (subset of files)
run: |
# Import a small subset of WordPress core files for testing
npm run wp-env run cli -- -- wp parser create /var/www/html/wp-includes/functions.php --user=admin

- name: Verify import worked
run: |
# Check that functions were imported
FUNCTION_COUNT=$(npm run wp-env run cli -- -- wp post list --post_type=wp-parser-function --format=count | tail -1)
echo "Functions imported: $FUNCTION_COUNT"

if [ "$FUNCTION_COUNT" -lt 50 ]; then
echo "ERROR: Expected at least 50 functions, got $FUNCTION_COUNT"
exit 1
fi

- name: Verify taxonomy terms
run: |
# Check that taxonomy terms are properly assigned
FILE_TERMS=$(npm run wp-env run cli -- -- wp term list wp-parser-source-file --format=count | tail -1)
echo "File taxonomy terms: $FILE_TERMS"

if [ "$FILE_TERMS" -eq 0 ]; then
echo "ERROR: No file taxonomy terms found"
exit 1
fi

- name: Test parser command with error detection
run: |
# Run parser and capture both stdout and stderr
if ! npm run wp-env run cli -- -- wp parser create /var/www/html/wp-includes/class-wp.php --user=admin 2>&1 | tee import_output.log; then
echo "ERROR: Parser command failed"
exit 1
fi

# Check for PHP warnings or errors in output
if grep -i "warning\|error\|fatal" import_output.log | grep -v "WP_CLI"; then
echo "ERROR: PHP warnings or errors detected in parser output"
cat import_output.log
exit 1
fi
15 changes: 12 additions & 3 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Unit Tests
on:
pull_request:
push:
branches: [ master ]
workflow_dispatch:

jobs:
Expand All @@ -12,7 +13,10 @@ jobs:
fail-fast: false
matrix:
php:
- '7.4'
- '8.1'
- '8.2'
- '8.3'
- '8.4'

env:
WP_ENV_PHP_VERSION: ${{ matrix.php }}
Expand All @@ -21,12 +25,17 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Install
run: npm install
run: npm ci

- name: Setup Environment
run: |
rm composer.lock
npm run setup

- name: Test
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
vendor
coverage
node_modules
.phpunit.result.cache
composer.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
6 changes: 5 additions & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"phpVersion": "7.4",
"phpVersion": "8.3",
"config": {
"WP_DEBUG": false,
"WP_DEBUG_DISPLAY": false
},
"plugins": [
".",
"https://downloads.wordpress.org/plugin/posts-to-posts.latest-stable.zip"
Expand Down
40 changes: 40 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Contributing

Thank you for your interest in contributing to WP Parser!

## Setup

This project uses wp-env to provide a containerised test environment. You should manage the environement and run the tests using the npm commands.

```bash
# Prerequisites: Node.js 20+, Docker Desktop
git clone https://github.com/your-username/phpdoc-parser.git
cd phpdoc-parser
npm install
npm run setup # First time only
npm run test # Run tests
```

To run the full export to JSON using the WordPress core files in the wp-env container:

```
npm run export
```

## Stop containers when done

```
npm run wp-env stop
```

## Architecture

```
lib/
├── class-file-reflector.php # Main AST parser
├── class-hook-reflector.php # WordPress hooks
├── runner.php # API compatibility
└── class-importer.php # WordPress posts
```

WP Parser uses PHPParser for AST traversal and phpstan/phpdoc-parser for PHPDoc.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,29 @@ We are currently looking for contributors to help us complete the work on the pa
There is a guide to developing for developer.wordpress.org in the [WordPress documentation handbook](https://make.wordpress.org/docs/handbook/projects/devhub/)

## Requirements
* PHP 5.4+
* [Composer](https://getcomposer.org/)
* [WP CLI](https://wp-cli.org/)

* **PHP 8.1+**
* **Node.js 20+** and **npm 9+** (for development environment)
* **Docker** (for wp-env testing environment)
* **Composer**

## Quick Start

Clone the repository into your WordPress plugins directory:

```bash
git clone https://github.com/WordPress/phpdoc-parser.git
cd phpdoc-parser
```

After that install the dependencies using composer in the parser directory:
After that install the dependencies:

```bash
composer install
npm install
npm run setup
```

## Running
Activate the plugin first:

wp plugin activate phpdoc-parser

In your site's directory:

Expand Down
15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
"issues": "https://github.com/WordPress/phpdoc-parser/issues"
},
"require" : {
"php" : ">=5.4",
"composer/installers" : "~1.0",
"phpdocumentor/reflection" : "~3.0",
"erusev/parsedown" : "~1.7",
"scribu/lib-posts-to-posts": "dev-master@dev",
"scribu/scb-framework" : "dev-master@dev",
"psr/log" : "~1.0"
"php" : ">=8.1",
"composer/installers" : "~2.0",
"phpstan/phpdoc-parser" : "^2.0",
"nikic/php-parser" : "^5.0",
"psr/log" : "^2.0|^3.0",
"erusev/parsedown" : "~1.7"
},
"require-dev" : {
"phpunit/phpunit": "^7",
"phpunit/phpunit": "^9",
"spatie/phpunit-watcher": "^1.23",
"yoast/phpunit-polyfills": "^1.0"
},
Expand Down
Loading