-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from flickerleap/feature-custom-sniffs
Add custom sniffs
- Loading branch information
Showing
3 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
28 changes: 28 additions & 0 deletions
28
src/Standards/Laravel/Sniffs/Convention/DisallowEnvUsageSniff.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters