Completed
Push — master ( 906394...0d82de )
by Alexander
02:07
created

register()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4286
cc 1
eloc 2
nc 1
nop 0
crap 2
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
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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