This repository has been archived by the owner on Jul 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Base VIPRestrictedClassesCheck on ClassCheckVisitor, and modify test …
…accordingly
- Loading branch information
Showing
3 changed files
with
16 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
<?php | ||
|
||
require_once( 'CheckTestBase.php' ); | ||
require_once( 'PhpFileCheckTestBase.php' ); | ||
|
||
class VIPRestrictedClassesTest extends CheckTestBase { | ||
class VIPRestrictedClassesTest extends PhpFileCheckTestBase { | ||
|
||
public function testWPClasses() { | ||
$class_name = 'WP_User_Query'; | ||
|
||
$file_contents = '<?php $dummy = new ' . $class_name . '( $args )'; | ||
|
||
$error_slugs = $this->runCheck( $file_contents ); | ||
|
||
$this->assertContains( $class_name, $error_slugs ); | ||
public function expectedErrors() { | ||
return array( | ||
array( 3, 'WP_User_Query', 'Note', 'Use of WP_User_Query' ), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
$dummy = new WP_User_Query( $args ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,13 @@ | ||
<?php | ||
|
||
class VIPRestrictedClassesCheck extends BaseCheck | ||
class VIPRestrictedClassesCheck extends ClassCheckVisitor | ||
{ | ||
function check( $files ) { | ||
$result = true; | ||
|
||
$class_names = array( | ||
// WordPress Classes | ||
"WP_User_Query" => array( 'level' => "Note", "note" => "Use of WP_User_Query" ), | ||
function __construct() { | ||
parent::__construct( | ||
array( | ||
// WordPress Classes | ||
"WP_User_Query" => array( 'level' => "Note", "note" => "Use of WP_User_Query" ), | ||
) | ||
); | ||
|
||
|
||
foreach ( $this->filter_files( $files, 'php' ) as $file_path => $file_content ) { | ||
foreach ( $class_names as $class_name => $check_info ) { | ||
$this->increment_check_count(); | ||
|
||
if ( strpos( $file_content, $class_name ) !== false ) { | ||
$pattern = "/\s+($class_name)+\s?\(+/msiU"; | ||
|
||
if ( preg_match( $pattern, $file_content, $matches ) ) { | ||
$filename = $this->get_filename( $file_path ); | ||
|
||
$lines = $this->grep_content( rtrim( $matches[0], '(' ), $file_content ); | ||
|
||
$this->add_error( | ||
$class_name, | ||
$check_info['note'], | ||
$check_info['level'], | ||
$filename, | ||
$lines | ||
); | ||
|
||
$result = false; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} |