PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
← All changes | src/extra/php-codesniffer-php-token/Util/Standards.php +263 -268 3.0.1 → 6.3.0 View file →
@@ -10,325 +10,320 @@
10 10 namespace PHP_CodeSniffer\Util;
11 11
12 12 use PHP_CodeSniffer\Config;
13 13
14 -class Standards
15 -{
14 +class Standards {
16 15
17 16
18 - /**
19 - * Get a list of paths where standards are installed.
20 - *
21 - * Unresolvable relative paths will be excluded from the results.
22 - *
23 - * @return array
24 - */
25 - public static function getInstalledStandardPaths()
26 - {
27 - $ds = DIRECTORY_SEPARATOR;
17 + /**
18 + * Get a list of paths where standards are installed.
19 + *
20 + * Unresolvable relative paths will be excluded from the results.
21 + *
22 + * @return array
23 + */
24 + public static function getInstalledStandardPaths() {
25 + $ds = DIRECTORY_SEPARATOR;
28 26
29 - $installedPaths = [dirname(dirname(__DIR__)).$ds.'src'.$ds.'Standards'];
30 - $configPaths = Config::getConfigData('installed_paths');
31 - if ($configPaths !== null) {
32 - $installedPaths = array_merge($installedPaths, explode(',', $configPaths));
33 - }
27 + $installedPaths = [ dirname( dirname( __DIR__ ) ) . $ds . 'src' . $ds . 'Standards' ];
28 + $configPaths = Config::getConfigData( 'installed_paths' );
29 + if ( $configPaths !== null ) {
30 + $installedPaths = array_merge( $installedPaths, explode( ',', $configPaths ) );
31 + }
34 32
35 - $resolvedInstalledPaths = [];
36 - foreach ($installedPaths as $installedPath) {
37 - if (substr($installedPath, 0, 1) === '.') {
38 - $installedPath = Common::realPath(__DIR__.$ds.'..'.$ds.'..'.$ds.$installedPath);
39 - if ($installedPath === false) {
40 - continue;
41 - }
42 - }
33 + $resolvedInstalledPaths = [];
34 + foreach ( $installedPaths as $installedPath ) {
35 + if ( substr( $installedPath, 0, 1 ) === '.' ) {
36 + $installedPath = Common::realPath( __DIR__ . $ds . '..' . $ds . '..' . $ds . $installedPath );
37 + if ( $installedPath === false ) {
38 + continue;
39 + }
40 + }
43 41
44 - $resolvedInstalledPaths[] = $installedPath;
45 - }
42 + $resolvedInstalledPaths[] = $installedPath;
43 + }
46 44
47 - return $resolvedInstalledPaths;
45 + return $resolvedInstalledPaths;
48 46
49 - }//end getInstalledStandardPaths()
47 + }//end getInstalledStandardPaths()
50 48
51 49
52 - /**
53 - * Get the details of all coding standards installed.
54 - *
55 - * Coding standards are directories located in the
56 - * CodeSniffer/Standards directory. Valid coding standards
57 - * include a Sniffs subdirectory.
58 - *
59 - * The details returned for each standard are:
60 - * - path: the path to the coding standard's main directory
61 - * - name: the name of the coding standard, as sourced from the ruleset.xml file
62 - * - namespace: the namespace used by the coding standard, as sourced from the ruleset.xml file
63 - *
64 - * If you only need the paths to the installed standards,
65 - * use getInstalledStandardPaths() instead as it performs less work to
66 - * retrieve coding standard names.
67 - *
68 - * @param boolean $includeGeneric If true, the special "Generic"
69 - * coding standard will be included
70 - * if installed.
71 - * @param string $standardsDir A specific directory to look for standards
72 - * in. If not specified, PHP_CodeSniffer will
73 - * look in its default locations.
74 - *
75 - * @return array
76 - * @see getInstalledStandardPaths()
77 - */
78 - public static function getInstalledStandardDetails(
79 - $includeGeneric=false,
80 - $standardsDir=''
81 - ) {
82 - $rulesets = [];
50 + /**
51 + * Get the details of all coding standards installed.
52 + *
53 + * Coding standards are directories located in the
54 + * CodeSniffer/Standards directory. Valid coding standards
55 + * include a Sniffs subdirectory.
56 + *
57 + * The details returned for each standard are:
58 + * - path: the path to the coding standard's main directory
59 + * - name: the name of the coding standard, as sourced from the ruleset.xml file
60 + * - namespace: the namespace used by the coding standard, as sourced from the ruleset.xml file
61 + *
62 + * If you only need the paths to the installed standards,
63 + * use getInstalledStandardPaths() instead as it performs less work to
64 + * retrieve coding standard names.
65 + *
66 + * @param boolean $includeGeneric If true, the special "Generic"
67 + * coding standard will be included
68 + * if installed.
69 + * @param string $standardsDir A specific directory to look for standards
70 + * in. If not specified, PHP_CodeSniffer will
71 + * look in its default locations.
72 + *
73 + * @return array
74 + * @see getInstalledStandardPaths()
75 + */
76 + public static function getInstalledStandardDetails(
77 + $includeGeneric = false,
78 + $standardsDir = ''
79 + ) {
80 + $rulesets = [];
83 81
84 - if ($standardsDir === '') {
85 - $installedPaths = self::getInstalledStandardPaths();
86 - } else {
87 - $installedPaths = [$standardsDir];
88 - }
82 + if ( $standardsDir === '' ) {
83 + $installedPaths = self::getInstalledStandardPaths();
84 + } else {
85 + $installedPaths = [ $standardsDir ];
86 + }
89 87
90 - foreach ($installedPaths as $standardsDir) {
91 - // Check if the installed dir is actually a standard itself.
92 - $csFile = $standardsDir.'/ruleset.xml';
93 - if (is_file($csFile) === true) {
94 - $rulesets[] = $csFile;
95 - continue;
96 - }
88 + foreach ( $installedPaths as $standardsDir ) {
89 + // Check if the installed dir is actually a standard itself.
90 + $csFile = $standardsDir . '/ruleset.xml';
91 + if ( is_file( $csFile ) === true ) {
92 + $rulesets[] = $csFile;
93 + continue;
94 + }
97 95
98 - if (is_dir($standardsDir) === false) {
99 - continue;
100 - }
96 + if ( is_dir( $standardsDir ) === false ) {
97 + continue;
98 + }
101 99
102 - $di = new \DirectoryIterator($standardsDir);
103 - foreach ($di as $file) {
104 - if ($file->isDir() === true && $file->isDot() === false) {
105 - $filename = $file->getFilename();
100 + $di = new \DirectoryIterator( $standardsDir );
101 + foreach ( $di as $file ) {
102 + if ( $file->isDir() === true && $file->isDot() === false ) {
103 + $filename = $file->getFilename();
106 104
107 - // Ignore the special "Generic" standard.
108 - if ($includeGeneric === false && $filename === 'Generic') {
109 - continue;
110 - }
105 + // Ignore the special "Generic" standard.
106 + if ( $includeGeneric === false && $filename === 'Generic' ) {
107 + continue;
108 + }
111 109
112 - // Valid coding standard dirs include a ruleset.
113 - $csFile = $file->getPathname().'/ruleset.xml';
114 - if (is_file($csFile) === true) {
115 - $rulesets[] = $csFile;
116 - }
117 - }
118 - }
119 - }//end foreach
110 + // Valid coding standard dirs include a ruleset.
111 + $csFile = $file->getPathname() . '/ruleset.xml';
112 + if ( is_file( $csFile ) === true ) {
113 + $rulesets[] = $csFile;
114 + }
115 + }
116 + }
117 + }//end foreach
120 118
121 - $installedStandards = [];
119 + $installedStandards = [];
122 120
123 - foreach ($rulesets as $rulesetPath) {
124 - $ruleset = @simplexml_load_string(file_get_contents($rulesetPath));
125 - if ($ruleset === false) {
126 - continue;
127 - }
121 + foreach ( $rulesets as $rulesetPath ) {
122 + $ruleset = @simplexml_load_string( file_get_contents( $rulesetPath ) );
123 + if ( $ruleset === false ) {
124 + continue;
125 + }
128 126
129 - $standardName = (string) $ruleset['name'];
130 - $dirname = basename(dirname($rulesetPath));
127 + $standardName = (string) $ruleset['name'];
128 + $dirname = basename( dirname( $rulesetPath ) );
131 129
132 - if (isset($ruleset['namespace']) === true) {
133 - $namespace = (string) $ruleset['namespace'];
134 - } else {
135 - $namespace = $dirname;
136 - }
130 + if ( isset( $ruleset['namespace'] ) === true ) {
131 + $namespace = (string) $ruleset['namespace'];
132 + } else {
133 + $namespace = $dirname;
134 + }
137 135
138 - $installedStandards[$dirname] = [
139 - 'path' => dirname($rulesetPath),
140 - 'name' => $standardName,
141 - 'namespace' => $namespace,
142 - ];
143 - }//end foreach
136 + $installedStandards[ $dirname ] = [
137 + 'path' => dirname( $rulesetPath ),
138 + 'name' => $standardName,
139 + 'namespace' => $namespace,
140 + ];
141 + }//end foreach
144 142
145 - return $installedStandards;
143 + return $installedStandards;
146 144
147 - }//end getInstalledStandardDetails()
145 + }//end getInstalledStandardDetails()
148 146
149 147
150 - /**
151 - * Get a list of all coding standards installed.
152 - *
153 - * Coding standards are directories located in the
154 - * CodeSniffer/Standards directory. Valid coding standards
155 - * include a Sniffs subdirectory.
156 - *
157 - * @param boolean $includeGeneric If true, the special "Generic"
158 - * coding standard will be included
159 - * if installed.
160 - * @param string $standardsDir A specific directory to look for standards
161 - * in. If not specified, PHP_CodeSniffer will
162 - * look in its default locations.
163 - *
164 - * @return array
165 - * @see isInstalledStandard()
166 - */
167 - public static function getInstalledStandards(
168 - $includeGeneric=false,
169 - $standardsDir=''
170 - ) {
171 - $installedStandards = [];
148 + /**
149 + * Get a list of all coding standards installed.
150 + *
151 + * Coding standards are directories located in the
152 + * CodeSniffer/Standards directory. Valid coding standards
153 + * include a Sniffs subdirectory.
154 + *
155 + * @param boolean $includeGeneric If true, the special "Generic"
156 + * coding standard will be included
157 + * if installed.
158 + * @param string $standardsDir A specific directory to look for standards
159 + * in. If not specified, PHP_CodeSniffer will
160 + * look in its default locations.
161 + *
162 + * @return array
163 + * @see isInstalledStandard()
164 + */
165 + public static function getInstalledStandards(
166 + $includeGeneric = false,
167 + $standardsDir = ''
168 + ) {
169 + $installedStandards = [];
172 170
173 - if ($standardsDir === '') {
174 - $installedPaths = self::getInstalledStandardPaths();
175 - } else {
176 - $installedPaths = [$standardsDir];
177 - }
171 + if ( $standardsDir === '' ) {
172 + $installedPaths = self::getInstalledStandardPaths();
173 + } else {
174 + $installedPaths = [ $standardsDir ];
175 + }
178 176
179 - foreach ($installedPaths as $standardsDir) {
180 - // Check if the installed dir is actually a standard itself.
181 - $csFile = $standardsDir.'/ruleset.xml';
182 - if (is_file($csFile) === true) {
183 - $installedStandards[] = basename($standardsDir);
184 - continue;
185 - }
177 + foreach ( $installedPaths as $standardsDir ) {
178 + // Check if the installed dir is actually a standard itself.
179 + $csFile = $standardsDir . '/ruleset.xml';
180 + if ( is_file( $csFile ) === true ) {
181 + $installedStandards[] = basename( $standardsDir );
182 + continue;
183 + }
186 184
187 - if (is_dir($standardsDir) === false) {
188 - // Doesn't exist.
189 - continue;
190 - }
185 + if ( is_dir( $standardsDir ) === false ) {
186 + // Doesn't exist.
187 + continue;
188 + }
191 189
192 - $di = new \DirectoryIterator($standardsDir);
193 - foreach ($di as $file) {
194 - if ($file->isDir() === true && $file->isDot() === false) {
195 - $filename = $file->getFilename();
190 + $di = new \DirectoryIterator( $standardsDir );
191 + foreach ( $di as $file ) {
192 + if ( $file->isDir() === true && $file->isDot() === false ) {
193 + $filename = $file->getFilename();
196 194
197 - // Ignore the special "Generic" standard.
198 - if ($includeGeneric === false && $filename === 'Generic') {
199 - continue;
200 - }
195 + // Ignore the special "Generic" standard.
196 + if ( $includeGeneric === false && $filename === 'Generic' ) {
197 + continue;
198 + }
201 199
202 - // Valid coding standard dirs include a ruleset.
203 - $csFile = $file->getPathname().'/ruleset.xml';
204 - if (is_file($csFile) === true) {
205 - $installedStandards[] = $filename;
206 - }
207 - }
208 - }
209 - }//end foreach
200 + // Valid coding standard dirs include a ruleset.
201 + $csFile = $file->getPathname() . '/ruleset.xml';
202 + if ( is_file( $csFile ) === true ) {
203 + $installedStandards[] = $filename;
204 + }
205 + }
206 + }
207 + }//end foreach
210 208
211 - return $installedStandards;
209 + return $installedStandards;
212 210
213 - }//end getInstalledStandards()
211 + }//end getInstalledStandards()
214 212
215 213
216 - /**
217 - * Determine if a standard is installed.
218 - *
219 - * Coding standards are directories located in the
220 - * CodeSniffer/Standards directory. Valid coding standards
221 - * include a ruleset.xml file.
222 - *
223 - * @param string $standard The name of the coding standard.
224 - *
225 - * @return boolean
226 - * @see getInstalledStandards()
227 - */
228 - public static function isInstalledStandard($standard)
229 - {
230 - $path = self::getInstalledStandardPath($standard);
231 - if ($path !== null && strpos($path, 'ruleset.xml') !== false) {
232 - return true;
233 - } else {
234 - // This could be a custom standard, installed outside our
235 - // standards directory.
236 - $standard = Common::realPath($standard);
237 - if ($standard === false) {
238 - return false;
239 - }
214 + /**
215 + * Determine if a standard is installed.
216 + *
217 + * Coding standards are directories located in the
218 + * CodeSniffer/Standards directory. Valid coding standards
219 + * include a ruleset.xml file.
220 + *
221 + * @param string $standard The name of the coding standard.
222 + *
223 + * @return boolean
224 + * @see getInstalledStandards()
225 + */
226 + public static function isInstalledStandard( $standard ) {
227 + $path = self::getInstalledStandardPath( $standard );
228 + if ( $path !== null && strpos( $path, 'ruleset.xml' ) !== false ) {
229 + return true;
230 + } else {
231 + // This could be a custom standard, installed outside our
232 + // standards directory.
233 + $standard = Common::realPath( $standard );
234 + if ( $standard === false ) {
235 + return false;
236 + }
240 237
241 - // Might be an actual ruleset file itUtil.
242 - // If it has an XML extension, let's at least try it.
243 - if (is_file($standard) === true
244 - && (substr(strtolower($standard), -4) === '.xml'
245 - || substr(strtolower($standard), -9) === '.xml.dist')
246 - ) {
247 - return true;
248 - }
238 + // Might be an actual ruleset file itUtil.
239 + // If it has an XML extension, let's at least try it.
240 + if ( is_file( $standard ) === true
241 + && ( substr( strtolower( $standard ), - 4 ) === '.xml'
242 + || substr( strtolower( $standard ), - 9 ) === '.xml.dist' )
243 + ) {
244 + return true;
245 + }
249 246
250 - // If it is a directory with a ruleset.xml file in it,
251 - // it is a standard.
252 - $ruleset = rtrim($standard, ' /\\').DIRECTORY_SEPARATOR.'ruleset.xml';
253 - if (is_file($ruleset) === true) {
254 - return true;
255 - }
256 - }//end if
247 + // If it is a directory with a ruleset.xml file in it,
248 + // it is a standard.
249 + $ruleset = rtrim( $standard, ' /\\' ) . DIRECTORY_SEPARATOR . 'ruleset.xml';
250 + if ( is_file( $ruleset ) === true ) {
251 + return true;
252 + }
253 + }//end if
257 254
258 - return false;
255 + return false;
259 256
260 - }//end isInstalledStandard()
257 + }//end isInstalledStandard()
261 258
262 259
263 - /**
264 - * Return the path of an installed coding standard.
265 - *
266 - * Coding standards are directories located in the
267 - * CodeSniffer/Standards directory. Valid coding standards
268 - * include a ruleset.xml file.
269 - *
270 - * @param string $standard The name of the coding standard.
271 - *
272 - * @return string|null
273 - */
274 - public static function getInstalledStandardPath($standard)
275 - {
276 - if (strpos($standard, '.') !== false) {
277 - return null;
278 - }
260 + /**
261 + * Return the path of an installed coding standard.
262 + *
263 + * Coding standards are directories located in the
264 + * CodeSniffer/Standards directory. Valid coding standards
265 + * include a ruleset.xml file.
266 + *
267 + * @param string $standard The name of the coding standard.
268 + *
269 + * @return string|null
270 + */
271 + public static function getInstalledStandardPath( $standard ) {
272 + if ( strpos( $standard, '.' ) !== false ) {
273 + return null;
274 + }
279 275
280 - $installedPaths = self::getInstalledStandardPaths();
281 - foreach ($installedPaths as $installedPath) {
282 - $standardPath = $installedPath.DIRECTORY_SEPARATOR.$standard;
283 - if (file_exists($standardPath) === false) {
284 - if (basename($installedPath) !== $standard) {
285 - continue;
286 - }
276 + $installedPaths = self::getInstalledStandardPaths();
277 + foreach ( $installedPaths as $installedPath ) {
278 + $standardPath = $installedPath . DIRECTORY_SEPARATOR . $standard;
279 + if ( file_exists( $standardPath ) === false ) {
280 + if ( basename( $installedPath ) !== $standard ) {
281 + continue;
282 + }
287 283
288 - $standardPath = $installedPath;
289 - }
284 + $standardPath = $installedPath;
285 + }
290 286
291 - $path = Common::realpath($standardPath.DIRECTORY_SEPARATOR.'ruleset.xml');
287 + $path = Common::realpath( $standardPath . DIRECTORY_SEPARATOR . 'ruleset.xml' );
292 288
293 - if ($path !== false && is_file($path) === true) {
294 - return $path;
295 - } else if (Common::isPharFile($standardPath) === true) {
296 - $path = Common::realpath($standardPath);
297 - if ($path !== false) {
298 - return $path;
299 - }
300 - }
301 - }//end foreach
289 + if ( $path !== false && is_file( $path ) === true ) {
290 + return $path;
291 + } else if ( Common::isPharFile( $standardPath ) === true ) {
292 + $path = Common::realpath( $standardPath );
293 + if ( $path !== false ) {
294 + return $path;
295 + }
296 + }
297 + }//end foreach
302 298
303 - return null;
299 + return null;
304 300
305 - }//end getInstalledStandardPath()
301 + }//end getInstalledStandardPath()
306 302
307 303
308 - /**
309 - * Prints out a list of installed coding standards.
310 - *
311 - * @return void
312 - */
313 - public static function printInstalledStandards()
314 - {
315 - $installedStandards = self::getInstalledStandards();
316 - $numStandards = count($installedStandards);
304 + /**
305 + * Prints out a list of installed coding standards.
306 + *
307 + * @return void
308 + */
309 + public static function printInstalledStandards() {
310 + $installedStandards = self::getInstalledStandards();
311 + $numStandards = count( $installedStandards );
317 312
318 - if ($numStandards === 0) {
319 - echo 'No coding standards are installed.'.PHP_EOL;
320 - } else {
321 - $lastStandard = array_pop($installedStandards);
322 - if ($numStandards === 1) {
323 - echo "The only coding standard installed is $lastStandard".PHP_EOL;
324 - } else {
325 - $standardList = implode(', ', $installedStandards);
326 - $standardList .= ' and '.$lastStandard;
327 - echo 'The installed coding standards are '.$standardList.PHP_EOL;
328 - }
329 - }
313 + if ( $numStandards === 0 ) {
314 + echo 'No coding standards are installed.' . PHP_EOL;
315 + } else {
316 + $lastStandard = array_pop( $installedStandards );
317 + if ( $numStandards === 1 ) {
318 + echo "The only coding standard installed is $lastStandard" . PHP_EOL;
319 + } else {
320 + $standardList = implode( ', ', $installedStandards );
321 + $standardList .= ' and ' . $lastStandard;
322 + echo 'The installed coding standards are ' . $standardList . PHP_EOL;
323 + }
324 + }
330 325
331 - }//end printInstalledStandards()
326 + }//end printInstalledStandards()
332 327
333 328
334 329 }//end class