- Code elements – syntactical parts of the PHP language, like namespaces, functions, classes (and contained methods), variables, etc.
- Resources – things like scripts, styles, filters, actions, taxonomies, capabilities, etc.
- Elements – code elements and resources.
- Analyzer – gathers structural information about a theme, i.e. produces a survey of its elements.
- Renderer – turns data obtained from an element into HTML or terminal output.
- Abstract Syntax Tree (AST) – tree representation of the abstract syntactic structure of a source code file.
- Visitor – object with a function that is invoked with every node in a tree when traversing it.
- Scanner – runs a list of checks on a theme.
- Check – checks for the presence of a specific error in a file, and reports it.
- There are currently three scan types available: 'Undefined Function Check', 'WP.com Theme Review', or 'VIP Theme Review', each of which is associated with a list of checks and analyzers (cf. Glossary).
- There are two ways to invoke VIP-scanner:
- It can be run from the corresponding WordPress admin page (in the 'Tools'
section). That admin page is added by
class VIP_Scanner_UI
(found invip-scanner.php
in the plugin's root directory). When the user clicks the 'Scan' button, its class methoddo_theme_review()
is invoked to generate the results for the scan type selected by the user. - It can be run as a WP-CLI command, i.e.
wp vip-scanner
. In this case, aVIPScanner_Command
(vip-scanner/class-wp-cli.php) instance is constructed, and depending on the subcommand invoked, either itsscan_theme()
or itsanalyze_theme()
method is called.
- It can be run from the corresponding WordPress admin page (in the 'Tools'
section). That admin page is added by
- Either way, an instance of
VIP_Scanner
(vip-scanner/vip-scanner.php) is then used to call itsrun_theme_review()
method.VIP_Scanner::run_theme_review()
creates an instance ofThemeScanner
(vip-scanner/scanners/class-theme-scanner.php) for the given review type.ThemeScanner
extendsDirectoryScanner
, which is used to collect all files within the theme's directory for scrutiny.DirectoryScanner
extendsBaseScanner
, which is at the core of VIP-scanner: Upon construction, it groups files by their type (like 'php', 'css', or 'html', etc.).- When its
scan
method is invoked,run_scanners()
is called.AnalyzedPHPFile
(vip-scanner/class-analyzed-php-file.php) andAnalyzedCSSFile
(vip-scanner/class-analyzed-css-file.php) objects are created for the 'php' and 'css' types, respectively.- Upon construction,
AnalyzedPHPFile
uses PHP-Parser to parse PHP files, yielding an AST, which can be accessed usingAnalyzedPHPFile::get_node_tree()
. Most information required by analyzers and scanners is readily available from the AST's nodes. - To add some more required information to the nodes, the tree is traversed, and a number of node visitors are run on each node.
- Upon construction,
- The scanner's
run_scanners()
method then iterates over the checks and analyzers associated with the selected scan type.- Files (names and contents) are passed to the check's
check()
method. Any errors found by the checks are obtained via theget_results()
class method inherited fromBaseCheck
(vip-scanner/class-base-check.php), and appended to the scanner's publicerrors
member, while the number of checks performed is added to itstotal_checks
member. - The pre-analyzed files (i.e.
AnalyzedPHPFile
andAnalyzedCSSFile
objects) are passed to the analyzer'sanalyze()
method. The analyzer then creates a set of corresponding elements (see below), which are obtained via itsget_elements()
method, and added to the scanner's publicelements
member, while statistics are obtained viaget_stats()
and appended to thestats
member.CodeAnalyzer
creates an object of a subclass ofCodeElement
for each relevant code element in the AST obtained fromAnalyzedPHPFile::get_node_tree()
. TheCodeElement
objects extract relevant information from the AST nodes to make it available in a form suitable for the renderer, i.e. via their public methods, e.g.get_header()
,get_child_summary()
,get_attributes()
,get_stats()
, etc.CodeElement
objects can be recursive: for example, aClassCodeElement
can contain any number ofMethodCodeElement
s. ACodeElement
's children can be obtained via itsget_children()
method.ResourceAnalyzer
createsResourceCodeElement
s for WordPress-specific resources (see glossary), which analyze the corresponding function calls (such asadd_filter()
,wp_enqueue_script()
, etc.) found in the AST.ThemeAnalyzer
adds information found in the themes CSS file, such as the name of the parent theme (if any).
- Files (names and contents) are passed to the check's
- When its
VIP_Scanner::run_theme_review()
returns theThemeScanner
instance.
- The scanner's properties are rendered for display:
- In the
VIP_Scanner_UI
class, thedisplay_theme_review_results()
displays the errors found by the checks. It then loops through the analyzers' elements, whose data are rendered into HTML by passing them toElementRenderer
(vip-scanner/renderers/class-element-renderer.php), whosedisplay()
method is eventually called. - In case of the
VIPScanner_Command
, scanner properties are formatted for terminal output. In case of the elements, the renderer'sdisplay()
method is called with an additional parameter indicating 'bare' (as opposed to HTML) output.
- In the
Analyzers, elements, renderers, visitors, scanners, and checks are found in the eponymous subdirectories of the vip-scanner directory (except for some stray base classes which are in the vip-scanner directory itself).