original_string: public static function readDir($dir, $return = Util::ALL, $recursive = false, $extension = NULL, $nameOnly = false, array $options = array()) {
          if (!is_dir($dir))
              return array(
                  'error' => 'Directory "' . $dir . '" does not exist',
              );
  
          if (!is_array($extension) && !empty($extension)) {
              $extension = array($extension);
          }
  
          if (substr($dir, strlen($dir) - 1) !== DIRECTORY_SEPARATOR)
              $dir .= DIRECTORY_SEPARATOR;
  
          $toReturn = array('dirs' => array(), 'files' => array());
          try {
              foreach (scandir($dir) as $current) {
                  if (in_array($current, array('.', '..')))
                      continue;
  
                  if (is_dir($dir . $current)) {
                      if (in_array($return, array(self::DIRS_ONLY, self::ALL))) {
                          $toReturn['dirs'][] = ($nameOnly) ? $current : $dir . $current;
                      }
                      if ($recursive) {
                          $toReturn = array_merge_recursive($toReturn, self::readDir($dir . $current, self::ALL, true, $extension, $nameOnly, $options));
                      }
                  } else if (is_file($dir . $current) && in_array($return, array(self::FILES_ONLY, self::ALL))) {
                      if ($extension)
                          $info = pathinfo($current);
                      if (empty($extension) || (is_array($extension) && in_array($info['extension'], $extension))) {
                          $toReturn['files'][$dir][] = ($nameOnly) ? $current : $dir . $current;
                      }
                  }
              }
  
              if ($return == self::ALL)
                  return $toReturn;
              elseif ($return == self::DIRS_ONLY)
                  return $toReturn['dirs'];
              elseif ($return == self::FILES_ONLY)
                  return $toReturn['files'];
          } catch (\Exception $ex) {
              throw new \Exception($ex->getMessage());
          }
      }
code: public static function readDir($dir, $return = Util::ALL, $recursive = false, $extension = NULL, $nameOnly = false, array $options = array()) {
          if (!is_dir($dir))
              return array(
                  'error' => 'Directory "' . $dir . '" does not exist',
              );
  
          if (!is_array($extension) && !empty($extension)) {
              $extension = array($extension);
          }
  
          if (substr($dir, strlen($dir) - 1) !== DIRECTORY_SEPARATOR)
              $dir .= DIRECTORY_SEPARATOR;
  
          $toReturn = array('dirs' => array(), 'files' => array());
          try {
              foreach (scandir($dir) as $current) {
                  if (in_array($current, array('.', '..')))
                      continue;
  
                  if (is_dir($dir . $current)) {
                      if (in_array($return, array(self::DIRS_ONLY, self::ALL))) {
                          $toReturn['dirs'][] = ($nameOnly) ? $current : $dir . $current;
                      }
                      if ($recursive) {
                          $toReturn = array_merge_recursive($toReturn, self::readDir($dir . $current, self::ALL, true, $extension, $nameOnly, $options));
                      }
                  } else if (is_file($dir . $current) && in_array($return, array(self::FILES_ONLY, self::ALL))) {
                      if ($extension)
                          $info = pathinfo($current);
                      if (empty($extension) || (is_array($extension) && in_array($info['extension'], $extension))) {
                          $toReturn['files'][$dir][] = ($nameOnly) ? $current : $dir . $current;
                      }
                  }
              }
  
              if ($return == self::ALL)
                  return $toReturn;
              elseif ($return == self::DIRS_ONLY)
                  return $toReturn['dirs'];
              elseif ($return == self::FILES_ONLY)
                  return $toReturn['files'];
          } catch (\Exception $ex) {
              throw new \Exception($ex->getMessage());
          }
      }
code_tokens: public static function readDir ( $ dir , $ return = Util :: ALL , $ recursive = false , $ extension = NULL , $ nameOnly = false , array $ options = array ( ) ) { if ( ! is_dir ( $ dir ) ) return array ( 'error' => 'Directory "' . $ dir . '" does not exist' , ) ; if ( ! is_array ( $ extension ) && ! empty ( $ extension ) ) { $ extension = array ( $ extension ) ; } if ( substr ( $ dir , strlen ( $ dir ) - 1 ) !== DIRECTORY_SEPARATOR ) $ dir .= DIRECTORY_SEPARATOR ; $ toReturn = array ( 'dirs' => array ( ) , 'files' => array ( ) ) ; try { foreach ( scandir ( $ dir ) as $ current ) { if ( in_array ( $ current , array ( '.' , '..' ) ) ) continue ; if ( is_dir ( $ dir . $ current ) ) { if ( in_array ( $ return , array ( self :: DIRS_ONLY , self :: ALL ) ) ) { $ toReturn [ 'dirs' ] [ ] = ( $ nameOnly ) ? $ current : $ dir . $ current ; } if ( $ recursive ) { $ toReturn = array_merge_recursive ( $ toReturn , self :: readDir ( $ dir . $ current , self :: ALL , true , $ extension , $ nameOnly , $ options ) ) ; } } else if ( is_file ( $ dir . $ current ) && in_array ( $ return , array ( self :: FILES_ONLY , self :: ALL ) ) ) { if ( $ extension ) $ info = pathinfo ( $ current ) ; if ( empty ( $ extension ) || ( is_array ( $ extension ) && in_array ( $ info [ 'extension' ] , $ extension ) ) ) { $ toReturn [ 'files' ] [ $ dir ] [ ] = ( $ nameOnly ) ? $ current : $ dir . $ current ; } } } if ( $ return == self :: ALL ) return $ toReturn ; elseif ( $ return == self :: DIRS_ONLY ) return $ toReturn [ 'dirs' ] ; elseif ( $ return == self :: FILES_ONLY ) return $ toReturn [ 'files' ] ; } catch ( \ Exception $ ex ) { throw new \ Exception ( $ ex -> getMessage ( ) ) ; } }
docstring: Reads the required source directory
  @param string $dir
  @param int $return
  @param boolean $recursive
  @param string|array\null $extension Extensions without the dot (.)
  @param boolean $nameOnly Indicates whether to return full path of dirs/files or names only
  @param array $options keys include:
  @return array
  @throws \Exception
docstring_tokens: Reads the required source directory