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

PHPCSStandards / PHP_CodeSniffer / 17483947696

05 Sep 2025 04:45AM UTC coverage: 78.507% (-0.7%) from 79.184%
17483947696

push

github

web-flow
Merge pull request #1213 from PHPCSStandards/feature/remove-filelist-tests

:fire: Hot Fix: remove FileList tests

25309 of 32238 relevant lines covered (78.51%)

73.81 hits per line

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

77.78
/src/Standards/Squiz/Sniffs/Objects/DisallowObjectStringIndexSniff.php
1
<?php
2
/**
3
 * Ensures that object indexes are written in dot notation.
4
 *
5
 * @author    Sertan Danis <sdanis@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\Squiz\Sniffs\Objects;
13

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

18
class DisallowObjectStringIndexSniff implements Sniff, DeprecatedSniff
19
{
20

21
    /**
22
     * A list of tokenizers this sniff supports.
23
     *
24
     * @var array
25
     */
26
    public $supportedTokenizers = ['JS'];
27

28

29
    /**
30
     * Returns an array of tokens this test wants to listen for.
31
     *
32
     * @return array<int|string>
33
     */
34
    public function register()
3✔
35
    {
36
        return [T_OPEN_SQUARE_BRACKET];
3✔
37

38
    }//end register()
39

40

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

54
        // Check if the next non whitespace token is a string.
55
        $index = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
3✔
56
        if ($tokens[$index]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
3✔
57
            return;
3✔
58
        }
59

60
        // Make sure it is the only thing in the square brackets.
61
        $next = $phpcsFile->findNext(T_WHITESPACE, ($index + 1), null, true);
3✔
62
        if ($tokens[$next]['code'] !== T_CLOSE_SQUARE_BRACKET) {
3✔
63
            return;
3✔
64
        }
65

66
        // Allow indexes that have dots in them because we can't write
67
        // them in dot notation.
68
        $content = trim($tokens[$index]['content'], '"\' ');
3✔
69
        if (strpos($content, '.') !== false) {
3✔
70
            return;
3✔
71
        }
72

73
        // Also ignore reserved words.
74
        if ($content === 'super') {
3✔
75
            return;
3✔
76
        }
77

78
        // Token before the opening square bracket cannot be a var name.
79
        $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
3✔
80
        if ($tokens[$prev]['code'] === T_STRING) {
3✔
81
            $error = 'Object indexes must be written in dot notation';
3✔
82
            $phpcsFile->addError($error, $prev, 'Found');
3✔
83
        }
1✔
84

85
    }//end process()
2✔
86

87

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

97
    }//end getDeprecationVersion()
98

99

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

109
    }//end getRemovalVersion()
110

111

112
    /**
113
     * Provide a custom message to display with the deprecation.
114
     *
115
     * @return string
116
     */
117
    public function getDeprecationMessage()
×
118
    {
119
        return 'Support for scanning JavaScript files will be removed completely in v4.0.0.';
×
120

121
    }//end getDeprecationMessage()
122

123

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