<commit_before><?php
namespace Stikman;
/**
 * This is a blocking PHP process that will watch the files in a specific directory
 * 1 level deep an emit events when files change accordingly. You can attach event
 * observers to the different file events to react to.
 *
 * @author <NAME>
 * @since 2015-06-10
 */
use Evenement\EventEmitterTrait;

class FileWatcher
{
    use EventEmitterTrait;

    /**
     * Event list for internal file watch events
     */
    const CREATE = 'create';
    const MODIFIED = 'modified';
    const DELETE = 'delete';

    /**
     * list of files currently pulled from the directory being watched
     * @var array
     */
    protected $files = array();

    /**
     * List of previous files scanned from the watch directory
     * @var array
     */
    protected $lastFiles = array();

    /**
     * Glob pattern used in glob method call to restrict results
     * @var string
     */
    protected $pattern;

    /**
     * Name of the directory to watch for changes
     * @var string
     */
    protected $directory;

    /**
     * Number of milliseconds to wait before rescanning the directory
     * @var int
     */
    protected $interval;

    /**
     * list of current file md5 hashes for comparison
     * @var array
     */
    protected $fileHashes = array();

    /**
     * list of previous file md5 hashes for comparison
     * @var array
     */
    protected $lastFileHashes = array();

    /**
     * Options to pass into the glob function
     * @var integer
     */
    protected $globOptions;

    /**
     * Tell the system to stop after set number of iterations.
     * The default is to run forever.
     * @var int
     */
    protected $iterations = -1;

    /**
     * This will setup the Directory Watcher.
     *
     * @param string $directory
     * @param string $pattern
     * @param int $interval in milliseconds
     * @throws \InvalidArgumentException
     */
    public function __construct($directory, $pattern = "*.{*}", $interval = 10)
    {
        if(empty($directory)) {
            throw new \InvalidArgumentException("You must pass in a non-empty directory to watch");
        }

        if(!is_dir($directory)) {
            throw new \InvalidArgumentException("The directory $directory does not exist on the file system. ");
        }

        if(!is_int($interval)) {
            throw new \InvalidArgumentException("The interval must be va valid integer to set the microseconds to watch");
        }

        $this->directory = $directory;
        $this->pattern = $pattern;
        $this->setGlobOptions(GLOB_NOSORT | GLOB_BRACE);
        $this->setInterval($interval);
    }

    /**
     * Number in milliseconds to wait before rescanning the watch directory for changes.
     * @return int
     */<commit_msg>updates to use sort<commit_after><?php
namespace Stikman;
/**
 * This is a blocking PHP process that will watch the files in a specific directory
 * 1 level deep an emit events when files change accordingly. You can attach event
 * observers to the different file events to react to.
 *
 * @author <NAME>
 * @since 2015-06-10
 */
use Evenement\EventEmitterTrait;

class FileWatcher
{
    use EventEmitterTrait;

    /**
     * Event list for internal file watch events
     */
    const CREATE = 'create';
    const MODIFIED = 'modified';
    const DELETE = 'delete';

    /**
     * list of files currently pulled from the directory being watched
     * @var array
     */
    protected $files = array();

    /**
     * List of previous files scanned from the watch directory
     * @var array
     */
    protected $lastFiles = array();

    /**
     * Glob pattern used in glob method call to restrict results
     * @var string
     */
    protected $pattern;

    /**
     * Name of the directory to watch for changes
     * @var string
     */
    protected $directory;

    /**
     * Number of milliseconds to wait before rescanning the directory
     * @var int
     */
    protected $interval;

    /**
     * list of current file md5 hashes for comparison
     * @var array
     */
    protected $fileHashes = array();

    /**
     * list of previous file md5 hashes for comparison
     * @var array
     */
    protected $lastFileHashes = array();

    /**
     * Options to pass into the glob function
     * @var integer
     */
    protected $globOptions;

    /**
     * Tell the system to stop after set number of iterations.
     * The default is to run forever.
     * @var int
     */
    protected $iterations = -1;

    /**
     * This will setup the Directory Watcher.
     *
     * @param string $directory
     * @param string $pattern
     * @param int $interval in milliseconds
     * @throws \InvalidArgumentException
     */
    public function __construct($directory, $pattern = "*.{*}", $interval = 10)
    {
        if(empty($directory)) {
            throw new \InvalidArgumentException("You must pass in a non-empty directory to watch");
        }

        if(!is_dir($directory)) {
            throw new \InvalidArgumentException("The directory $directory does not exist on the file system. ");
        }

        if(!is_int($interval)) {
            throw new \InvalidArgumentException("The interval must be va valid integer to set the microseconds to watch");
        }

        $this->directory = $directory;
        $this->pattern = $pattern;
        $this->setGlobOptions(GLOB_BRACE);
        $this->setInterval($interval);
    }

    /**
     * Number in milliseconds to wait before rescanning the watch directory for changes.
     * @return int
     */
{'fraction_non_alphanumeric': 0.09660714285714286, 'fraction_numerical': 0.005, 'mean_word_length': 2.2488399071925755, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '3056401', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1455, 'n_words': 562}