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

PHPCSStandards / PHP_CodeSniffer / 15036337869

15 May 2025 04:03AM UTC coverage: 78.375% (-0.2%) from 78.556%
15036337869

Pull #856

github

web-flow
Merge 93f570b46 into f5e7943d0
Pull Request #856: [Doc] Cover all errors of PEAR ClassDeclaration

25112 of 32041 relevant lines covered (78.37%)

69.4 hits per line

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

0.0
/src/Standards/MySource/Sniffs/Channels/IncludeOwnSystemSniff.php
1
<?php
2
/**
3
 * Ensures that a system does not include itself.
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/master/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

18
class IncludeOwnSystemSniff implements Sniff, DeprecatedSniff
19
{
20

21

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

31
    }//end register()
32

33

34
    /**
35
     * Processes this sniff, when one of its tokens is encountered.
36
     *
37
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
38
     * @param int                         $stackPtr  The position of the current token in
39
     *                                               the stack passed in $tokens.
40
     *
41
     * @return void
42
     */
43
    public function process(File $phpcsFile, $stackPtr)
×
44
    {
45
        $fileName = $phpcsFile->getFilename();
×
46
        $matches  = [];
×
47
        if (preg_match('|/systems/(.*)/([^/]+)?actions.inc$|i', $fileName, $matches) === 0) {
×
48
            // Not an actions file.
49
            return;
×
50
        }
51

52
        $ownClass = $matches[2];
×
53
        $tokens   = $phpcsFile->getTokens();
×
54

55
        $typeName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($stackPtr + 2), null, false, true);
×
56
        $typeName = trim($tokens[$typeName]['content'], " '");
×
57
        switch (strtolower($tokens[($stackPtr + 1)]['content'])) {
×
58
        case 'includesystem' :
×
59
            $included = strtolower($typeName);
×
60
            break;
×
61
        case 'includeasset' :
×
62
            $included = strtolower($typeName).'assettype';
×
63
            break;
×
64
        case 'includewidget' :
×
65
            $included = strtolower($typeName).'widgettype';
×
66
            break;
×
67
        default:
68
            return;
×
69
        }
70

71
        if ($included === strtolower($ownClass)) {
×
72
            $error = "You do not need to include \"%s\" from within the system's own actions file";
×
73
            $data  = [$ownClass];
×
74
            $phpcsFile->addError($error, $stackPtr, 'NotRequired', $data);
×
75
        }
76

77
    }//end process()
78

79

80
    /**
81
     * Determines the included class name from given token.
82
     *
83
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
84
     * @param array                       $tokens    The array of file tokens.
85
     * @param int                         $stackPtr  The position in the tokens array of the
86
     *                                               potentially included class.
87
     *
88
     * @return bool
89
     */
90
    protected function getIncludedClassFromToken(
×
91
        $phpcsFile,
92
        array $tokens,
93
        $stackPtr
94
    ) {
95

96
        return false;
×
97

98
    }//end getIncludedClassFromToken()
99

100

101
    /**
102
     * Provide the version number in which the sniff was deprecated.
103
     *
104
     * @return string
105
     */
106
    public function getDeprecationVersion()
×
107
    {
108
        return 'v3.9.0';
×
109

110
    }//end getDeprecationVersion()
111

112

113
    /**
114
     * Provide the version number in which the sniff will be removed.
115
     *
116
     * @return string
117
     */
118
    public function getRemovalVersion()
×
119
    {
120
        return 'v4.0.0';
×
121

122
    }//end getRemovalVersion()
123

124

125
    /**
126
     * Provide a custom message to display with the deprecation.
127
     *
128
     * @return string
129
     */
130
    public function getDeprecationMessage()
×
131
    {
132
        return 'The MySource standard will be removed completely in v4.0.0.';
×
133

134
    }//end getDeprecationMessage()
135

136

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