<commit_before><?php
/**
 * PHPSpec
 *
 * LICENSE
 *
 * This file is subject to the GNU Lesser General Public License Version 3
 * that is bundled with this package in the file LICENSE.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/lgpl-3.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category  PHPSpec
 * @package   PHPSpec
 * @copyright Copyright (c) 2007-2009 <NAME>, <NAME>
 * @copyright Copyright (c) 2010-2011 <NAME>, <NAME>,
 *                                    <NAME>
 * @license   http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
 */
namespace PHPSpec\Runner\Loader;

/**
 * @category   PHPSpec
 * @package    PHPSpec
 * @copyright  Copyright (c) 2007-2009 <NAME>, <NAME>
 * @copyright  Copyright (c) 2010-2011 <NAME>, <NAME>,
 *                                     <NAME>
 * @license    http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
 */
class DirectoryRecursive
{

    /**
     * Array with the instances of the loaded examples
     * 
     * @var array
     */
    protected $_loaded = array();

    /**
     * @FIXME! this property seems to be redundant and misleading.
     * 
     * @var array
     */
    protected $_loadedClasses = array();

    /**
     * The filter object
     * 
     * @var PHPSpec\Runner\Filter\Standard
     */
    protected $_filter = null;

    /**
     * The name of the filter class
     * 
     * @var string
     */
    protected $_filterName = '\PHPSpec\Runner\Filter\Standard';

    /**
     * The directory being scanned
     * 
     * @var \RecursiveIteratorIterator
     */
    protected $_directory = null;

    /**
     * Loads the directory
     * 
     * @param string $directory
     * @return array
     */
    public function load($directory)
    {
        $this->_directory = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator($directory)
        );

        $filterIterator = $this->getFilter();

        foreach ($filterIterator as $file) {
            $pathName = $file->getPathname();
            require_once $pathName;
            
            $class = $this->_getClassName($file);
            if ($class && !in_array($class, $this->_loadedClasses)) {
                $classReflected = new \ReflectionClass($class);
                $this->_loaded[] = $classReflected;
            }
        }

        return $this->_loaded;
    }

    /**
     * Gets the loaded examples
     * 
     * @return array
     */
    public function getLoaded()
    {
        return $this->_loaded;
    }

    /**
     * Sets the filter name
     * 
     * @param string $filterName
     */
    public function setFilterClass($filterName)
    {
        $this->_filterName = $filterName;
    }

    /**
     * Gets the filter object
     * 
     * @throws \Exception
     * @return \PHPSpec\Runner\Filter\Standard
     */
    public function getFilter()
    {
        if (is_null($this->_filter)) {
            if (is_null($this->_directory)) {
                throw new \Exception();
            }
            $reflection = new \ReflectionClass($this->_filterName);
            $this->_filter = $reflection->newInstance($this->_directory);
        }
        return $this->_filter;
    }
    
    /**
     * Gets a class name based on the file
     * 
     * @param \SplFileInfo $file
     * @return string
     */
    protected function _getClassName(\SplFileInfo $file)
    {
        $fileName = $file->getFilename();
        $className = substr($fileName, 0, strlen($fileName) - 4);
        $secondName = 'Describe' . substr($fileName, 0, strlen($fileName) - 8);
        $thirdName = 'describe' . substr($fileName, 0, strlen($fileName) - 8);
        if (class_exists($className, false)) {
            $class = $className;
        } elseif (class_exists($secondName, false)) {
            $class = $secondName;<commit_msg>Quick hotfix related to namespaces in php 5.3.2 loading directories<commit_after><?php
/**
 * PHPSpec
 *
 * LICENSE
 *
 * This file is subject to the GNU Lesser General Public License Version 3
 * that is bundled with this package in the file LICENSE.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/lgpl-3.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category  PHPSpec
 * @package   PHPSpec
 * @copyright Copyright (c) 2007-2009 <NAME>, <NAME>
 * @copyright Copyright (c) 2010-2011 <NAME>, <NAME>,
 *                                    <NAME>
 * @license   http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
 */
namespace PHPSpec\Runner\Loader;

/**
 * @category   PHPSpec
 * @package    PHPSpec
 * @copyright  Copyright (c) 2007-2009 <NAME>, <NAME>
 * @copyright  Copyright (c) 2010-2011 <NAME>, <NAME>,
 *                                     <NAME>
 * @license    http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
 */
class DirectoryRecursive
{

    /**
     * Array with the instances of the loaded examples
     * 
     * @var array
     */
    protected $_loaded = array();

    /**
     * @FIXME! this property seems to be redundant and misleading.
     * 
     * @var array
     */
    protected $_loadedClasses = array();

    /**
     * The filter object
     * 
     * @var PHPSpec\Runner\Filter\Standard
     */
    protected $_filter = null;

    /**
     * The name of the filter class
     * 
     * @var string
     */
    protected $_filterName = '\PHPSpec\Runner\Filter\Standard';

    /**
     * The directory being scanned
     * 
     * @var \RecursiveIteratorIterator
     */
    protected $_directory = null;

    /**
     * Loads the directory
     * 
     * @param string $directory
     * @return array
     */
    public function load($directory)
    {
        $this->_directory = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator($directory)
        );

        $filterIterator = $this->getFilter();

        foreach ($filterIterator as $file) {
            $pathName = $file->getPathname();
            require_once $pathName;
            
            $class = $this->_getClassName($file);
            if ($class && !in_array($class, $this->_loadedClasses)) {
                $classReflected = new \ReflectionClass($class);
                $this->_loaded[] = $classReflected;
            }
        }

        return $this->_loaded;
    }

    /**
     * Gets the loaded examples
     * 
     * @return array
     */
    public function getLoaded()
    {
        return $this->_loaded;
    }

    /**
     * Sets the filter name
     * 
     * @param string $filterName
     */
    public function setFilterClass($filterName)
    {
        $this->_filterName = $filterName;
    }

    /**
     * Gets the filter object
     * 
     * @throws \Exception
     * @return \PHPSpec\Runner\Filter\Standard
     */
    public function getFilter()
    {
        if (is_null($this->_filter)) {
            if (is_null($this->_directory)) {
                throw new \Exception();
            }
            // hack for 5.3.2 bug
            if ($this->_filterName === '\PHPSpec\Runner\Filter\Standard') {
                return new \PHPSpec\Runner\Filter\Standard($this->_directory);
            }
            $reflection = new \ReflectionClass($this->_filterName);
            $this->_filter = $reflection->newInstance($this->_directory);
        }
        return $this->_filter;
    }
    
    /**
     * Gets a class name based on the file
     * 
     * @param \SplFileInfo $file
     * @return string
     */
    protected function _getClassName(\SplFileInfo $file)
    {
        $fileName = $file->getFilename();
        $className = substr($fileName, 0, strlen($fileName) - 4);
        $secondName = 'Describe' . substr($fileName, 0, strlen($fileName) - 8);
        $thirdName = 'describe' . substr($fileName, 0, strlen($fileName) - 8);
        if (class_exists($className, false)) {
            $class = $className;
        } elseif (class_exists($secondName, false)) {
            $class = $secondName;
{'fraction_non_alphanumeric': 0.12334486460694262, 'fraction_numerical': 0.011928903733746868, 'mean_word_length': 1.9815078236130867, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6712963', 'n_tokens_mistral': 2459, 'n_tokens_neox': 2346, 'n_words': 646}