Don't use `phpcs:ignoreFile` to selectively ignore sniffs
[lhc/web/wiklou.git] / includes / utils / AutoloadGenerator.php
index 14c432c..0e2ef85 100644 (file)
@@ -42,6 +42,13 @@ class AutoloadGenerator {
         */
        protected $overrides = [];
 
+       /**
+        * Directories that should be excluded
+        *
+        * @var string[]
+        */
+       protected $excludePaths = [];
+
        /**
         * @param string $basepath Root path of the project being scanned for classes
         * @param array|string $flags
@@ -60,6 +67,34 @@ class AutoloadGenerator {
                }
        }
 
+       /**
+        * Directories that should be excluded
+        *
+        * @since 1.31
+        * @param string[] $paths
+        */
+       public function setExcludePaths( array $paths ) {
+               foreach ( $paths as $path ) {
+                       $this->excludePaths[] = self::normalizePathSeparator( $path );
+               }
+       }
+
+       /**
+        * Whether the file should be excluded
+        *
+        * @param string $path File path
+        * @return bool
+        */
+       private function shouldExclude( $path ) {
+               foreach ( $this->excludePaths as $dir ) {
+                       if ( strpos( $path, $dir ) === 0 ) {
+                               return true;
+                       }
+               }
+
+               return false;
+       }
+
        /**
         * Force a class to be autoloaded from a specific path, regardless of where
         * or if it was detected.
@@ -94,6 +129,9 @@ class AutoloadGenerator {
                if ( substr( $inputPath, 0, $len ) !== $this->basepath ) {
                        throw new \Exception( "Path is not within basepath: $inputPath" );
                }
+               if ( $this->shouldExclude( $inputPath ) ) {
+                       return;
+               }
                $result = $this->collector->getClasses(
                        file_get_contents( $inputPath )
                );
@@ -198,11 +236,10 @@ class AutoloadGenerator {
                }
 
                $output = implode( "\n\t", $content );
-               return
-                       <<<EOD
+               return <<<EOD
 <?php
 // This file is generated by $commandName, do not adjust manually
-// @codingStandardsIgnoreFile
+// phpcs:disable Generic.Files.LineLength
 global \${$this->variableName};
 
 \${$this->variableName} {$op} [