-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDisallowAlternativeSyntaxSniff.php
More file actions
65 lines (60 loc) · 1.37 KB
/
DisallowAlternativeSyntaxSniff.php
File metadata and controls
65 lines (60 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Eightshift coding standards for WordPress
*
* @package EightshiftCS
*
* @author Eightshift <team.wordpress@infinum.com>
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/infinum/eightshift-coding-standards
*/
namespace EightshiftCS\Eightshift\Sniffs\ControlStructures;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
/**
* Disallows alternative control structure syntax.
*
* Enforces the use of curly braces for all control structures.
* Alternative syntax keywords (endif, endforeach, endfor, endwhile, endswitch)
* are not allowed.
*
* @since 2.1.0
*/
class DisallowAlternativeSyntaxSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
*
* @since 2.1.0
*
* @return array
*/
public function register()
{
return [
\T_ENDIF,
\T_ENDFOREACH,
\T_ENDFOR,
\T_ENDWHILE,
\T_ENDSWITCH,
];
}
/**
* Processes this test when one of its tokens is encountered.
*
* @since 2.1.0
*
* @param File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the stack.
*
* @return void
*/
public function process(File $phpcsFile, $stackPtr)
{
$phpcsFile->addError(
'Alternative control structure syntax is not allowed; use curly braces instead.',
$stackPtr,
'FoundAlternativeSyntax'
);
}
}