Skip to content

Commit 9d4af7a

Browse files
committed
Filters/ExactMatch: deprecate the getBlacklist() and getWhitelist() methods
Deprecate the `getBlacklist()` and `getWhitelist()` methods and introduce the `getDisallowedFiles()` and `getAllowedFiles()` replacement methods. When available in child classes, the `getDisallowedFiles()` and `getAllowedFiles()` methods will take precedence over the deprecated `getBlacklist()` and `getWhitelist()` methods. Fixes 198
1 parent f6566e9 commit 9d4af7a

File tree

3 files changed

+128
-8
lines changed

3 files changed

+128
-8
lines changed

src/Filters/ExactMatch.php

+52-4
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,32 @@ public function accept()
4747
}
4848

4949
if ($this->disallowedFiles === null) {
50-
$this->disallowedFiles = $this->getblacklist();
50+
$this->disallowedFiles = $this->getDisallowedFiles();
51+
52+
// BC-layer.
53+
if ($this->disallowedFiles === null) {
54+
$this->disallowedFiles = $this->getBlacklist();
55+
}
5156
}
5257

5358
if ($this->allowedFiles === null) {
54-
$this->allowedFiles = $this->getwhitelist();
59+
$this->allowedFiles = $this->getAllowedFiles();
60+
61+
// BC-layer.
62+
if ($this->allowedFiles === null) {
63+
$this->allowedFiles = $this->getWhitelist();
64+
}
5565
}
5666

5767
$filePath = Util\Common::realpath($this->current());
5868

59-
// If file is both disallowed and allowed, the disallowed files list takes precedence.
69+
// If a file is both disallowed and allowed, the disallowed files list takes precedence.
6070
if (isset($this->disallowedFiles[$filePath]) === true) {
6171
return false;
6272
}
6373

6474
if (empty($this->allowedFiles) === true && empty($this->disallowedFiles) === false) {
65-
// We are only checking a disallowed files list, so everything else should be allowed.
75+
// We are only checking the disallowed files list, so everything else should be allowed.
6676
return true;
6777
}
6878

@@ -92,6 +102,11 @@ public function getChildren()
92102
/**
93103
* Get a list of file paths to exclude.
94104
*
105+
* @deprecated 3.9.0 Overload the `getDisallowedFiles()` method instead.
106+
* The `getDisallowedFiles()` method will be made abstract and therefore required
107+
* in v4.0 and this method will be removed.
108+
* If both methods are implemented, the new `getDisallowedFiles()` method will take precedence.
109+
*
95110
* @return array
96111
*/
97112
abstract protected function getBlacklist();
@@ -100,9 +115,42 @@ abstract protected function getBlacklist();
100115
/**
101116
* Get a list of file paths to include.
102117
*
118+
* @deprecated 3.9.0 Overload the `getAllowedFiles()` method instead.
119+
* The `getAllowedFiles()` method will be made abstract and therefore required
120+
* in v4.0 and this method will be removed.
121+
* If both methods are implemented, the new `getAllowedFiles()` method will take precedence.
122+
*
103123
* @return array
104124
*/
105125
abstract protected function getWhitelist();
106126

107127

128+
/**
129+
* Get a list of file paths to exclude.
130+
*
131+
* @since 3.9.0 Replaces the deprecated `getBlacklist()` method.
132+
*
133+
* @return array|null
134+
*/
135+
protected function getDisallowedFiles()
136+
{
137+
return null;
138+
139+
}//end getDisallowedFiles()
140+
141+
142+
/**
143+
* Get a list of file paths to include.
144+
*
145+
* @since 3.9.0 Replaces the deprecated `getWhitelist()` method.
146+
*
147+
* @return array|null
148+
*/
149+
protected function getAllowedFiles()
150+
{
151+
return null;
152+
153+
}//end getAllowedFiles()
154+
155+
108156
}//end class

src/Filters/GitModified.php

+38-2
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,41 @@ class GitModified extends ExactMatch
1818
/**
1919
* Get a list of file paths to exclude.
2020
*
21+
* @since 3.9.0
22+
*
2123
* @return array
2224
*/
23-
protected function getBlacklist()
25+
protected function getDisallowedFiles()
2426
{
2527
return [];
2628

29+
}//end getDisallowedFiles()
30+
31+
32+
/**
33+
* Get a list of file paths to exclude.
34+
*
35+
* @deprecated 3.9.0 Overload the `getDisallowedFiles()` method instead.
36+
*
37+
* @codeCoverageIgnore
38+
*
39+
* @return array
40+
*/
41+
protected function getBlacklist()
42+
{
43+
return $this->getDisallowedFiles();
44+
2745
}//end getBlacklist()
2846

2947

3048
/**
3149
* Get a list of file paths to include.
3250
*
51+
* @since 3.9.0
52+
*
3353
* @return array
3454
*/
35-
protected function getWhitelist()
55+
protected function getAllowedFiles()
3656
{
3757
$modified = [];
3858

@@ -59,6 +79,22 @@ protected function getWhitelist()
5979

6080
return $modified;
6181

82+
}//end getAllowedFiles()
83+
84+
85+
/**
86+
* Get a list of file paths to include.
87+
*
88+
* @deprecated 3.9.0 Overload the `getAllowedFiles()` method instead.
89+
*
90+
* @codeCoverageIgnore
91+
*
92+
* @return array
93+
*/
94+
protected function getWhitelist()
95+
{
96+
return $this->getAllowedFiles();
97+
6298
}//end getWhitelist()
6399

64100

src/Filters/GitStaged.php

+38-2
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,41 @@ class GitStaged extends ExactMatch
2020
/**
2121
* Get a list of file paths to exclude.
2222
*
23+
* @since 3.9.0
24+
*
2325
* @return array
2426
*/
25-
protected function getBlacklist()
27+
protected function getDisallowedFiles()
2628
{
2729
return [];
2830

31+
}//end getDisallowedFiles()
32+
33+
34+
/**
35+
* Get a list of file paths to exclude.
36+
*
37+
* @deprecated 3.9.0 Overload the `getDisallowedFiles()` method instead.
38+
*
39+
* @codeCoverageIgnore
40+
*
41+
* @return array
42+
*/
43+
protected function getBlacklist()
44+
{
45+
return $this->getDisallowedFiles();
46+
2947
}//end getBlacklist()
3048

3149

3250
/**
3351
* Get a list of file paths to include.
3452
*
53+
* @since 3.9.0
54+
*
3555
* @return array
3656
*/
37-
protected function getWhitelist()
57+
protected function getAllowedFiles()
3858
{
3959
$modified = [];
4060

@@ -61,6 +81,22 @@ protected function getWhitelist()
6181

6282
return $modified;
6383

84+
}//end getAllowedFiles()
85+
86+
87+
/**
88+
* Get a list of file paths to include.
89+
*
90+
* @deprecated 3.9.0 Overload the `getAllowedFiles()` method instead.
91+
*
92+
* @codeCoverageIgnore
93+
*
94+
* @return array
95+
*/
96+
protected function getWhitelist()
97+
{
98+
return $this->getAllowedFiles();
99+
64100
}//end getWhitelist()
65101

66102

0 commit comments

Comments
 (0)