Completed
Push — master ( b79486...df4d3f )
by Alexander
02:06
created

process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
ccs 9
cts 9
cp 1
crap 2
1
<?php
2
/**
3
 * CodingStandard_Sniffs_Classes_ClassNamespaceSniff.
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
 * Class Namespace Test.
16
 *
17
 * Checks the that of the class is namespaced.
18
 *
19
 * @category PHP
20
 * @package  PHP_CodeSniffer
21
 * @author   Alexander Obuhovich <[email protected]>
22
 * @license  https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause
23
 * @link     https://github.com/aik099/CodingStandard
24
 */
25
class CodingStandard_Sniffs_Classes_ClassNamespaceSniff 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...
26
{
27
28
29
    /**
30
     * Returns an array of tokens this test wants to listen for.
31
     *
32
     * @return array
33
     */
34 1
    public function register()
35
    {
36
        // @codeCoverageIgnoreStart
37
        if (version_compare(PHP_VERSION, '5.3.0') < 0) {
38
            return array();
39
        }
40
        // @codeCoverageIgnoreEnd
41
42
        return array(
43 1
                T_CLASS,
44 1
                T_INTERFACE,
45 1
                T_TRAIT,
46 1
               );
47
48
    }//end register()
49
50
51
    /**
52
     * Processes this test, when one of its tokens is encountered.
53
     *
54
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
55
     * @param integer              $stackPtr  The position of the current token in the
56
     *                                        stack passed in $tokens.
57
     *
58
     * @return void
59
     */
60 1
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
61
    {
62 1
        $tokens    = $phpcsFile->getTokens();
63 1
        $namespace = $phpcsFile->findPrevious(T_NAMESPACE, ($stackPtr - 1));
64
65 1
        if ($namespace === false) {
66 1
            $error = 'Each %s must be in a namespace of at least one level (a top-level vendor name)';
67 1
            $data  = array($tokens[$stackPtr]['content']);
68 1
            $phpcsFile->addError($error, $stackPtr, 'MissingNamespace', $data);
69 1
        }
70
71 1
    }//end process()
72
73
74
}//end class
75