Skip to content

Commit

Permalink
Merge pull request #837 from WordPress/add-sniff-rules
Browse files Browse the repository at this point in the history
Add sniff rules related to Byte Order Mark and Call-time Pass by Reference
  • Loading branch information
ernilambar authored Dec 17, 2024
2 parents 1f446de + 6316c54 commit 012db17
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions phpcs-rulesets/plugin-review.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@
<severity>7</severity>
</rule>

<!-- No ByteOrderMark allowed - important to prevent issues with content being sent before headers. -->
<rule ref="Generic.Files.ByteOrderMark">
<severity>7</severity>
</rule>

<!-- Call-time pass-by-reference has been deprecated since PHP 5.3 and should not be used. -->
<rule ref="Generic.Functions.CallTimePassByReference">
<severity>7</severity>
</rule>

<!-- Check for missing required function parameters. -->
<rule ref="PluginCheck.CodeAnalysis.RequiredFunctionParameters">
<severity>7</severity>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
echo 'foo';
?>
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@

$encoded_value = json_encode( array( 'key' => 'value' ) );

custom_function(&$myvar);
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function test_run_with_errors() {

$this->assertNotEmpty( $errors );
$this->assertArrayHasKey( 'load.php', $errors );
$this->assertArrayHasKey( 'file-with-bom.php', $errors );
$this->assertNotEmpty( $warnings );
$this->assertArrayHasKey( 'load.php', $warnings );

Expand All @@ -44,6 +45,12 @@ public function test_run_with_errors() {
// Check for PluginCheck.CodeAnalysis.RequiredFunctionParameters.parse_str_resultMissing error on Line no 34 and column no at 1.
$this->assertSame( 'PluginCheck.CodeAnalysis.RequiredFunctionParameters.parse_str_resultMissing', $errors['load.php'][34][1][0]['code'] );

// Check for Generic.Functions.CallTimePassByReference.NotAllowed error on Line no 38 and column no 16.
$this->assertSame( 'Generic.Functions.CallTimePassByReference.NotAllowed', $errors['load.php'][38][16][0]['code'] );

// Check for Generic.Files.ByteOrderMark.Found error on Line no 1 and column no 1.
$this->assertSame( 'Generic.Files.ByteOrderMark.Found', $errors['file-with-bom.php'][1][1][0]['code'] );

// There should not be WordPress.WP.AlternativeFunctions.json_encode_json_encode error on Line no 36 and column no at 18.
$this->assertCount( 0, wp_list_filter( $errors['load.php'][36][18], array( 'code' => 'WordPress.WP.AlternativeFunctions.json_encode_json_encode' ) ) );

Expand Down

0 comments on commit 012db17

Please sign in to comment.