Skip to content

Commit

Permalink
Merge pull request #800 from WordPress/792-do-not-use-heredoc
Browse files Browse the repository at this point in the history
Disallow usage of HEREDOC and NOWDOC
  • Loading branch information
ernilambar authored Nov 24, 2024
2 parents c841bc3 + 1ffcb55 commit 78f9033
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions phpcs-rulesets/plugin-review.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<severity>7</severity>
</rule>

<!-- Prohibit the use of HEREDOC or NOWDOC. -->
<rule ref="Squiz.PHP.Heredoc">
<severity>7</severity>
</rule>

<!-- Prohibit the use of the `goto` PHP language construct. -->
<rule ref="Generic.PHP.DiscourageGoto.Found">
<type>error</type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@

query_posts( 'cat=3' );
wp_reset_query();

$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public function test_run_with_errors() {
$this->assertArrayHasKey( 'code', $errors['load.php'][6][1][0] );
$this->assertEquals( 'Generic.PHP.DisallowShortOpenTag.Found', $errors['load.php'][6][1][0]['code'] );

// Check for Squiz.PHP.Heredoc.NotAllowed error on Line no 28 and column no at 8.
$this->assertEquals( 'Squiz.PHP.Heredoc.NotAllowed', $errors['load.php'][28][8][0]['code'] );

// Check for WordPress.WP.DeprecatedFunctions.the_author_emailFound error on Line no 12 and column no at 5.
$this->assertArrayHasKey( 12, $errors['load.php'] );
$this->assertArrayHasKey( 5, $errors['load.php'][12] );
Expand Down

0 comments on commit 78f9033

Please sign in to comment.