Completed
Push — in-portal ( 542489...3b6de0 )
by Alexander
04:02
created

NoSpaceAfterBooleanNotSniff   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A process() 0 14 3
1
<?php
2
/**
3
 * CodingStandard_Sniffs_Formatting_NoSpaceAfterBooleanNotSniff.
4
 *
5
 * PHP version 5
6
 *
7
 * @category PHP
8
 * @package  PHP_CodeSniffer
9
 * @author   Alexander Obuhovich <[email protected]>
10
 * @license  https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause
11
 * @link     https://github.com/aik099/CodingStandard
12
 */
13
14
namespace CodingStandard\Sniffs\Formatting;
15
16
use PHP_CodeSniffer\Files\File;
17
use PHP_CodeSniffer\Sniffs\Sniff;
18
19
/**
20
 * CodingStandard_Sniffs_Formatting_NoSpaceAfterBooleanNotSniff.
21
 *
22
 * Ensures there is no space after boolean not operator.
23
 *
24
 * @category PHP
25
 * @package  PHP_CodeSniffer
26
 * @author   Alexander Obuhovich <[email protected]>
27
 * @license  https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause
28
 * @link     https://github.com/aik099/CodingStandard
29
 */
30
class NoSpaceAfterBooleanNotSniff implements Sniff
31
{
32
33
34
    /**
35
     * Returns an array of tokens this test wants to listen for.
36
     *
37
     * @return array
38
     */
39 1
    public function register()
40
    {
41 1
        return array(T_BOOLEAN_NOT);
42
    }//end register()
43
44
45
    /**
46
     * Processes this test, when one of its tokens is encountered.
47
     *
48
     * @param File $phpcsFile The file being scanned.
49
     * @param int  $stackPtr  The position of the current token in the
50
     *                        stack passed in $tokens.
51
     *
52
     * @return void
53
     */
54 1
    public function process(File $phpcsFile, $stackPtr)
55
    {
56 1
        $tokens = $phpcsFile->getTokens();
57
58 1
        if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
59 1
            return;
60
        }
61
62 1
        $error = 'A boolean not operator must not be followed by a space';
63 1
        $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceFound');
64 1
        if ($fix === true) {
65 1
            $phpcsFile->fixer->replaceToken(($stackPtr + 1), '');
66 1
        }
67 1
    }//end process()
68
}//end class
69