Skip to Content

todo_search_files()

Actually search theme files for @todo comments.

PHP April 13, 2017

Usage

PHP
nebula()->todo_search_files($todo_dirpath, $child)

Parameters

$todo_dirpath
(Optional) (String) The directory path to search
Default: None

$child
(Optional) (Boolean) Whether to search child theme
Default: false

Request or provide clarification »

Additional Notes

This function shouldn’t ever need to be called manually.

Source File

Located in /libs/Admin/Dashboard.php on line 550.

No Hooks

This function does not have any filters or actions available. Request one?

Note: This function contains 4 to-do comments.

PHP
        public function todo_search_files($directory=null){
            //@todo "Nebula" 0: Use null coalescing operator here
            if ( empty($directory) ){
                $directory = get_template_directory();
            }

            ini_set('memory_limit', '512M'); //@todo Nebula 0: Remove these when possible...

            $these_todos = array();
            foreach ( $this->glob_r($directory . '/*') as $todo_file ){
                if ( is_file($todo_file) ){
                    $todo_skipFilenames = array('README.md', 'debug_log', 'error_log', '/vendor', 'resources/'); //Skip certain filepaths and file names (more file extensions are skipped separately)

                    if ( !$this->contains($todo_file, $this->skip_extensions()) && !$this->contains($todo_file, $todo_skipFilenames) ){ //Skip certain extensions and filenames
                        foreach ( file($todo_file) as $todo_lineNumber => $todo_line ){ //@todo "Nebula" 0: How can we reduce the memory usage of this?
                            preg_match("/(@todo)\s?(?'category'[\"\'\`].+?[\"\'\`])?\s?(?'priority'\d)?:\s(?'description'.+)/i", $todo_line, $todo_details); //Separate the todo comment into useable groups

                            if ( !empty($todo_details) ){
                                $these_todos[] = array(
                                    'directory' => $directory,
                                    'filepath' => $todo_file,
                                    'line_number' => $todo_lineNumber,
                                    'line' => trim(htmlentities($todo_line)),
                                    'priority' => ( $todo_details['priority'] === '' )? 'empty' : intval($todo_details['priority']),
                                    'category' => ( !empty($todo_details['category']) )? str_replace(array('"', "'", '`'), '', $todo_details['category']) : '',
                                    'description' => strip_tags(str_replace(array('-->', '?>', '*/'), '', $todo_details['description'])),
                                );
                            }
                        }
                    }
                }
            }

            return $these_todos;
        }

Override

This function can not be short-circuited with an override filter. Request one?