original_string: private function expandClasses(array $patterns, array $classes)
      {
          $expanded = [];
  
          // Explicit classes declared in the patterns are returned directly
          foreach ($patterns as $key => $pattern) {
              if ('\\' !== substr($pattern, -1) && false === strpos($pattern, '*')) {
                  unset($patterns[$key]);
                  $expanded[] = ltrim($pattern, '\\');
              }
          }
  
          // Match patterns with the classes list
          $regexps = $this->patternsToRegexps($patterns);
  
          foreach ($classes as $class) {
              $class = ltrim($class, '\\');
  
              if ($this->matchAnyRegexps($class, $regexps)) {
                  $expanded[] = $class;
              }
          }
  
          return array_unique($expanded);
      }
code: private function expandClasses(array $patterns, array $classes)
      {
          $expanded = [];
  
          // Explicit classes declared in the patterns are returned directly
          foreach ($patterns as $key => $pattern) {
              if ('\\' !== substr($pattern, -1) && false === strpos($pattern, '*')) {
                  unset($patterns[$key]);
                  $expanded[] = ltrim($pattern, '\\');
              }
          }
  
          // Match patterns with the classes list
          $regexps = $this->patternsToRegexps($patterns);
  
          foreach ($classes as $class) {
              $class = ltrim($class, '\\');
  
              if ($this->matchAnyRegexps($class, $regexps)) {
                  $expanded[] = $class;
              }
          }
  
          return array_unique($expanded);
      }
code_tokens: private function expandClasses ( array $ patterns , array $ classes ) { $ expanded = [ ] ; // Explicit classes declared in the patterns are returned directly foreach ( $ patterns as $ key => $ pattern ) { if ( '\\' !== substr ( $ pattern , - 1 ) && false === strpos ( $ pattern , '*' ) ) { unset ( $ patterns [ $ key ] ) ; $ expanded [ ] = ltrim ( $ pattern , '\\' ) ; } } // Match patterns with the classes list $ regexps = $ this -> patternsToRegexps ( $ patterns ) ; foreach ( $ classes as $ class ) { $ class = ltrim ( $ class , '\\' ) ; if ( $ this -> matchAnyRegexps ( $ class , $ regexps ) ) { $ expanded [ ] = $ class ; } } return array_unique ( $ expanded ) ; }
docstring: Expands the given class patterns using a list of existing classes.
  
  @param array $patterns The class patterns to expand
  @param array $classes  The existing classes to match against the patterns
  
  @return array A list of classes derived from the patterns
docstring_tokens: Expands the given class patterns using a list of existing classes .