• 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

70.83
/src/Standards/MySource/Sniffs/Strings/JoinStringsSniff.php
1
<?php
2
/**
3
 * Ensures that strings are not joined using array.join().
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\Strings;
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 JoinStringsSniff implements Sniff, DeprecatedSniff
20
{
21

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

29

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

39
    }//end register()
40

41

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

55
        if ($tokens[$stackPtr]['content'] !== 'join') {
3✔
56
            return;
3✔
57
        }
58

59
        $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
3✔
60
        if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR) {
3✔
61
            return;
×
62
        }
63

64
        $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prev - 1), null, true);
3✔
65
        if ($tokens[$prev]['code'] === T_CLOSE_SQUARE_BRACKET) {
3✔
66
            $opener = $tokens[$prev]['bracket_opener'];
3✔
67
            if ($tokens[($opener - 1)]['code'] !== T_STRING) {
3✔
68
                // This means the array is declared inline, like x = [a,b,c].join()
69
                // and not elsewhere, like x = y[a].join()
70
                // The first is not allowed while the second is.
71
                $error = 'Joining strings using inline arrays is not allowed; use the + operator instead';
3✔
72
                $phpcsFile->addError($error, $stackPtr, 'ArrayNotAllowed');
3✔
73
            }
1✔
74
        }
1✔
75

76
    }//end process()
2✔
77

78

79
    /**
80
     * Provide the version number in which the sniff was deprecated.
81
     *
82
     * @return string
83
     */
84
    public function getDeprecationVersion()
×
85
    {
86
        return 'v3.9.0';
×
87

88
    }//end getDeprecationVersion()
89

90

91
    /**
92
     * Provide the version number in which the sniff will be removed.
93
     *
94
     * @return string
95
     */
96
    public function getRemovalVersion()
×
97
    {
98
        return 'v4.0.0';
×
99

100
    }//end getRemovalVersion()
101

102

103
    /**
104
     * Provide a custom message to display with the deprecation.
105
     *
106
     * @return string
107
     */
108
    public function getDeprecationMessage()
×
109
    {
110
        return 'The MySource standard will be removed completely in v4.0.0.';
×
111

112
    }//end getDeprecationMessage()
113

114

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