• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

PHPCompatibility / PHPCompatibility / 19804455605

30 Nov 2025 08:31PM UTC coverage: 98.306% (-0.04%) from 98.346%
19804455605

push

github

web-flow
Merge pull request #2014 from PHPCompatibility/php-8.5/new-removedterminatingcasewithsemicolon-sniff

PHP 8.5 | ✨ New `PHPCompatibility.ControlStructures.RemovedTerminatingCaseWithSemicolon` sniff (RFC)

30 of 34 new or added lines in 1 file covered. (88.24%)

21 existing lines in 15 files now uncovered.

8355 of 8499 relevant lines covered (98.31%)

20.51 hits per line

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

97.5
/PHPCompatibility/Sniffs/ParameterValues/NewStripTagsAllowableTagsArraySniff.php
1
<?php
2
/**
3
 * PHPCompatibility, an external standard for PHP_CodeSniffer.
4
 *
5
 * @package   PHPCompatibility
6
 * @copyright 2012-2020 PHPCompatibility Contributors
7
 * @license   https://opensource.org/licenses/LGPL-3.0 LGPL3
8
 * @link      https://github.com/PHPCompatibility/PHPCompatibility
9
 */
10

11
namespace PHPCompatibility\Sniffs\ParameterValues;
12

13
use PHPCompatibility\AbstractFunctionCallParameterSniff;
14
use PHPCompatibility\Helpers\ScannedCode;
15
use PHP_CodeSniffer\Files\File;
16
use PHP_CodeSniffer\Util\Tokens;
17
use PHPCSUtils\Utils\PassedParameters;
18

19
/**
20
 * As of PHP 7.4, `strip_tags()` now also accepts an array of `$allowed_tags`.
21
 *
22
 * PHP version 7.4
23
 *
24
 * @link https://www.php.net/manual/en/migration74.new-features.php#migration74.new-features.standard.strip-tags
25
 * @link https://www.php.net/manual/en/function.strip-tags.php
26
 *
27
 * @since 9.3.0
28
 * @since 10.0.0 This class is now `final`.
29
 */
30
final class NewStripTagsAllowableTagsArraySniff extends AbstractFunctionCallParameterSniff
31
{
32

33
    /**
34
     * Functions to check for.
35
     *
36
     * @since 9.3.0
37
     *
38
     * @var array<string, true>
39
     */
40
    protected $targetFunctions = [
41
        'strip_tags' => true,
42
    ];
43

44

45
    /**
46
     * Do a version check to determine if this sniff needs to run at all.
47
     *
48
     * @since 9.3.0
49
     *
50
     * @return bool
51
     */
52
    protected function bowOutEarly()
8✔
53
    {
54
        return false;
8✔
55
    }
56

57

58
    /**
59
     * Process the parameters of a matched function.
60
     *
61
     * @since 9.3.0
62
     *
63
     * @param \PHP_CodeSniffer\Files\File $phpcsFile    The file being scanned.
64
     * @param int                         $stackPtr     The position of the current token in the stack.
65
     * @param string                      $functionName The token content (function name) which was matched.
66
     * @param array                       $parameters   Array with information about the parameters.
67
     *
68
     * @return void
69
     */
70
    public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters)
8✔
71
    {
72
        $targetParam = PassedParameters::getParameterFromStack($parameters, 2, 'allowed_tags');
8✔
73
        if ($targetParam === false) {
8✔
74
            return;
8✔
75
        }
76

77
        $tokens       = $phpcsFile->getTokens();
8✔
78
        $nextNonEmpty = $phpcsFile->findNext(Tokens::EMPTY_TOKENS, $targetParam['start'], $targetParam['end'], true);
8✔
79

80
        if ($nextNonEmpty === false) {
8✔
81
            // Shouldn't be possible.
82
            return;
8✔
83
        }
84

85
        if ($tokens[$nextNonEmpty]['code'] !== \T_ARRAY
8✔
86
            && $tokens[$nextNonEmpty]['code'] !== \T_OPEN_SHORT_ARRAY
8✔
87
        ) {
88
            // Not passed as a hard-coded array.
89
            return;
8✔
90
        }
91

92
        if (ScannedCode::shouldRunOnOrBelow('7.3') === true) {
8✔
93
            $phpcsFile->addError(
4✔
94
                'The strip_tags() function did not accept $allowed_tags to be passed in array format in PHP 7.3 and earlier.',
4✔
95
                $nextNonEmpty,
4✔
96
                'Found'
4✔
97
            );
2✔
98
        }
99

100
        if (ScannedCode::shouldRunOnOrAbove('7.4') === true) {
8✔
101
            if (\strpos($targetParam['clean'], '>') === false) {
4✔
102
                // Efficiency: prevent needlessly walking the array.
103
                return;
4✔
104
            }
105

106
            $items = PassedParameters::getParameters($phpcsFile, $nextNonEmpty);
4✔
107

108
            if (empty($items)) {
4✔
UNCOV
109
                return;
×
110
            }
111

112
            foreach ($items as $item) {
4✔
113
                for ($i = $item['start']; $i <= $item['end']; $i++) {
4✔
114
                    if (isset(Tokens::NAME_TOKENS[$tokens[$i]['code']]) === true
4✔
115
                        || $tokens[$i]['code'] === \T_VARIABLE
4✔
116
                    ) {
117
                        // Variable, constant, function call. Ignore complete item as undetermined.
118
                        break;
4✔
119
                    }
120

121
                    if (isset(Tokens::TEXT_STRING_TOKENS[$tokens[$i]['code']]) === true
4✔
122
                        && \strpos($tokens[$i]['content'], '>') !== false
4✔
123
                    ) {
124
                        $phpcsFile->addWarning(
4✔
125
                            'When passing strip_tags() the $allowed_tags parameter as an array, the tags should not be enclosed in <> brackets. Found: %s',
4✔
126
                            $i,
4✔
127
                            'Invalid',
4✔
128
                            [$item['clean']]
4✔
129
                        );
2✔
130

131
                        // Only throw one error per array item.
132
                        break;
4✔
133
                    }
134
                }
135
            }
136
        }
137
    }
4✔
138
}
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