Skip to content

Commit 97dca4d

Browse files
committed
Trim this waaay down.
1 parent 25a9933 commit 97dca4d

File tree

1 file changed

+18
-329
lines changed

1 file changed

+18
-329
lines changed

CONTRIBUTING.md

Lines changed: 18 additions & 329 deletions
Original file line numberDiff line numberDiff line change
@@ -1,345 +1,34 @@
1-
# Contributing to WP Parser
1+
# Contributing
22

3-
Thank you for your interest in contributing to WP Parser! This document provides guidelines for contributing to the project.
3+
Thank you for your interest in contributing to WP Parser!
44

5-
## Getting Started
5+
## Setup
66

7-
### Prerequisites
8-
9-
Before you begin, ensure you have:
10-
11-
- **PHP 8.1+** installed locally (for development outside Docker)
12-
- **Node.js 20+** and **npm 9+**
13-
- **Docker Desktop** (for wp-env testing environment)
14-
- **Git** for version control
15-
- Basic understanding of PHP, WordPress development, and PHPDoc
16-
17-
### Development Setup
18-
19-
1. **Fork and Clone**
20-
```bash
21-
git clone https://github.com/your-username/phpdoc-parser.git
22-
cd phpdoc-parser
23-
```
24-
25-
2. **Install Dependencies**
26-
```bash
27-
# Install Node.js dependencies
28-
npm install
29-
30-
# Install PHP dependencies via wp-env
31-
npm run composer:setup
32-
```
33-
34-
3. **Start Development Environment**
35-
```bash
36-
# Start WordPress with Docker
37-
npm start
38-
39-
# Verify everything works
40-
npm test
41-
```
42-
43-
## Development Workflow
44-
45-
### Making Changes
46-
47-
1. **Create a branch** for your feature or bug fix:
48-
```bash
49-
git checkout -b feature/your-feature-name
50-
# or
51-
git checkout -b fix/issue-description
52-
```
53-
54-
2. **Make your changes** following the coding standards below
55-
56-
3. **Test your changes**:
57-
```bash
58-
# Run full test suite
59-
npm test
60-
61-
# Run specific tests
62-
npm run test:phpunit -- --filter=YourTestName
63-
64-
# Watch tests during development
65-
composer run test:watch
66-
```
67-
68-
4. **Commit your changes** with descriptive messages:
69-
```bash
70-
git add .
71-
git commit -m "Add support for parsing readonly properties"
72-
```
73-
74-
### Testing
75-
76-
All contributions must include appropriate tests:
77-
78-
- **Unit tests** for new parser functionality
79-
- **Integration tests** for WordPress-specific features
80-
- **Regression tests** for bug fixes
7+
This project uses wp-env to provide a containerised test environment. You should manage the environement and run the tests using the npm commands.
818

829
```bash
83-
# Run tests in different ways
84-
npm test # Full test suite
85-
npm run test:phpunit:setup # First-time setup + tests
86-
composer run test:coverage # Generate coverage report
87-
88-
# Debug failing tests
89-
npm run test:phpunit -- --filter=test_name --debug
10+
# Prerequisites: Node.js 20+, Docker Desktop
11+
git clone https://github.com/your-username/phpdoc-parser.git
12+
cd phpdoc-parser
13+
npm install
14+
npm run setup # First time only
15+
npm run test # Run tests
9016
```
9117

92-
### Code Quality
93-
94-
Before submitting, ensure your code passes all quality checks:
18+
## Stop containers when done
9519

96-
```bash
97-
# Currently, the project doesn't have linting configured
98-
# But ensure your code follows WordPress coding standards
9920
```
100-
101-
## Coding Standards
102-
103-
### PHP Code Style
104-
105-
Follow [WordPress PHP Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/):
106-
107-
- **Indentation**: Use tabs, not spaces
108-
- **Line length**: Aim for 100 characters max
109-
- **Naming**: Use snake_case for functions/variables, PascalCase for classes
110-
- **Documentation**: All public methods must have PHPDoc blocks
111-
112-
```php
113-
/**
114-
* Parse a function node and extract function information.
115-
*
116-
* @param Node\Stmt\Function_ $node The function node.
117-
* @return array Function data with name, parameters, and docblock.
118-
*/
119-
protected function processFunction( Node\Stmt\Function_ $node ) {
120-
// Implementation
121-
}
21+
npm run wp-env stop
12222
```
12323

124-
### Documentation
125-
126-
- **PHPDoc blocks** required for all public methods
127-
- **Inline comments** for complex logic
128-
- **README updates** for new features
129-
- **Example usage** in docblocks when helpful
130-
131-
### Git Commit Messages
132-
133-
Use clear, descriptive commit messages:
134-
135-
```bash
136-
# Good
137-
git commit -m "Add namespace detection to File_Reflector"
138-
git commit -m "Fix property docblock parsing for static properties"
139-
git commit -m "Update README with Docker setup instructions"
140-
141-
# Avoid
142-
git commit -m "Fix bug"
143-
git commit -m "Update stuff"
144-
git commit -m "WIP"
145-
```
146-
147-
## Architecture Guidelines
148-
149-
### Core Components
150-
151-
Understanding the parser architecture helps when contributing:
24+
## Architecture
15225

15326
```
15427
lib/
155-
├── class-file-reflector.php # Main AST parser (NodeVisitorAbstract)
156-
├── class-hook-reflector.php # WordPress hook detection
157-
├── class-function-call-reflector.php # Function call parsing
158-
├── class-method-call-reflector.php # Instance method calls
159-
├── class-static-method-call-reflector.php # Static method calls
160-
├── runner.php # API compatibility layer
161-
├── class-importer.php # WordPress post creation
162-
└── template.php # Output formatting
163-
```
164-
165-
### Adding New Parsing Features
166-
167-
When adding new parser functionality:
168-
169-
1. **Extend File_Reflector** if it needs AST traversal
170-
2. **Create dedicated reflector classes** for complex parsing
171-
3. **Update runner.php** to maintain API compatibility
172-
4. **Add comprehensive tests** in `tests/phpunit/tests/`
173-
174-
### Parsing Approach
175-
176-
The parser uses modern PHP libraries:
177-
178-
- **PHPParser v5**: AST-based parsing for accuracy
179-
- **phpstan/phpdoc-parser**: Advanced PHPDoc understanding
180-
- **NodeVisitorAbstract**: Traverse syntax trees efficiently
181-
182-
```php
183-
// Example: Adding new node type handling
184-
public function enterNode( Node $node ) {
185-
switch ( $node->getType() ) {
186-
case 'Stmt_YourNewType':
187-
$this->processYourNewType( $node );
188-
break;
189-
}
190-
}
191-
```
192-
193-
## WordPress Integration
194-
195-
### Testing with wp-env
196-
197-
The project uses [@wordpress/env](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/) for WordPress integration:
198-
199-
```bash
200-
# WordPress environment management
201-
npm run wp-env start # Start containers
202-
npm run wp-env stop # Stop containers
203-
npm run wp-env clean # Reset everything
204-
205-
# Access WordPress container
206-
npm run wp-env run tests-wordpress bash
207-
208-
# Run WP-CLI commands
209-
npm run wp-env run tests-wordpress wp plugin list
210-
```
211-
212-
### Parser WordPress Integration
213-
214-
- **Plugin activation**: Tests run in a real WordPress environment
215-
- **Post creation**: Parsed data becomes WordPress posts
216-
- **Hook detection**: WordPress-specific action/filter parsing
217-
- **Database storage**: Results stored as custom post types
218-
219-
## Common Tasks
220-
221-
### Adding Support for New PHP Features
222-
223-
Example: Adding enum support
224-
225-
1. **Update File_Reflector** to detect enum nodes:
226-
```php
227-
case 'Stmt_Enum':
228-
$this->processEnum( $node );
229-
break;
230-
```
231-
232-
2. **Create processing method**:
233-
```php
234-
protected function processEnum( Node\Stmt\Enum_ $node ) {
235-
// Extract enum data
236-
}
237-
```
238-
239-
3. **Update export functions** in runner.php
240-
4. **Add test cases** for various enum scenarios
241-
242-
### Improving WordPress Hook Detection
243-
244-
Hook detection happens in `isFilter()` method:
245-
246-
```php
247-
protected function isFilter( Node\Expr\FuncCall $node ) {
248-
$function_name = $node->name->toString();
249-
return in_array( $function_name, [
250-
'apply_filters',
251-
'do_action',
252-
'add_filter',
253-
'add_action'
254-
// Add new hook functions here
255-
], true );
256-
}
28+
├── class-file-reflector.php # Main AST parser
29+
├── class-hook-reflector.php # WordPress hooks
30+
├── runner.php # API compatibility
31+
└── class-importer.php # WordPress posts
25732
```
25833

259-
### Debugging Parser Issues
260-
261-
1. **Add debug logging**:
262-
```php
263-
error_log( 'Debug: Found node type: ' . $node->getType() );
264-
```
265-
266-
2. **Inspect AST structure**:
267-
```bash
268-
# Use php-parse to see AST
269-
vendor/bin/php-parse /path/to/file.php
270-
```
271-
272-
3. **Check test output**:
273-
```bash
274-
npm run test:phpunit -- --filter=failing_test --debug
275-
```
276-
277-
## Submitting Contributions
278-
279-
### Pull Request Process
280-
281-
1. **Ensure tests pass**: `npm test` should be green
282-
2. **Update documentation** if needed
283-
3. **Create detailed PR description**:
284-
- What changes were made
285-
- Why they were needed
286-
- How to test the changes
287-
- Any breaking changes
288-
289-
4. **Link related issues**: Use "Fixes #123" in description
290-
291-
### PR Review Criteria
292-
293-
Your PR will be reviewed for:
294-
295-
- **Functionality**: Does it work as intended?
296-
- **Testing**: Are there adequate tests?
297-
- **Code quality**: Follows coding standards?
298-
- **Documentation**: Is it properly documented?
299-
- **WordPress compatibility**: Works with WordPress ecosystem?
300-
- **Performance**: No significant performance regressions?
301-
302-
## Getting Help
303-
304-
### Resources
305-
306-
- **WordPress Developer Handbook**: https://make.wordpress.org/docs/handbook/projects/devhub/
307-
- **PHPParser Documentation**: https://github.com/nikic/PHP-Parser/tree/master/doc
308-
- **phpstan/phpdoc-parser**: https://github.com/phpstan/phpdoc-parser
309-
- **WordPress Coding Standards**: https://developer.wordpress.org/coding-standards/
310-
311-
### Community
312-
313-
- **GitHub Issues**: For bug reports and feature requests
314-
- **WordPress Slack**: #docs channel for general discussion
315-
- **GitHub Discussions**: For questions and implementation discussions
316-
317-
### Common Issues
318-
319-
**Docker Problems**:
320-
```bash
321-
npm run wp-env clean
322-
npm run wp-env start
323-
```
324-
325-
**PHP Version Issues**:
326-
- wp-env uses PHP 8.2 in containers
327-
- Ensure Docker is running
328-
- For local development, ensure PHP 8.1+
329-
330-
**Test Failures**:
331-
- Check that WordPress environment is running
332-
- Verify all dependencies are installed
333-
- Look at specific test output for clues
334-
335-
## Release Process
336-
337-
For maintainers:
338-
339-
1. **Update version** in relevant files
340-
2. **Update changelog** with new features/fixes
341-
3. **Tag release**: `git tag v1.x.x`
342-
4. **Create GitHub release** with changelog
343-
5. **Test on WordPress.org** staging environment
344-
345-
Thank you for contributing to WP Parser! Your efforts help improve the WordPress developer experience for thousands of developers worldwide.
34+
WP Parser uses PHPParser for AST traversal and phpstan/phpdoc-parser for PHPDoc.

0 commit comments

Comments
 (0)