*/
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
}
}
+ /**
+ * 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.
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 )
);
/**
* Generates a PHP file setting up autoload information.
*
- * @param {string} $commandName Command name to include in comment
- * @param {string} $filename of PHP file to put autoload information in.
+ * @param string $commandName Command name to include in comment
+ * @param string $filename of PHP file to put autoload information in.
* @return string
*/
protected function generatePHPAutoload( $commandName, $filename ) {
}
$output = implode( "\n\t", $content );
- return
- <<<EOD
+ return <<<EOD
<?php
// This file is generated by $commandName, do not adjust manually
-// @codingStandardsIgnoreFile
+// phpcs:ignoreFile Generic.Files.LineLength
global \${$this->variableName};
\${$this->variableName} {$op} [
// Note: When changing class name discovery logic,
// AutoLoaderTest.php may also need to be updated.
switch ( $token[0] ) {
- case T_NAMESPACE:
- case T_CLASS:
- case T_INTERFACE:
- case T_TRAIT:
- case T_DOUBLE_COLON:
- $this->startToken = $token;
- break;
- case T_STRING:
- if ( $token[1] === 'class_alias' ) {
+ case T_NAMESPACE:
+ case T_CLASS:
+ case T_INTERFACE:
+ case T_TRAIT:
+ case T_DOUBLE_COLON:
$this->startToken = $token;
- $this->alias = [];
- }
+ break;
+ case T_STRING:
+ if ( $token[1] === 'class_alias' ) {
+ $this->startToken = $token;
+ $this->alias = [];
+ }
}
}
*/
protected function tryEndExpect( $token ) {
switch ( $this->startToken[0] ) {
- case T_DOUBLE_COLON:
- // Skip over T_CLASS after T_DOUBLE_COLON because this is something like
- // "self::static" which accesses the class name. It doens't define a new class.
- $this->startToken = null;
- break;
- case T_NAMESPACE:
- if ( $token === ';' || $token === '{' ) {
- $this->namespace = $this->implodeTokens() . '\\';
- } else {
- $this->tokens[] = $token;
- }
- break;
-
- case T_STRING:
- if ( $this->alias !== null ) {
- // Flow 1 - Two string literals:
- // - T_STRING class_alias
- // - '('
- // - T_CONSTANT_ENCAPSED_STRING 'TargetClass'
- // - ','
- // - T_WHITESPACE
- // - T_CONSTANT_ENCAPSED_STRING 'AliasName'
- // - ')'
- // Flow 2 - Use of ::class syntax for first parameter
- // - T_STRING class_alias
- // - '('
- // - T_STRING TargetClass
- // - T_DOUBLE_COLON ::
- // - T_CLASS class
- // - ','
- // - T_WHITESPACE
- // - T_CONSTANT_ENCAPSED_STRING 'AliasName'
- // - ')'
- if ( $token === '(' ) {
- // Start of a function call to class_alias()
- $this->alias = [ 'target' => false, 'name' => false ];
- } elseif ( $token === ',' ) {
- // Record that we're past the first parameter
- if ( $this->alias['target'] === false ) {
- $this->alias['target'] = true;
- }
- } elseif ( is_array( $token ) && $token[0] === T_CONSTANT_ENCAPSED_STRING ) {
- if ( $this->alias['target'] === true ) {
- // We already saw a first argument, this must be the second.
- // Strip quotes from the string literal.
- $this->alias['name'] = substr( $token[1], 1, -1 );
+ case T_DOUBLE_COLON:
+ // Skip over T_CLASS after T_DOUBLE_COLON because this is something like
+ // "self::static" which accesses the class name. It doens't define a new class.
+ $this->startToken = null;
+ break;
+ case T_NAMESPACE:
+ if ( $token === ';' || $token === '{' ) {
+ $this->namespace = $this->implodeTokens() . '\\';
+ } else {
+ $this->tokens[] = $token;
+ }
+ break;
+
+ case T_STRING:
+ if ( $this->alias !== null ) {
+ // Flow 1 - Two string literals:
+ // - T_STRING class_alias
+ // - '('
+ // - T_CONSTANT_ENCAPSED_STRING 'TargetClass'
+ // - ','
+ // - T_WHITESPACE
+ // - T_CONSTANT_ENCAPSED_STRING 'AliasName'
+ // - ')'
+ // Flow 2 - Use of ::class syntax for first parameter
+ // - T_STRING class_alias
+ // - '('
+ // - T_STRING TargetClass
+ // - T_DOUBLE_COLON ::
+ // - T_CLASS class
+ // - ','
+ // - T_WHITESPACE
+ // - T_CONSTANT_ENCAPSED_STRING 'AliasName'
+ // - ')'
+ if ( $token === '(' ) {
+ // Start of a function call to class_alias()
+ $this->alias = [ 'target' => false, 'name' => false ];
+ } elseif ( $token === ',' ) {
+ // Record that we're past the first parameter
+ if ( $this->alias['target'] === false ) {
+ $this->alias['target'] = true;
+ }
+ } elseif ( is_array( $token ) && $token[0] === T_CONSTANT_ENCAPSED_STRING ) {
+ if ( $this->alias['target'] === true ) {
+ // We already saw a first argument, this must be the second.
+ // Strip quotes from the string literal.
+ $this->alias['name'] = substr( $token[1], 1, -1 );
+ }
+ } elseif ( $token === ')' ) {
+ // End of function call
+ $this->classes[] = $this->alias['name'];
+ $this->alias = null;
+ $this->startToken = null;
+ } elseif ( !is_array( $token ) || (
+ $token[0] !== T_STRING &&
+ $token[0] !== T_DOUBLE_COLON &&
+ $token[0] !== T_CLASS &&
+ $token[0] !== T_WHITESPACE
+ ) ) {
+ // Ignore this call to class_alias() - compat/Timestamp.php
+ $this->alias = null;
+ $this->startToken = null;
}
- } elseif ( $token === ')' ) {
- // End of function call
- $this->classes[] = $this->alias['name'];
- $this->alias = null;
- $this->startToken = null;
- } elseif ( !is_array( $token ) || (
- $token[0] !== T_STRING &&
- $token[0] !== T_DOUBLE_COLON &&
- $token[0] !== T_CLASS &&
- $token[0] !== T_WHITESPACE
- ) ) {
- // Ignore this call to class_alias() - compat/Timestamp.php
- $this->alias = null;
- $this->startToken = null;
}
- }
- break;
-
- case T_CLASS:
- case T_INTERFACE:
- case T_TRAIT:
- $this->tokens[] = $token;
- if ( is_array( $token ) && $token[0] === T_STRING ) {
- $this->classes[] = $this->namespace . $this->implodeTokens();
- }
+ break;
+
+ case T_CLASS:
+ case T_INTERFACE:
+ case T_TRAIT:
+ $this->tokens[] = $token;
+ if ( is_array( $token ) && $token[0] === T_STRING ) {
+ $this->classes[] = $this->namespace . $this->implodeTokens();
+ }
}
}