Skip to content

Commit d79fe5b

Browse files
committed
docs: Add PHP API documentation section to README
Explains how classes/functions get included in API docs: - Referenced via @see in hooks documentation - Marked with @api or @public tags - Transitively referenced from documented classes Includes examples for @api, @public, and @see tag usage, plus best practices for writing quality PHPDoc comments.
1 parent e8705f4 commit d79fe5b

1 file changed

Lines changed: 134 additions & 1 deletion

File tree

README.md

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,137 @@ npm run hooks:generate -- --dry-run # Preview without making changes
105105
npm run hooks:generate -- --help # Show help
106106
```
107107

108+
**Generate PHP API Reference**
109+
```bash
110+
npm run api:generate # Generate all API docs
111+
npm run api:generate -- --filter gravityview # Generate specific product
112+
npm run api:generate -- --dry-run # Preview without making changes
113+
```
114+
115+
## PHP API Documentation
116+
117+
The PHP API reference documents classes, methods, and functions from your codebase. Documentation is automatically generated from PHPDoc comments.
118+
119+
### How classes and functions get included
120+
121+
Not every class gets documented—only those that meet specific criteria:
122+
123+
1. **Referenced in hooks documentation** - Classes/methods mentioned via `@see` in hook docblocks
124+
2. **Marked as public API** - Classes/methods with `@api` or `@public` tags
125+
3. **Transitively referenced** - Classes referenced via `@see` in already-documented classes
126+
127+
This scoping ensures the API docs focus on symbols developers actually interact with, rather than internal implementation details.
128+
129+
### Using @api and @public tags
130+
131+
Add `@api` or `@public` to any class, method, or function docblock to include it in the documentation:
132+
133+
```php
134+
/**
135+
* Public API for creating custom entry displays.
136+
*
137+
* @api
138+
*/
139+
class GravityView_Entry_Renderer {
140+
/**
141+
* Render an entry using the specified template.
142+
*
143+
* @api
144+
* @param array $entry The Gravity Forms entry.
145+
* @param string $template Template slug to use.
146+
* @return string Rendered HTML.
147+
*/
148+
public function render( $entry, $template ) {
149+
// ...
150+
}
151+
}
152+
```
153+
154+
**When to use:**
155+
- Public APIs that third-party developers should use
156+
- Extension points designed for customization
157+
- Utility functions meant for external consumption
158+
159+
**Tag equivalence:** Both `@api` and `@public` work identically. Use whichever fits your team's conventions.
160+
161+
### Using @see for cross-references
162+
163+
The `@see` tag creates links between documented symbols and can pull in additional classes:
164+
165+
```php
166+
/**
167+
* Alias for GravityView_Merge_Tags::replace_variables()
168+
*
169+
* @see \GravityView_Merge_Tags::replace_variables() Moved in 1.8.4
170+
* @see gravityview_get_entry()
171+
*/
172+
public static function replace_variables( $text, $form = [], $entry = [] ) {
173+
// ...
174+
}
175+
```
176+
177+
**Supported @see formats:**
178+
- `\ClassName::methodName()` - Links to a class method (also includes that class in docs)
179+
- `functionName()` - Links to a standalone function
180+
- `https://...` - External URL (rendered as-is)
181+
182+
**Transitive expansion:** If ClassA references ClassB via `@see`, and ClassB references ClassC, all three classes are included. This runs iteratively to capture the full reference graph.
183+
184+
### Best practices for PHPDoc
185+
186+
For quality API documentation:
187+
188+
```php
189+
/**
190+
* Brief one-line summary of what this does.
191+
*
192+
* Longer description with more details about usage,
193+
* edge cases, and important considerations.
194+
*
195+
* @since 2.0
196+
*
197+
* @param array $entry The Gravity Forms entry array.
198+
* @param string $context Where this is being called from.
199+
*
200+
* @return string|null The processed value, or null on failure.
201+
*
202+
* @throws \InvalidArgumentException When entry is missing required fields.
203+
*
204+
* @see \GV\Entry::get_value() For the modern approach.
205+
* @see https://docs.gravitykit.com/article/123 Full documentation.
206+
*/
207+
```
208+
209+
**Required for good docs:**
210+
- Summary line (first line of docblock)
211+
- `@param` with type and description for each parameter
212+
- `@return` with type and description
213+
- `@since` version tag
214+
215+
**Optional but helpful:**
216+
- `@throws` for exceptions
217+
- `@see` for related symbols
218+
- `@deprecated` with replacement guidance
219+
- `@example` with code samples
220+
221+
### Viewing generation output
222+
223+
When you run `npm run api:generate`, you'll see output like:
224+
225+
```
226+
▶ Generating API docs: gravityview (GravityView)
227+
ℹ️ gravityview: limiting API to 102 symbols referenced in @see docblocks
228+
ℹ️ gravityview: added 11 classes from property types
229+
ℹ️ gravityview: added 11 classes and 15 functions from @see tags (3 iterations)
230+
⚠️ gravityview: 609 doc issues (missing summary: 130, missing @param: 125...)
231+
✅ gravityview: 64 classes, 5 functions
232+
```
233+
234+
- **Limiting API to N symbols** - How many symbols were found in hooks docs
235+
- **Added N classes from property types** - Classes found in typed properties
236+
- **Added N from @see tags (M iterations)** - Transitive expansion results
237+
- **Doc issues** - Missing summaries, parameters, or return types
238+
108239
## Project Structure
109240

110241
```
@@ -121,7 +252,9 @@ gravitykit.dev/
121252
│ └── ...
122253
├── scripts/
123254
│ ├── clone-repos.mjs # Clone/update GitHub repos
124-
│ └── regen-hooks-docs-new.mjs # Generate hooks documentation
255+
│ ├── generate-hooks.mjs # Generate hooks documentation
256+
│ ├── generate-php-api.mjs # Generate PHP API reference docs
257+
│ └── extract-php-api.php # PHP parser for class extraction
125258
├── src/
126259
│ ├── pages/ # Custom pages
127260
│ └── css/ # Styling

0 commit comments

Comments
 (0)