Skip to content

Commit

Permalink
Merge pull request #637 from WordPress/587-discouraged-functions
Browse files Browse the repository at this point in the history
Add discouraged PHP functions
  • Loading branch information
davidperezgar authored Sep 17, 2024
2 parents 8af2297 + bd419dd commit 030ac2e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
11 changes: 9 additions & 2 deletions phpcs-rulesets/plugin-review.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,21 @@
<element key="create_function" value="null"/>
<element key="eval" value="null"/>
<element key="str_rot13" value="null"/>
</property>
</properties>
<type>error</type>
<severity>7</severity>
</rule>

<rule ref="Squiz.PHP.DiscouragedFunctions">
<properties>
<property name="forbiddenFunctions" type="array">
<element key="set_time_limit" value="null"/>
<element key="ini_set" value="null"/>
<element key="ini_alter" value="null"/>
<element key="dl" value="null"/>
</property>
</properties>
<type>error</type>
<severity>7</severity>
</rule>

<!-- Check for use of deprecated WordPress classes, functions and function parameters. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public function test_run_with_errors() {

$plugin_review_phpcs_check->run( $check_result );

$errors = $check_result->get_errors();
$errors = $check_result->get_errors();
$warnings = $check_result->get_warnings();

$this->assertNotEmpty( $errors );
$this->assertArrayHasKey( 'load.php', $errors );
$this->assertEquals( 9, $check_result->get_error_count() );
$this->assertNotEmpty( $warnings );
$this->assertArrayHasKey( 'load.php', $warnings );

// Check for Generic.PHP.DisallowShortOpenTag.Found error on Line no 6 and column no at 1.
$this->assertArrayHasKey( 6, $errors['load.php'] );
Expand All @@ -42,29 +44,17 @@ public function test_run_with_errors() {
$this->assertArrayHasKey( 'code', $errors['load.php'][15][27][0] );
$this->assertEquals( 'WordPress.Security.ValidatedSanitizedInput.InputNotValidated', $errors['load.php'][15][27][0]['code'] );

// Check for WordPress.Security.Generic.PHP.ForbiddenFunctions.Found error on Line no 17 and column no at 1.
$this->assertArrayHasKey( 17, $errors['load.php'] );
$this->assertArrayHasKey( 1, $errors['load.php'][17] );
$this->assertArrayHasKey( 'code', $errors['load.php'][17][1][0] );
$this->assertEquals( 'Generic.PHP.ForbiddenFunctions.Found', $errors['load.php'][17][1][0]['code'] );

// Check for WordPress.Security.Generic.PHP.ForbiddenFunctions.Found error on Line no 18 and column no at 1.
$this->assertArrayHasKey( 18, $errors['load.php'] );
$this->assertArrayHasKey( 1, $errors['load.php'][18] );
$this->assertArrayHasKey( 'code', $errors['load.php'][18][1][0] );
$this->assertEquals( 'Generic.PHP.ForbiddenFunctions.Found', $errors['load.php'][18][1][0]['code'] );

// Check for WordPress.Security.Generic.PHP.ForbiddenFunctions.Found error on Line no 19 and column no at 1.
$this->assertArrayHasKey( 19, $errors['load.php'] );
$this->assertArrayHasKey( 1, $errors['load.php'][19] );
$this->assertArrayHasKey( 'code', $errors['load.php'][19][1][0] );
$this->assertEquals( 'Generic.PHP.ForbiddenFunctions.Found', $errors['load.php'][19][1][0]['code'] );

// Check for WordPress.Security.Generic.PHP.ForbiddenFunctions.Found error on Line no 20 and column no at 1.
$this->assertArrayHasKey( 20, $errors['load.php'] );
$this->assertArrayHasKey( 1, $errors['load.php'][20] );
$this->assertArrayHasKey( 'code', $errors['load.php'][20][1][0] );
$this->assertEquals( 'Generic.PHP.ForbiddenFunctions.Found', $errors['load.php'][20][1][0]['code'] );
// Check for Squiz.PHP.DiscouragedFunctions.Discouraged warning on Line no 17 and column no at 1.
$this->assertSame( 'Squiz.PHP.DiscouragedFunctions.Discouraged', $warnings['load.php'][17][1][0]['code'] );

// Check for Squiz.PHP.DiscouragedFunctions.Discouraged warning on Line no 18 and column no at 1.
$this->assertSame( 'Squiz.PHP.DiscouragedFunctions.Discouraged', $warnings['load.php'][18][1][0]['code'] );

// Check for Squiz.PHP.DiscouragedFunctions.Discouraged warning on Line no 19 and column no at 1.
$this->assertSame( 'Squiz.PHP.DiscouragedFunctions.Discouraged', $warnings['load.php'][19][1][0]['code'] );

// Check for Squiz.PHP.DiscouragedFunctions.Discouraged warning on Line no 20 and column no at 1.
$this->assertSame( 'Squiz.PHP.DiscouragedFunctions.Discouraged', $warnings['load.php'][20][1][0]['code'] );
}

public function test_run_without_errors() {
Expand Down

0 comments on commit 030ac2e

Please sign in to comment.