diff --git a/vip-scanner/checks/DeprecatedParametersCheck.php b/vip-scanner/checks/DeprecatedParametersCheck.php
index 28952fb..575bb57 100644
--- a/vip-scanner/checks/DeprecatedParametersCheck.php
+++ b/vip-scanner/checks/DeprecatedParametersCheck.php
@@ -3,61 +3,52 @@
* Checks for deprecated parameters.
*/
-class DeprecatedParametersCheck extends BaseCheck {
+class DeprecatedParametersCheck extends CodeCheckVisitor {
- function check( $files ) {
- $result = true;
- $this->increment_check_count();
+ protected static $parameters = array(
+ 'get_bloginfo' => array(
+ 'home' => 'home_url()',
+ 'url' => 'home_url()',
+ 'wpurl' => 'site_url()',
+ 'stylesheet_directory' => 'get_stylesheet_directory_uri()',
+ 'template_directory' => 'get_template_directory_uri()',
+ 'template_url' => 'get_template_directory_uri()',
+ 'text_direction' => 'is_rtl()',
+ 'feed_url' => "get_feed_link( 'feed' ), where feed is rss, rss2 or atom",
+ ),
+ 'bloginfo' => array(
+ 'home' => 'echo esc_url( home_url() )',
+ 'url' => 'echo esc_url( home_url() )',
+ 'wpurl' => 'echo esc_url( site_url() )',
+ 'stylesheet_directory' => 'echo esc_url( get_stylesheet_directory_uri() )',
+ 'template_directory' => 'echo esc_url( get_template_directory_uri() )',
+ 'template_url' => 'echo esc_url( get_template_directory_uri() )',
+ 'text_direction' => 'is_rtl()',
+ 'feed_url' => "echo esc_url( get_feed_link( 'feed' ) ), where feed is rss, rss2 or atom",
+ ),
+ 'get_option' => array(
+ 'home' => 'home_url()',
+ 'site_url' => 'site_url()',
+ )
+ );
- $checks = array(
- 'get_bloginfo' => array(
- 'home' => 'home_url()',
- 'url' => 'home_url()',
- 'wpurl' => 'site_url()',
- 'stylesheet_directory' => 'get_stylesheet_directory_uri()',
- 'template_directory' => 'get_template_directory_uri()',
- 'template_url' => 'get_template_directory_uri()',
- 'text_direction' => 'is_rtl()',
- 'feed_url' => "get_feed_link( 'feed' ), where feed is rss, rss2 or atom",
- ),
- 'bloginfo' => array(
- 'home' => 'echo esc_url( home_url() )',
- 'url' => 'echo esc_url( home_url() )',
- 'wpurl' => 'echo esc_url( site_url() )',
- 'stylesheet_directory' => 'echo esc_url( get_stylesheet_directory_uri() )',
- 'template_directory' => 'echo esc_url( get_template_directory_uri() )',
- 'template_url' => 'echo esc_url( get_template_directory_uri() )',
- 'text_direction' => 'is_rtl()',
- 'feed_url' => "echo esc_url( get_feed_link( 'feed' ) ), where feed is rss, rss2 or atom",
- ),
- 'get_option' => array(
- 'home' => 'home_url()',
- 'site_url' => 'site_url()',
- )
- );
-
- foreach ( $this->filter_files( $files, 'php' ) as $file_path => $file_content ) {
-
- // Loop through all functions.
- foreach ( $checks as $function => $data ) {
-
- // Loop through the parameters and look for all function/parameter combinations.
- foreach ( $data as $parameter => $replacement ) {
-
- if ( preg_match( '/' . $function . '\(\s*("|\')' . $parameter . '("|\')\s*\)/', $file_content, $matches ) ) {
- $error = trim( rtrim( $matches[0], '(' ) );
+ function check( PhpParser\Node $node ) {
+ if ( $node instanceof PhpParser\Node\Expr\FuncCall ) {
+ $name = $node->name->toString();
+ if ( array_key_exists( $name, self::$parameters ) ) {
+ $pars = self::$parameters[ $name ];
+ if ( ! empty( $node->args ) ) {
+ $value = $node->args[0]->value;
+ if ( $value instanceof PhpParser\Node\Scalar\String && array_key_exists( $value->value, $pars ) ) {
+ $message = 'The deprecated function parameter %1$s was found. Use %2$s instead.';
$this->add_error(
'deprecated',
- 'The deprecated function parameter ' . esc_html( $error ) . '
was found. Use ' . esc_html( $replacement ) . '
instead.',
- BaseScanner::LEVEL_BLOCKER,
- $this->get_filename( $file_path )
+ sprintf( $message, '' . esc_html( $name . "( '" . $value->value . "' )" ) . '
' , '' . esc_html( $pars[ $value->value ] ) . '
' ),
+ BaseScanner::LEVEL_BLOCKER
);
- $result = false;
}
}
}
}
-
- return $result;
}
}