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

ValidTraitNameSniff   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 49
ccs 0
cts 16
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 5 1
A process() 0 14 3
1
<?php
2
/**
3
 * CodingStandard_Sniffs_NamingConventions_ValidTraitNameSniff.
4
 *
5
 * PHP version 5
6
 *
7
 * @category PHP
8
 * @package  PHP_CodeSniffer
9
 * @author   Symfony2-phpcs-authors <[email protected]>
10
 * @author   Alexander Obuhovich <[email protected]>
11
 * @license  https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause
12
 * @link     https://github.com/aik099/CodingStandard
13
 */
14
15
/**
16
 * CodingStandard_Sniffs_NamingConventions_ValidTraitNameSniff.
17
 *
18
 * Throws errors if trait names are not prefixed with "T".
19
 *
20
 * @category PHP
21
 * @package  PHP_CodeSniffer
22
 * @author   Alexander Obuhovich <[email protected]>
23
 * @license  https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause
24
 * @link     https://github.com/aik099/CodingStandard
25
 */
26
class CodingStandard_Sniffs_NamingConventions_ValidTraitNameSniff 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...
27
{
28
29
    /**
30
     * A list of tokenizers this sniff supports.
31
     *
32
     * @var array
33
     */
34
    public $supportedTokenizers = array('PHP');
35
36
37
    /**
38
     * Returns an array of tokens this test wants to listen for.
39
     *
40
     * @return integer[]
41
     */
42
    public function register()
43
    {
44
        return array(T_TRAIT);
45
46
    }//end register()
47
48
49
    /**
50
     * Processes this test, when one of its tokens is encountered.
51
     *
52
     * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
53
     * @param int                  $stackPtr  The position of the current token in
54
     *                                        the stack passed in $tokens.
55
     *
56
     * @return void
57
     */
58
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
59
    {
60
        $interfaceName = $phpcsFile->getDeclarationName($stackPtr);
61
        $firstLetter   = $interfaceName[0];
62
        $secondLetter  = $interfaceName[1];
63
64
        if ($firstLetter !== 'T' || $secondLetter === strtolower($secondLetter)) {
65
            $phpcsFile->addError(
66
                'Trait name is not prefixed with "T"',
67
                $stackPtr
68
            );
69
        }
70
71
    }//end process()
72
73
74
}//end class
75