<commit_before><?php
/**
 * SimpleComplex PHP Inspect
 * @link      https://github.com/simplecomplex/inspect
 * @copyright Copyright (c) 2011-2017 <NAME>
 * @license   https://github.com/simplecomplex/inspect/blob/master/LICENSE (MIT License)
 */
declare(strict_types=1);

namespace SimpleComplex\Inspect\Helper;

use SimpleComplex\Inspect\Inspector;

/**
 * Configuration proxy.
 *
 * We cannot know the workings of a framework's configuration mechanism.
 * To accommodate Inspect in a framework, extend this class.
 * @see Config::__get()
 *
 *
 * @see Inspector::DEPTH_DEFAULT
 * @see Inspector::TRACE_DEPTH_DEFAULT
 * @property-read int|null $depth
 *
 * @see Inspector::TRACE_LIMIT_DEFAULT
 * @property-read int|null $trace_limit
 *
 * @see Inspector::TRUNCATE_DEFAULT
 * @property-read int|null $truncate
 *
 * @see Inspector::ESCAPE_HTML
 * @property-read bool|null $escape_html
 *
 * @see Inspector::OUTPUT_DEFAULT
 * @property-read int|null $output_max
 *
 * @see Inspector::EXEC_TIMEOUT_DEFAULT
 * @property-read int|null $exectime_percent
 *
 * @see Inspector::ROOT_DIR_REPLACE
 * @property-read bool|null $rootdir_replace
 *
 *
 * @package SimpleComplex\Inspect
 */
class Config implements \Countable, \Iterator /*~ Traversable*/, \JsonSerializable
{
    /**
     * Keys list supported property names.
     *
     * Associative array to make extension simpler;
     * PROPERTIES[...] + Parent::PROPERTIES.
     *
     * @var bool[]
     */
    const PROPERTIES = [
        'depth' => true,
        'trace_limit' => true,
        'truncate' => true,
        'escape_html' => true,
        'output_max' => true,
        'exectime_percent' => true,
        'rootdir_replace' => true,
    ];

    /**
     * Injected configuration object, or null.
     *
     * @var object|null
     */
    protected $config;

    /**
     * For count()'ing and foreach'ing.
     *
     * @var string[]
     */
    protected $explorableIndex;

    /**
     * @param object|null $config
     *      Null if no custom value(s), overriding Inspecter defaults.
     */
    public function __construct(?object $config = null)
    {
        $this->config = $config;

        // Copy.
        $this->explorableIndex = array_keys(static::PROPERTIES);
    }

    /**
     * Get a configuration property.
     *
     * Supports simplecomplex configuration regime
     * plus simple direct access: $this->config->{$name} ?? null;
     *
     * @param string $name
     *
     * @return mixed|null
     *
     * @throws \OutOfBoundsException
     *      If unsupported configuration property name.
     */
    public function __get(string $name)
    {
        static $useGetMethod;
        if (array_key_exists($name, static::PROPERTIES)) {
            if (!$this->config) {
                return null;
            }
            if (!$useGetMethod) {
                if (class_exists($interface = '\\SimpleComplex\\Config\\Interfaces\\SectionedConfigInterface')
                    && is_subclass_of($this->config, $interface)
                ) {
                    $useGetMethod = 1;
                }
                else {
                    $useGetMethod = -1;
                }
            }
            if ($useGetMethod == 1) {
                /**
                 * \SimpleComplex\Config\Interfaces\SectionedConfigInterface
                 */
                return $this->config->get('lib_simplecomplex_inspect', $name, null);
            }<commit_msg>Use interface_exists() when interface; not class_exists().<commit_after><?php
/**
 * SimpleComplex PHP Inspect
 * @link      https://github.com/simplecomplex/inspect
 * @copyright Copyright (c) 2011-2017 <NAME>
 * @license   https://github.com/simplecomplex/inspect/blob/master/LICENSE (MIT License)
 */
declare(strict_types=1);

namespace SimpleComplex\Inspect\Helper;

use SimpleComplex\Inspect\Inspector;

/**
 * Configuration proxy.
 *
 * We cannot know the workings of a framework's configuration mechanism.
 * To accommodate Inspect in a framework, extend this class.
 * @see Config::__get()
 *
 *
 * @see Inspector::DEPTH_DEFAULT
 * @see Inspector::TRACE_DEPTH_DEFAULT
 * @property-read int|null $depth
 *
 * @see Inspector::TRACE_LIMIT_DEFAULT
 * @property-read int|null $trace_limit
 *
 * @see Inspector::TRUNCATE_DEFAULT
 * @property-read int|null $truncate
 *
 * @see Inspector::ESCAPE_HTML
 * @property-read bool|null $escape_html
 *
 * @see Inspector::OUTPUT_DEFAULT
 * @property-read int|null $output_max
 *
 * @see Inspector::EXEC_TIMEOUT_DEFAULT
 * @property-read int|null $exectime_percent
 *
 * @see Inspector::ROOT_DIR_REPLACE
 * @property-read bool|null $rootdir_replace
 *
 *
 * @package SimpleComplex\Inspect
 */
class Config implements \Countable, \Iterator /*~ Traversable*/, \JsonSerializable
{
    /**
     * Keys list supported property names.
     *
     * Associative array to make extension simpler;
     * PROPERTIES[...] + Parent::PROPERTIES.
     *
     * @var bool[]
     */
    const PROPERTIES = [
        'depth' => true,
        'trace_limit' => true,
        'truncate' => true,
        'escape_html' => true,
        'output_max' => true,
        'exectime_percent' => true,
        'rootdir_replace' => true,
    ];

    /**
     * Injected configuration object, or null.
     *
     * @var object|null
     */
    protected $config;

    /**
     * For count()'ing and foreach'ing.
     *
     * @var string[]
     */
    protected $explorableIndex;

    /**
     * @param object|null $config
     *      Null if no custom value(s), overriding Inspecter defaults.
     */
    public function __construct(?object $config = null)
    {
        $this->config = $config;

        // Copy.
        $this->explorableIndex = array_keys(static::PROPERTIES);
    }

    /**
     * Get a configuration property.
     *
     * Supports simplecomplex configuration regime
     * plus simple direct access: $this->config->{$name} ?? null;
     *
     * @param string $name
     *
     * @return mixed|null
     *
     * @throws \OutOfBoundsException
     *      If unsupported configuration property name.
     */
    public function __get(string $name)
    {
        static $useGetMethod;
        if (array_key_exists($name, static::PROPERTIES)) {
            if (!$this->config) {
                return null;
            }
            if (!$useGetMethod) {
                $interface = '\\SimpleComplex\\Config\\Interfaces\\SectionedConfigInterface';
                if (interface_exists($interface)
                    && is_subclass_of($this->config, $interface)
                ) {
                    $useGetMethod = 1;
                }
                else {
                    $useGetMethod = -1;
                }
            }
            if ($useGetMethod == 1) {
                /**
                 * \SimpleComplex\Config\Interfaces\SectionedConfigInterface
                 */
                return $this->config->get('lib_simplecomplex_inspect', $name, null);
            }
{'fraction_non_alphanumeric': 0.12372613750538251, 'fraction_numerical': 0.0034448112530500933, 'mean_word_length': 2.2081031307550645, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, 'https://': 4, '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': '4188391', 'n_tokens_mistral': 2065, 'n_tokens_neox': 1982, 'n_words': 442}