Skip to content

Commit ef46e2b

Browse files
Maximilian GroschMaximilian Grosch
authored andcommitted
Merge pull request #2 in CFA/coding-guidelines from NO_GOTO_NOR_EVAL to master
* commit 'd4f52cf72e64840f611a3db735d5a3d460fe2fa6': goto or eval is forbidden
2 parents 9714edf + d4f52cf commit ef46e2b

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace flyeralarm\CodingGuidelines\Flyeralarm\Sniffs\File;
4+
5+
use PHP_CodeSniffer\Sniffs\Sniff;
6+
use PHP_CodeSniffer\Files\File;
7+
8+
class ForbiddenKeywordsSniff implements Sniff
9+
{
10+
/**
11+
* @return array
12+
*/
13+
public function register()
14+
{
15+
return array(T_CLASS, T_ABSTRACT, T_TRAIT);
16+
}
17+
18+
/**
19+
* @param File $phpcsFile
20+
* @param int $stackPtr
21+
* @return void
22+
*/
23+
public function process(File $phpcsFile, $stackPtr)
24+
{
25+
if ($phpcsFile->findNext(T_GOTO, 0)) {
26+
$phpcsFile->addError(
27+
'GOTO is not allowed',
28+
$stackPtr,
29+
'ForbiddenKeyword'
30+
);
31+
}
32+
33+
if ($phpcsFile->findNext(T_EVAL, 0)) {
34+
$phpcsFile->addError(
35+
'EVAL is not allowed',
36+
$stackPtr,
37+
'ForbiddenKeyword'
38+
);
39+
}
40+
}
41+
}

ruleset.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
88
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
99
<rule ref="./custom-standards/Flyeralarm/Sniffs/File/ExceptionMessageSniff.php"/>
10+
<rule ref="./custom-standards/Flyeralarm/Sniffs/File/ForbiddenKeywordsSniff.php"/>
1011
<rule ref="./custom-standards/Flyeralarm/Sniffs/File/NoClassKindSuffixSniff.php"/>
1112
<rule ref="./custom-standards/Flyeralarm/Sniffs/Docblock/ReturnTypeSniff.php"/>
1213
</ruleset>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
// @expectedError EVAL is not allowed
3+
4+
class ClassWithEval
5+
{
6+
public function foo()
7+
{
8+
eval(1 + 1);
9+
}
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
// @expectedError GOTO is not allowed
3+
4+
class ClassWithGoto
5+
{
6+
public function foo()
7+
{
8+
goto foo;
9+
10+
foo:
11+
return;
12+
}
13+
}

0 commit comments

Comments
 (0)