Completed
Push — in-portal ( b7a6d3...d7c658 )
by Alexander
02:38
created

CodingStandard_Sniffs_Commenting_DocCommentSniff   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
ccs 0
cts 13
cp 0
wmc 4
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 18 4
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 31 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Ensures doc blocks follow basic formatting.
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
// @codeCoverageIgnoreStart
15
if (class_exists('Generic_Sniffs_Commenting_DocCommentSniff', true) === false) {
16
    $error = 'Class Generic_Sniffs_Commenting_DocCommentSniff not found';
17
    throw new PHP_CodeSniffer_Exception($error);
18
}
19
// @codeCoverageIgnoreEnd
20
21
/**
22
 * Ensures doc blocks follow basic formatting.
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
31
class CodingStandard_Sniffs_Commenting_DocCommentSniff extends Generic_Sniffs_Commenting_DocCommentSniff
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...
32
{
33
34
    /**
35
     * Processes this test, when one of its tokens is encountered.
36
     *
37
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
38
     * @param int                  $stackPtr  The position of the current token
39
     *                                        in the stack passed in $tokens.
40
     *
41
     * @return void
42
     */
43
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
44
    {
45
        $tokens       = $phpcsFile->getTokens();
46
        $commentEnd   = $phpcsFile->findNext(T_DOC_COMMENT_CLOSE_TAG, ($stackPtr + 1));
47
        $commentStart = $tokens[$commentEnd]['comment_opener'];
48
49
        if ($tokens[$commentStart]['line'] === $tokens[$commentEnd]['line']) {
50
            $commentText = $phpcsFile->getTokensAsString($commentStart, ($commentEnd - $commentStart + 1));
51
52
            if (strpos($commentText, '@var') !== false || strpos($commentText, '@type') !== false) {
53
                // Skip inline block comments with variable type definition.
54
                return;
55
            }
56
        }
57
58
        parent::process($phpcsFile, $stackPtr);
59
60
    }//end process()
61
62
63
}//end class
64