Skip to content
This repository has been archived by the owner on Jul 20, 2018. It is now read-only.

Commit

Permalink
Add ClassCheckVisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Dec 6, 2014
1 parent 2c0691b commit 271e67e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions vip-scanner/vip-scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

require_once( VIP_SCANNER_VISITORS_DIR . '/class-php-file-check-visitor.php' );
require_once( VIP_SCANNER_VISITORS_DIR . '/class-function-call-check-visitor.php' );
require_once( VIP_SCANNER_VISITORS_DIR . '/class-class-check-visitor.php' );


if ( is_admin() ) {
Expand Down
28 changes: 28 additions & 0 deletions vip-scanner/visitors/class-class-check-visitor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

class ClassCheckVisitor extends PhpFileCheckVisitor {
protected $checks = array();

function __construct( $checks ) {
$this->checks = $checks;
}

function process( PhpParser\Node $node ) {

if ( $node instanceof PhpParser\Node\Expr\New_ ) {
foreach ( $this->checks as $check => $check_info ) {
$this->increment_check_count();

if ( $node->class->toString() === $check ) {
$this->add_error(
$check,
// If no slug is specified, use the function's name as slug.
empty( $check_info['slug'] ) ? $check : $check_info['slug'],
$check_info['note'],
$check_info['level']
);
}
}
}
}
}

0 comments on commit 271e67e

Please sign in to comment.