Skip to content

Bump VariableAnalysis to 2.9.0 to allow use of the backported options #120

Closed
@GaryJones

Description

What problem would the enhancement address for VIP?

When template partials are require'd from within a class, then the partial may use $this->... to insert display a value. At PHP runtime, it works, but for PHPCS analysis, it sees a PHP file with an undefined $this and so reports it via the VariableAnalysis package. Technically it's correct, and while it could be ignored, it's not practical or desirable to do that.

Describe the solution you'd like

VariableAnalysis 2.9.0 includes two new options that can control whether these violations are raised.

VIPCS already requires ^2.8.3, so the code analysis bot could simply pull in the updated version of VA without changes to VIPCS.

Both options could then be set in the config when looking at code.

What code should be reported as a violation?

What code should not be reported as a violation?

Don't report on $this:

<?php
// Example foo.php template.

if ( ! empty( $this->vars['video-id'] ) ) {
	echo '<video...></video>';
}

Don't report on $args (new feature in WP 5.5):

<?php
// Example foo.php template.
 
// Set defaults.
$args = wp_parse_args(
    $args,
    array(
        'class'          => '',
        'arbitrary_data' => array(
            'foo' => 'fooval',
            'bar' => false,
        ),
        ...
    )
);
?>
 
<div class="widget <?php echo esc_html_class( $args['class'] ); ?>">
    <?php echo esc_html( $args['arbitrary_data']['foo'] ); ?>
</div>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions