Skip to content

Commit

Permalink
Merge pull request #5 from flickerleap/feature-custom-sniffs
Browse files Browse the repository at this point in the history
Add custom sniffs
  • Loading branch information
phillipdebruin authored Sep 25, 2018
2 parents cc7e876 + 7e36769 commit f334db9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
File renamed without changes.
28 changes: 28 additions & 0 deletions src/Standards/Laravel/Sniffs/Convention/DisallowEnvUsageSniff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;

class DisallowEnvUsageSniff implements Sniff
{
public function register()
{
return [T_STRING];
}

public function process(File $phpcsFile, $stackPtr)
{
if(array_slice(explode('/',$phpcsFile->path), -2, 1)[0] == 'config') {
return;
}

$tokens = $phpcsFile->getTokens();

if ($tokens[$stackPtr]['content'] === 'env') {
$error = 'env function usage is prohibited, use the config function instead';
$data = array(trim($tokens[$stackPtr]['content']));
$phpcsFile->addError($error, $stackPtr, 'Found', $data);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
<ruleset name="FlickerLeapLaravel">
<description>FlickerLeap Laravel coding standard</description>

<rule ref="../ruleset.xml"/>
<rule ref="Flickerleap"/>

<rule ref="Laravel.Convention.DisallowEnvUsage"/>
</ruleset>

0 comments on commit f334db9

Please sign in to comment.