Skip to content

Commit

Permalink
Merge pull request #46 from tighten/adc/fix-forbidden-functions
Browse files Browse the repository at this point in the history
Add custom `UseConfigOverEnv` sniff
  • Loading branch information
driftingly authored Oct 21, 2022
2 parents 9bfd9ed + b971086 commit 624cd35
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 12 additions & 0 deletions standards/Tighten/Sniffs/PHP/UseConfigOverEnvSniff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Tighten\Sniffs\PHP;

use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;

class UseConfigOverEnvSniff extends ForbiddenFunctionsSniff
{
public $forbiddenFunctions = [
'env' => 'config',
];
}
7 changes: 4 additions & 3 deletions standards/Tighten/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
</rule>

<!-- No compact() and no 'dumps' -->
<!-- Use config() over env() -->
<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="forbiddenFunctions" type="array">
Expand All @@ -57,10 +56,12 @@
<element key="dump" value="null"/>
<element key="var_dump" value="null"/>
<element key="ray" value="null"/>
<element key="env" value="config"/>
</property>
</properties>
<!-- This will also allow all other forbidden functions in confg directory -->
</rule>

<!-- Use config() over env() -->
<rule ref="Tighten.PHP.UseConfigOverEnv">
<exclude-pattern>/config/*</exclude-pattern>
</rule>

Expand Down

0 comments on commit 624cd35

Please sign in to comment.