• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHPCSStandards / PHP_CodeSniffer / 18114150721

30 Sep 2025 12:00AM UTC coverage: 78.601% (-0.6%) from 79.178%
18114150721

push

github

web-flow
Merge pull request #1284 from PHPCSStandards/dependabot/github_actions/3.x/action-runners-f175f89d6c

GH Actions: Bump actions/cache from 4.2.4 to 4.3.0 in the action-runners group

25341 of 32240 relevant lines covered (78.6%)

74.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.72
/src/Standards/MySource/Sniffs/Commenting/FunctionCommentSniff.php
1
<?php
2
/**
3
 * Parses and verifies the doc comments for functions.
4
 *
5
 * Same as the Squiz standard, but adds support for API tags.
6
 *
7
 * @author    Greg Sherwood <gsherwood@squiz.net>
8
 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
9
 * @license   https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/HEAD/licence.txt BSD Licence
10
 *
11
 * @deprecated 3.9.0
12
 */
13

14
namespace PHP_CodeSniffer\Standards\MySource\Sniffs\Commenting;
15

16
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
17
use PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\FunctionCommentSniff as SquizFunctionCommentSniff;
18
use PHP_CodeSniffer\Util\Tokens;
19
use PHP_CodeSniffer\Files\File;
20

21
class FunctionCommentSniff extends SquizFunctionCommentSniff implements DeprecatedSniff
22
{
23

24

25
    /**
26
     * Processes this test, when one of its tokens is encountered.
27
     *
28
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
29
     * @param int                         $stackPtr  The position of the current token
30
     *                                               in the stack passed in $tokens.
31
     *
32
     * @return void
33
     */
34
    public function process(File $phpcsFile, $stackPtr)
3✔
35
    {
36
        parent::process($phpcsFile, $stackPtr);
3✔
37

38
        $tokens = $phpcsFile->getTokens();
3✔
39
        $find   = Tokens::$methodPrefixes;
3✔
40
        $find[] = T_WHITESPACE;
3✔
41

42
        $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true);
3✔
43
        if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG) {
3✔
44
            return;
×
45
        }
46

47
        $commentStart = $tokens[$commentEnd]['comment_opener'];
3✔
48
        $hasApiTag    = false;
3✔
49
        foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
3✔
50
            if ($tokens[$tag]['content'] === '@api') {
3✔
51
                if ($hasApiTag === true) {
3✔
52
                    // We've come across an API tag already, which means
53
                    // we were not the first tag in the API list.
54
                    $error = 'The @api tag must come first in the @api tag list in a function comment';
3✔
55
                    $phpcsFile->addError($error, $tag, 'ApiNotFirst');
3✔
56
                }
1✔
57

58
                $hasApiTag = true;
3✔
59

60
                // There needs to be a blank line before the @api tag.
61
                $prev = $phpcsFile->findPrevious([T_DOC_COMMENT_STRING, T_DOC_COMMENT_TAG], ($tag - 1));
3✔
62
                if ($tokens[$prev]['line'] !== ($tokens[$tag]['line'] - 2)) {
3✔
63
                    $error = 'There must be one blank line before the @api tag in a function comment';
3✔
64
                    $phpcsFile->addError($error, $tag, 'ApiSpacing');
3✔
65
                }
1✔
66
            } else if (substr($tokens[$tag]['content'], 0, 5) === '@api-') {
3✔
67
                $hasApiTag = true;
3✔
68

69
                $prev = $phpcsFile->findPrevious([T_DOC_COMMENT_STRING, T_DOC_COMMENT_TAG], ($tag - 1));
3✔
70
                if ($tokens[$prev]['line'] !== ($tokens[$tag]['line'] - 1)) {
3✔
71
                    $error = 'There must be no blank line before the @%s tag in a function comment';
3✔
72
                    $data  = [$tokens[$tag]['content']];
3✔
73
                    $phpcsFile->addError($error, $tag, 'ApiTagSpacing', $data);
3✔
74
                }
1✔
75
            }//end if
1✔
76
        }//end foreach
1✔
77

78
        if ($hasApiTag === true && substr($tokens[$tag]['content'], 0, 4) !== '@api') {
3✔
79
            // API tags must be the last tags in a function comment.
80
            $error = 'The @api tags must be the last tags in a function comment';
3✔
81
            $phpcsFile->addError($error, $commentEnd, 'ApiNotLast');
3✔
82
        }
1✔
83

84
    }//end process()
2✔
85

86

87
    /**
88
     * Provide the version number in which the sniff was deprecated.
89
     *
90
     * @return string
91
     */
92
    public function getDeprecationVersion()
×
93
    {
94
        return 'v3.9.0';
×
95

96
    }//end getDeprecationVersion()
97

98

99
    /**
100
     * Provide the version number in which the sniff will be removed.
101
     *
102
     * @return string
103
     */
104
    public function getRemovalVersion()
×
105
    {
106
        return 'v4.0.0';
×
107

108
    }//end getRemovalVersion()
109

110

111
    /**
112
     * Provide a custom message to display with the deprecation.
113
     *
114
     * @return string
115
     */
116
    public function getDeprecationMessage()
×
117
    {
118
        return 'The MySource standard will be removed completely in v4.0.0.';
×
119

120
    }//end getDeprecationMessage()
121

122

123
}//end class
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc