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

PHPCSStandards / PHP_CodeSniffer / 14471881504

15 Apr 2025 02:22PM UTC coverage: 77.605%. Remained the same
14471881504

Pull #999

github

web-flow
Merge 97fd6a533 into 142199d59
Pull Request #999: AbstractSniffTestCase: flag missing `.fixed` files

19354 of 24939 relevant lines covered (77.61%)

78.6 hits per line

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

0.0
/src/Filters/ExactMatch.php
1
<?php
2
/**
3
 * An abstract filter class for checking files and folders against exact matches.
4
 *
5
 * Supports both allowed files and disallowed files.
6
 *
7
 * @author    Greg Sherwood <gsherwood@squiz.net>
8
 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
9
 * @license   https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
10
 */
11

12
namespace PHP_CodeSniffer\Filters;
13

14
use PHP_CodeSniffer\Util\Common;
15

16
abstract class ExactMatch extends Filter
17
{
18

19
    /**
20
     * A list of files to exclude.
21
     *
22
     * @var array
23
     */
24
    private $disallowedFiles = null;
25

26
    /**
27
     * A list of files to include.
28
     *
29
     * If the allowed files list is empty, only files in the disallowed files list will be excluded.
30
     *
31
     * @var array
32
     */
33
    private $allowedFiles = null;
34

35

36
    /**
37
     * Check whether the current element of the iterator is acceptable.
38
     *
39
     * If a file is both disallowed and allowed, it will be deemed unacceptable.
40
     *
41
     * @return bool
42
     */
43
    public function accept()
×
44
    {
45
        if (parent::accept() === false) {
×
46
            return false;
×
47
        }
48

49
        if ($this->disallowedFiles === null) {
×
50
            $this->disallowedFiles = $this->getDisallowedFiles();
×
51
        }
52

53
        if ($this->allowedFiles === null) {
×
54
            $this->allowedFiles = $this->getAllowedFiles();
×
55
        }
56

57
        $filePath = Common::realpath($this->current());
×
58

59
        // If a file is both disallowed and allowed, the disallowed files list takes precedence.
60
        if (isset($this->disallowedFiles[$filePath]) === true) {
×
61
            return false;
×
62
        }
63

64
        if (empty($this->allowedFiles) === true && empty($this->disallowedFiles) === false) {
×
65
            // We are only checking the disallowed files list, so everything else should be allowed.
66
            return true;
×
67
        }
68

69
        return isset($this->allowedFiles[$filePath]);
×
70

71
    }//end accept()
72

73

74
    /**
75
     * Returns an iterator for the current entry.
76
     *
77
     * Ensures that the disallowed files list and the allowed files list are preserved so they don't have
78
     * to be generated each time.
79
     *
80
     * @return \RecursiveIterator
81
     */
82
    public function getChildren()
×
83
    {
84
        $children = parent::getChildren();
×
85
        $children->disallowedFiles = $this->disallowedFiles;
×
86
        $children->allowedFiles    = $this->allowedFiles;
×
87
        return $children;
×
88

89
    }//end getChildren()
90

91

92
    /**
93
     * Get a list of file paths to exclude.
94
     *
95
     * @since 3.9.0 Replaces the `getBlacklist()` method, which was removed in PHPCS 4.0.0.
96
     *
97
     * @return array
98
     */
99
    abstract protected function getDisallowedFiles();
100

101

102
    /**
103
     * Get a list of file paths to include.
104
     *
105
     * @since 3.9.0 Replaces the `getWhitelist()` method, which was removed in PHPCS 4.0.0.
106
     *
107
     * @return array
108
     */
109
    abstract protected function getAllowedFiles();
110

111

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