2
2
/**
3
3
* Class to manage a list of sniffs to ignore.
4
4
*
5
- * @author Brad Jorsch <[email protected] >
6
- * @copyright 2023 Brad Jorsch
7
- * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
5
+ * @copyright 2025 PHPCSStandards and contributors
6
+ * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8
7
*/
9
8
10
9
namespace PHP_CodeSniffer \Util ;
11
10
12
- class IgnoreList
11
+ /**
12
+ * Class to manage a list of sniffs to ignore.
13
+ *
14
+ * ---------------------------------------------------------------------------------------------
15
+ * This class is intended for internal use only and is not part of the public API.
16
+ * This also means that it has no promise of backward compatibility. Use at your own risk.
17
+ * ---------------------------------------------------------------------------------------------
18
+ *
19
+ * @internal
20
+ */
21
+ final class IgnoreList
13
22
{
14
23
15
24
/**
@@ -19,35 +28,55 @@ class IgnoreList
19
28
* Each level may be a boolean indicating that everything underneath the branch is or is not ignored, or
20
29
* may have a `.default' key indicating the default status for any branches not in the tree.
21
30
*
22
- * @var array|boolean
31
+ * @var array<string, bool|array<string, bool|array<string, bool|array<string, bool>>>>
23
32
*/
24
33
private $ data = [ '.default ' => false ];
25
34
26
35
27
36
/**
28
37
* Get an instance set to ignore nothing.
29
38
*
30
- * @return static
39
+ * @return IgnoreList
31
40
*/
32
- public static function ignoringNone ()
41
+ public static function getInstanceIgnoringNothing ()
33
42
{
34
43
return new self ();
35
44
36
- }//end ignoringNone ()
45
+ }//end getInstanceIgnoringNothing ()
37
46
38
47
39
48
/**
40
49
* Get an instance set to ignore everything.
41
50
*
42
- * @return static
51
+ * @return IgnoreList
52
+ */
53
+ public static function getInstanceIgnoringAll ()
54
+ {
55
+ $ instance = new self ();
56
+ $ instance ->data ['.default ' ] = true ;
57
+ return $ instance ;
58
+
59
+ }//end getInstanceIgnoringAll()
60
+
61
+
62
+ /**
63
+ * Get a new instance based on an existing instance.
64
+ *
65
+ * If passed null, creates a new instance that ignores nothing.
66
+ *
67
+ * @param IgnoreList|null $ignoreList List to clone.
68
+ *
69
+ * @return IgnoreList
43
70
*/
44
- public static function ignoringAll ( )
71
+ public static function getNewInstanceFrom (? IgnoreList $ ignoreList )
45
72
{
46
- $ ret = new self ();
47
- $ ret ->data ['.default ' ] = true ;
48
- return $ ret ;
73
+ if ($ ignoreList === null ) {
74
+ return self ::getInstanceIgnoringNothing ();
75
+ }
76
+
77
+ return clone $ ignoreList ;
49
78
50
- }//end ignoringAll ()
79
+ }//end getNewInstanceFrom ()
51
80
52
81
53
82
/**
@@ -57,29 +86,29 @@ public static function ignoringAll()
57
86
*
58
87
* @return bool
59
88
*/
60
- public function check ($ code )
89
+ public function isIgnored ($ code )
61
90
{
62
- $ data = $ this ->data ;
63
- $ ret = $ data ['.default ' ];
91
+ $ data = $ this ->data ;
92
+ $ returnValue = $ data ['.default ' ];
64
93
foreach (explode ('. ' , $ code ) as $ part ) {
65
94
if (isset ($ data [$ part ]) === false ) {
66
95
break ;
67
96
}
68
97
69
98
$ data = $ data [$ part ];
70
99
if (is_bool ($ data ) === true ) {
71
- $ ret = $ data ;
100
+ $ returnValue = $ data ;
72
101
break ;
73
102
}
74
103
75
104
if (isset ($ data ['.default ' ]) === true ) {
76
- $ ret = $ data ['.default ' ];
105
+ $ returnValue = $ data ['.default ' ];
77
106
}
78
107
}
79
108
80
- return $ ret ;
109
+ return $ returnValue ;
81
110
82
- }//end check ()
111
+ }//end isIgnored ()
83
112
84
113
85
114
/**
@@ -88,7 +117,7 @@ public function check($code)
88
117
* @param string $code Partial or complete sniff code.
89
118
* @param bool $ignore Whether the specified sniff should be ignored.
90
119
*
91
- * @return this
120
+ * @return IgnoreList $ this for chaining.
92
121
*/
93
122
public function set ($ code , $ ignore )
94
123
{
@@ -114,55 +143,55 @@ public function set($code, $ignore)
114
143
115
144
116
145
/**
117
- * Check if the list is empty .
146
+ * Check if the list ignores nothing .
118
147
*
119
148
* @return bool
120
149
*/
121
- public function isEmpty ()
150
+ public function ignoresNothing ()
122
151
{
123
- $ arrs = [ $ this ->data ];
124
- while ($ arrs !== []) {
125
- $ arr = array_pop ($ arrs );
126
- foreach ($ arr as $ v ) {
127
- if ($ v === true ) {
152
+ $ arraysToProcess = [ $ this ->data ];
153
+ while ($ arraysToProcess !== []) {
154
+ $ arrayBeingProcessed = array_pop ($ arraysToProcess );
155
+ foreach ($ arrayBeingProcessed as $ valueBeingProcessed ) {
156
+ if ($ valueBeingProcessed === true ) {
128
157
return false ;
129
158
}
130
159
131
- if (is_array ($ v ) === true ) {
132
- $ arrs [] = $ v ;
160
+ if (is_array ($ valueBeingProcessed ) === true ) {
161
+ $ arraysToProcess [] = $ valueBeingProcessed ;
133
162
}
134
163
}
135
164
}
136
165
137
166
return true ;
138
167
139
- }//end isEmpty ()
168
+ }//end ignoresNothing ()
140
169
141
170
142
171
/**
143
172
* Check if the list ignores everything.
144
173
*
145
174
* @return bool
146
175
*/
147
- public function isAll ()
176
+ public function ignoresEverything ()
148
177
{
149
- $ arrs = [ $ this ->data ];
150
- while ($ arrs !== []) {
151
- $ arr = array_pop ($ arrs );
152
- foreach ($ arr as $ v ) {
153
- if ($ v === false ) {
178
+ $ arraysToProcess = [ $ this ->data ];
179
+ while ($ arraysToProcess !== []) {
180
+ $ arrayBeingProcessed = array_pop ($ arraysToProcess );
181
+ foreach ($ arrayBeingProcessed as $ valueBeingProcessed ) {
182
+ if ($ valueBeingProcessed === false ) {
154
183
return false ;
155
184
}
156
185
157
- if (is_array ($ v ) === true ) {
158
- $ arrs [] = $ v ;
186
+ if (is_array ($ valueBeingProcessed ) === true ) {
187
+ $ arraysToProcess [] = $ valueBeingProcessed ;
159
188
}
160
189
}
161
190
}
162
191
163
192
return true ;
164
193
165
- }//end isAll ()
194
+ }//end ignoresEverything ()
166
195
167
196
168
197
}//end class
0 commit comments