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

PHPCSStandards / PHP_CodeSniffer / 18079229190

19 Sep 2025 11:00PM UTC coverage: 78.601% (-0.6%) from 79.178%
18079229190

push

github

jrfnl
Dependabot: remove `cooldown`

Follow up on PR 1273

Turns out that the `cooldown` configuration option is not supported for the `github-actions` ecosystem.... _sigh_

So I guess I better remove it again as otherwise Dependabot is blocked from running due to this "configuration error".

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

88.14
/src/Standards/MySource/Sniffs/Channels/DisallowSelfActionsSniff.php
1
<?php
2
/**
3
 * Ensures that self and static are not used to call public methods in action classes.
4
 *
5
 * @author    Greg Sherwood <gsherwood@squiz.net>
6
 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
7
 * @license   https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/HEAD/licence.txt BSD Licence
8
 *
9
 * @deprecated 3.9.0
10
 */
11

12
namespace PHP_CodeSniffer\Standards\MySource\Sniffs\Channels;
13

14
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
15
use PHP_CodeSniffer\Sniffs\Sniff;
16
use PHP_CodeSniffer\Files\File;
17
use PHP_CodeSniffer\Util\Tokens;
18

19
class DisallowSelfActionsSniff implements Sniff, DeprecatedSniff
20
{
21

22

23
    /**
24
     * Returns an array of tokens this test wants to listen for.
25
     *
26
     * @return array<int|string>
27
     */
28
    public function register()
3✔
29
    {
30
        return [T_CLASS];
3✔
31

32
    }//end register()
33

34

35
    /**
36
     * Processes this sniff, when one of its tokens is encountered.
37
     *
38
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
39
     * @param int                         $stackPtr  The position of the current token in
40
     *                                               the stack passed in $tokens.
41
     *
42
     * @return void
43
     */
44
    public function process(File $phpcsFile, $stackPtr)
3✔
45
    {
46
        $tokens = $phpcsFile->getTokens();
3✔
47

48
        // We are not interested in abstract classes.
49
        $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
3✔
50
        if ($prev !== false && $tokens[$prev]['code'] === T_ABSTRACT) {
3✔
51
            return;
3✔
52
        }
53

54
        // We are only interested in Action classes.
55
        $classNameToken = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
3✔
56
        $className      = $tokens[$classNameToken]['content'];
3✔
57
        if (substr($className, -7) !== 'Actions') {
3✔
58
            return;
×
59
        }
60

61
        $foundFunctions = [];
3✔
62
        $foundCalls     = [];
3✔
63

64
        // Find all static method calls in the form self::method() in the class.
65
        $classEnd = $tokens[$stackPtr]['scope_closer'];
3✔
66
        for ($i = ($classNameToken + 1); $i < $classEnd; $i++) {
3✔
67
            if ($tokens[$i]['code'] !== T_DOUBLE_COLON) {
3✔
68
                if ($tokens[$i]['code'] === T_FUNCTION) {
3✔
69
                    // Cache the function information.
70
                    $funcName  = $phpcsFile->findNext(T_STRING, ($i + 1));
3✔
71
                    $funcScope = $phpcsFile->findPrevious(Tokens::$scopeModifiers, ($i - 1));
3✔
72

73
                    $foundFunctions[$tokens[$funcName]['content']] = strtolower($tokens[$funcScope]['content']);
3✔
74
                }
1✔
75

76
                continue;
3✔
77
            }
78

79
            $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($i - 1), null, true);
3✔
80
            if ($tokens[$prevToken]['content'] !== 'self'
3✔
81
                && $tokens[$prevToken]['content'] !== 'static'
3✔
82
            ) {
1✔
83
                continue;
3✔
84
            }
85

86
            $funcNameToken = $phpcsFile->findNext(T_WHITESPACE, ($i + 1), null, true);
3✔
87
            if ($tokens[$funcNameToken]['code'] === T_VARIABLE) {
3✔
88
                // We are only interested in function calls.
89
                continue;
3✔
90
            }
91

92
            $funcName = $tokens[$funcNameToken]['content'];
3✔
93

94
            // We've found the function, now we need to find it and see if it is
95
            // public, private or protected. If it starts with an underscore we
96
            // can assume it is private.
97
            if ($funcName[0] === '_') {
3✔
98
                continue;
3✔
99
            }
100

101
            $foundCalls[$i] = [
3✔
102
                'name' => $funcName,
3✔
103
                'type' => strtolower($tokens[$prevToken]['content']),
3✔
104
            ];
1✔
105
        }//end for
1✔
106

107
        $errorClassName = substr($className, 0, -7);
3✔
108

109
        foreach ($foundCalls as $token => $funcData) {
3✔
110
            if (isset($foundFunctions[$funcData['name']]) === false) {
3✔
111
                // Function was not in this class, might have come from the parent.
112
                // Either way, we can't really check this.
113
                continue;
3✔
114
            } else if ($foundFunctions[$funcData['name']] === 'public') {
3✔
115
                $type  = $funcData['type'];
3✔
116
                $error = "Static calls to public methods in Action classes must not use the $type keyword; use %s::%s() instead";
3✔
117
                $data  = [
1✔
118
                    $errorClassName,
3✔
119
                    $funcName,
3✔
120
                ];
2✔
121
                $phpcsFile->addError($error, $token, 'Found'.ucfirst($funcData['type']), $data);
3✔
122
            }
1✔
123
        }
1✔
124

125
    }//end process()
2✔
126

127

128
    /**
129
     * Provide the version number in which the sniff was deprecated.
130
     *
131
     * @return string
132
     */
133
    public function getDeprecationVersion()
×
134
    {
135
        return 'v3.9.0';
×
136

137
    }//end getDeprecationVersion()
138

139

140
    /**
141
     * Provide the version number in which the sniff will be removed.
142
     *
143
     * @return string
144
     */
145
    public function getRemovalVersion()
×
146
    {
147
        return 'v4.0.0';
×
148

149
    }//end getRemovalVersion()
150

151

152
    /**
153
     * Provide a custom message to display with the deprecation.
154
     *
155
     * @return string
156
     */
157
    public function getDeprecationMessage()
×
158
    {
159
        return 'The MySource standard will be removed completely in v4.0.0.';
×
160

161
    }//end getDeprecationMessage()
162

163

164
}//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

© 2026 Coveralls, Inc