WordPress / WordPress/phpdoc-parser
Add filter for skipping files earlier in the pipeline than 'wp_parser_pre_import_file'
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 239
- Forks
- 81
- Avg merge
- 16h 29m
- Merged PRs (30d)
- 8
Description
\\WP_Parser\Importer::import_file() provides the wp_parser_pre_import_file filter to skip importing a particular file.
It would improve efficiency if there were a similar filter earlier in the pipeline, e.g., in \\WP_Parser\get_wp_files(). For example,
function get_wp_files( $directory ) {
$iterableFiles = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator( $directory )
);
$files = array();
try {
foreach ( $iterableFiles as $file ) {
if ( 'php' !== $file->getExtension() ) {
continue;
}
if ( ! apply_filters( 'wp_parser_pre_get_wp_file', true, $file->getPathname(), $directory ) ) {
continue;
}
$files[] = $file->getPathname();
}
} catch ( \UnexpectedValueException $exc ) {
return new \WP_Error(
'unexpected_value_exception',
sprintf( 'Directory [%s] contained a directory we can not recurse into', $directory )
);
}
return $files;
}
I use this plugin to produce developer documentation for plugins/themes I create for clients, and currently hook into wp_parser_pre_import_file to skip importing anything in tests/ or vendor/ sub-dirs of a plugin/theme. Having the proposed wp_parser_pre_get_wp_file hook would allow avoiding the overhead of parsing all those files, only to skip them later in the pipeline.
Here is an example of a func I would hook into the proposed filter, to show why the proposed filter takes the additional $directory param that wp_parser_pre_import_file does not:
add_filter( 'wp_parser_pre_get_wp_file', 'shc_wp_parser_skip_files', 10, 3 );
function shc_wp_parser_skip_files( $default, $file, $directory ) {
$file = str_replace( $directory . DIRECTORY_SEPARATOR, '', $file );
$paths = explode( DIRECTORY_SEPARATOR, $file );
if ( in_array( $paths[1], array( 'tests', 'vendor' ) ) ) {
return false;
}
return $default;
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at WP_Parser\get_wp_files() and compare its file discovery flow with the existing wp_parser_pre_import_file filter in WP_Parser\Importer::import_file(). Add the earlier filter with the proposed file and directory arguments, and confirm that files rejected there are not parsed or imported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100