• 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

81.82
/src/Standards/Squiz/Sniffs/Classes/DuplicatePropertySniff.php
1
<?php
2
/**
3
 * Ensures JS classes don't contain duplicate property names.
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\Squiz\Sniffs\Classes;
13

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

18
class DuplicatePropertySniff 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_OBJECT];
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 current file being processed.
45
     * @param int                         $stackPtr  The position of the current token in the
46
     *                                               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
        $properties   = [];
3✔
55
        $wantedTokens = [
1✔
56
            T_PROPERTY,
3✔
57
            T_OBJECT,
3✔
58
        ];
2✔
59

60
        $next = $phpcsFile->findNext($wantedTokens, ($stackPtr + 1), $tokens[$stackPtr]['bracket_closer']);
3✔
61
        while ($next !== false && $next < $tokens[$stackPtr]['bracket_closer']) {
3✔
62
            if ($tokens[$next]['code'] === T_OBJECT) {
3✔
63
                // Skip nested objects.
64
                $next = $tokens[$next]['bracket_closer'];
3✔
65
            } else {
1✔
66
                $propName = $tokens[$next]['content'];
3✔
67
                if (isset($properties[$propName]) === true) {
3✔
68
                    $error = 'Duplicate property definition found for "%s"; previously defined on line %s';
3✔
69
                    $data  = [
1✔
70
                        $propName,
3✔
71
                        $tokens[$properties[$propName]]['line'],
3✔
72
                    ];
2✔
73
                    $phpcsFile->addError($error, $next, 'Found', $data);
3✔
74
                }
1✔
75

76
                $properties[$propName] = $next;
3✔
77
            }//end if
78

79
            $next = $phpcsFile->findNext($wantedTokens, ($next + 1), $tokens[$stackPtr]['bracket_closer']);
3✔
80
        }//end while
1✔
81

82
    }//end process()
2✔
83

84

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

94
    }//end getDeprecationVersion()
95

96

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

106
    }//end getRemovalVersion()
107

108

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

118
    }//end getDeprecationMessage()
119

120

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