<commit_before><?php

/*
 * This file is part of the symfony package.
 * (c) 2004-2006 <NAME> <<EMAIL>>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 *
 * @package    symfony
 * @subpackage util
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id$
 */

/**
 *
 * Allow to build rules to find files and directories.
 *
 * All rules may be invoked several times, except for ->in() method.
 * Some rules are cumulative (->name() for example) whereas others are destructive
 * (most recent value is used, ->maxdepth() method for example).
 *
 * All methods return the current sfFinder object to allow easy chaining:
 *
 * $files = sfFinder::type('file')->name('*.php')->in(.);
 *
 * Interface loosely based on perl File::Find::Rule module.
 *
 * @package    symfony
 * @subpackage util
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id$
 */
class sfFinder
{
  protected $type        = 'file';
  protected $names       = array();
  protected $prunes      = array();
  protected $discards    = array();
  protected $execs       = array();
  protected $mindepth    = 0;
  protected $sizes       = array();
  protected $maxdepth    = 1000000;
  protected $relative    = false;
  protected $follow_link = false;

  /**
   * Sets maximum directory depth.
   *
   * Finder will descend at most $level levels of directories below the starting point.
   *
   * @param  integer level
   * @return object current sfFinder object
   */
  public function maxdepth($level)
  {
    $this->maxdepth = $level;

    return $this;
  }

  /**
   * Sets minimum directory depth.
   *
   * Finder will start applying tests at level $level.
   *
   * @param  integer level
   * @return object current sfFinder object
   */
  public function mindepth($level)
  {
    $this->mindepth = $level;

    return $this;
  }

  public function get_type()
  {
    return $this->type;
  }

  /**
   * Sets the type of elements to returns.
   *
   * @param  string directory or file or any (for both file and directory)
   * @return object new sfFinder object
   */
  public static function type($name)
  {
    $finder = new sfFinder();

    if (strtolower(substr($name, 0, 3)) == 'dir')
    {
      $finder->type = 'directory';
    }
    else if (strtolower($name) == 'any')
    {
      $finder->type = 'any';
    }
    else
    {
      $finder->type = 'file';
    }

    return $finder;
  }

  /*
   * glob, patterns (must be //) or strings
   */
  protected function to_regex($str)
  {
    if ($str{0} == '/' && $str{strlen($str) - 1} == '/')
    {
      return $str;
    }
    else
    {
      return sfGlobToRegex::glob_to_regex($str);<commit_msg>added a new setType() method to sfFinder<commit_after><?php

/*
 * This file is part of the symfony package.
 * (c) 2004-2006 <NAME> <<EMAIL>>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 *
 * @package    symfony
 * @subpackage util
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id$
 */

/**
 *
 * Allow to build rules to find files and directories.
 *
 * All rules may be invoked several times, except for ->in() method.
 * Some rules are cumulative (->name() for example) whereas others are destructive
 * (most recent value is used, ->maxdepth() method for example).
 *
 * All methods return the current sfFinder object to allow easy chaining:
 *
 * $files = sfFinder::type('file')->name('*.php')->in(.);
 *
 * Interface loosely based on perl File::Find::Rule module.
 *
 * @package    symfony
 * @subpackage util
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id$
 */
class sfFinder
{
  protected $type        = 'file';
  protected $names       = array();
  protected $prunes      = array();
  protected $discards    = array();
  protected $execs       = array();
  protected $mindepth    = 0;
  protected $sizes       = array();
  protected $maxdepth    = 1000000;
  protected $relative    = false;
  protected $follow_link = false;

  /**
   * Sets maximum directory depth.
   *
   * Finder will descend at most $level levels of directories below the starting point.
   *
   * @param  integer level
   * @return object current sfFinder object
   */
  public function maxdepth($level)
  {
    $this->maxdepth = $level;

    return $this;
  }

  /**
   * Sets minimum directory depth.
   *
   * Finder will start applying tests at level $level.
   *
   * @param  integer level
   * @return object current sfFinder object
   */
  public function mindepth($level)
  {
    $this->mindepth = $level;

    return $this;
  }

  public function get_type()
  {
    return $this->type;
  }

  /**
   * Sets the type of elements to returns.
   *
   * @param  string directory or file or any (for both file and directory)
   * @return object new sfFinder object
   */
  public static function type($name)
  {
    $finder = new sfFinder();
    return $finder->setType($name);
  }

  public function setType($name)
  {
    if (strtolower(substr($name, 0, 3)) == 'dir')
    {
      $this->type = 'directory';
    }
    else if (strtolower($name) == 'any')
    {
      $this->type = 'any';
    }
    else
    {
      $this->type = 'file';
    }

    return $this;
  }

  /*
   * glob, patterns (must be //) or strings
   */
  protected function to_regex($str)
  {
    if ($str{0} == '/' && $str{strlen($str) - 1} == '/')
    {
      return $str;
    }
    else
    {
      return sfGlobToRegex::glob_to_regex($str);
{'fraction_non_alphanumeric': 0.1349005424954792, 'fraction_numerical': 0.007233273056057866, 'mean_word_length': 2.5706907682375726, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3800051', 'n_tokens_mistral': 1776, 'n_tokens_neox': 1728, 'n_words': 560}