Completed
Push — master ( 7cb383...bf8a98 )
by Alexander
02:20
created

process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 9
ccs 0
cts 8
cp 0
crap 6
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * CodingStandard_Sniffs_Files_OneTraitPerFileSniff.
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
/**
15
 * Checks that only one trait is declared per file.
16
 *
17
 * @category PHP
18
 * @package  PHP_CodeSniffer
19
 * @author   Alexander Obuhovich <[email protected]>
20
 * @license  https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause
21
 * @link     https://github.com/aik099/CodingStandard
22
 */
23
class CodingStandard_Sniffs_Files_OneTraitPerFileSniff implements PHP_CodeSniffer_Sniff
0 ignored issues
show
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
24
{
25
26
27
    /**
28
     * Returns an array of tokens this test wants to listen for.
29
     *
30
     * @return integer[]
31
     */
32
    public function register()
33
    {
34
        return array(T_TRAIT);
35
36
    }//end register()
37
38
39
    /**
40
     * Processes this sniff, when one of its tokens is encountered.
41
     *
42
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
43
     * @param int                  $stackPtr  The position of the current token in
44
     *                                        the stack passed in $tokens.
45
     *
46
     * @return void
47
     */
48
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
49
    {
50
        $nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1));
51
        if ($nextClass !== false) {
52
            $error = 'Only one trait is allowed in a file';
53
            $phpcsFile->addError($error, $nextClass, 'MultipleFound');
54
        }
55
56
    }//end process()
57
58
59
}//end class
60