<commit_before><?php

namespace Build\Core\Bauhaus;

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

use Illuminate\Http\Response;
use Build\Core\Support\NestedSet;

class Mapper extends NestedSet
{

    // query types.
    const QUERY_TYPE_NONE = 'none';
    const QUERY_TYPE_SINGLE = 'single';
    const QUERY_TYPE_MULTIPLE = 'multiple';

    /**
     * Holds the query type.
     * @var string
     */
    protected $queryType = self::QUERY_TYPE_SINGLE;

    /**
     * Holds the mapper properties.
     * @var array
     */
    protected $properties = [];

    /**
     * Magic method getter/setter.
     *
     * @param  string  $method
     * @param  array   $arguments
     *
     * @return Mapper
     */
    public function __call($method, array $arguments = [])
    {
        if (isset($arguments[0])) {
            return $this->set($method, $arguments[0]);
        }

        return $this->get($method);
    }

    /**
     * Magic property setter.
     *
     * @param  string  $key
     * @param  mixed   $value
     *
     * @return $this
     */
    public function __set($key, $value)
    {
        $this->set($key, $value);

        return $this;
    }

    /**
     * Magic property getter.
     *
     * @param  string  $key
     *
     * @return mixed
     */
    public function __get($key)
    {
        return $this->get($key);
    }

    /**
     * Magic property `checker`.
     *
     * @param  string  $key
     *
     * @return bool
     */
    public function __isset($key)
    {
        return $this->has($key);
    }

    /**
     * Get a property on the implementing object.
     *
     * @param  string  $property
     * @param  mixed   $default
     *
     * @return mixed
     */
    public function get($property, $default = null)
    {
        if (! $this->has($property)) {
            return $default;
        }

        return $this->properties[$property];
    }

    /**
     * Get all the properties.
     *
     * @return array
     */
    public function getProperties()
    {
        return $this->properties;
    }

    /**
     * Check if the object has a certain property.
     *
     * @param  string  $property
     *
     * @return bool
     */
    public function has($property)
    {
        return isset($this->properties[$property]);
    }

    /**
     * Set a property on the implementing object.
     *
     * @param  string  $property
     * @param  mixed   $value
     *
     * @return $this
     */
    public function set($property, $value = null)
    {
        if (is_array($property)) {
            foreach ($property as $key => $value) {
                $this->set($key, $value);
            }

            return $this;
        }

        if (is_callable($value)) {
            switch ($this->getParent()->getQueryType()) {
                case self::QUERY_TYPE_SINGLE:
                    $this->properties[$property] = $value;
                    break;

                case self::QUERY_TYPE_MULTIPLE:
                    foreach (app('build.bauhaus.query') as $row) {
                        $this->setRow($row);
                        $this->properties[$property] = $value;
                    }
                    break;
            }

            return $this;
        }

        $this->properties[$property] = $value;

        return $this;
    }

    /**
     * Add a new child.
     *
     * @param  string         $instance
     * @param  \Closure|null  $callback
     *
     * @return $this
     * @throws \Exception
     */
    public function add($instance, $callback = null)
    {
        if (is_string($instance)) {
            if (! class_exists($instance)) {
                $instance = app('build.bauhaus.container')->get($instance);
            }

            if (!class_exists($instance)) {
                throw new \Exception("Mapper cannot create an instance of {$instance}. Make sure it exists in the config");
            }

            $instance = new $instance;
        }

        $instance->setParent($this);

        $this->addChild($instance);

        if (is_array($callback)) {
            foreach ($callback as $key => $value) {
                $instance->set($key, $value);
            }
        }

        if (is_callable($callback)) {
            $callback($instance);
        }

        return $this;
    }

    /**
     * Get the current query type.<commit_msg>fixed bauhaus missing widget instance exception<commit_after><?php

namespace Build\Core\Bauhaus;

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

use Illuminate\Http\Response;
use Build\Core\Support\NestedSet;

class Mapper extends NestedSet
{

    // query types.
    const QUERY_TYPE_NONE = 'none';
    const QUERY_TYPE_SINGLE = 'single';
    const QUERY_TYPE_MULTIPLE = 'multiple';

    /**
     * Holds the query type.
     * @var string
     */
    protected $queryType = self::QUERY_TYPE_SINGLE;

    /**
     * Holds the mapper properties.
     * @var array
     */
    protected $properties = [];

    /**
     * Magic method getter/setter.
     *
     * @param  string  $method
     * @param  array   $arguments
     *
     * @return Mapper
     */
    public function __call($method, array $arguments = [])
    {
        if (isset($arguments[0])) {
            return $this->set($method, $arguments[0]);
        }

        return $this->get($method);
    }

    /**
     * Magic property setter.
     *
     * @param  string  $key
     * @param  mixed   $value
     *
     * @return $this
     */
    public function __set($key, $value)
    {
        $this->set($key, $value);

        return $this;
    }

    /**
     * Magic property getter.
     *
     * @param  string  $key
     *
     * @return mixed
     */
    public function __get($key)
    {
        return $this->get($key);
    }

    /**
     * Magic property `checker`.
     *
     * @param  string  $key
     *
     * @return bool
     */
    public function __isset($key)
    {
        return $this->has($key);
    }

    /**
     * Get a property on the implementing object.
     *
     * @param  string  $property
     * @param  mixed   $default
     *
     * @return mixed
     */
    public function get($property, $default = null)
    {
        if (! $this->has($property)) {
            return $default;
        }

        return $this->properties[$property];
    }

    /**
     * Get all the properties.
     *
     * @return array
     */
    public function getProperties()
    {
        return $this->properties;
    }

    /**
     * Check if the object has a certain property.
     *
     * @param  string  $property
     *
     * @return bool
     */
    public function has($property)
    {
        return isset($this->properties[$property]);
    }

    /**
     * Set a property on the implementing object.
     *
     * @param  string  $property
     * @param  mixed   $value
     *
     * @return $this
     */
    public function set($property, $value = null)
    {
        if (is_array($property)) {
            foreach ($property as $key => $value) {
                $this->set($key, $value);
            }

            return $this;
        }

        if (is_callable($value)) {
            switch ($this->getParent()->getQueryType()) {
                case self::QUERY_TYPE_SINGLE:
                    $this->properties[$property] = $value;
                    break;

                case self::QUERY_TYPE_MULTIPLE:
                    foreach (app('build.bauhaus.query') as $row) {
                        $this->setRow($row);
                        $this->properties[$property] = $value;
                    }
                    break;
            }

            return $this;
        }

        $this->properties[$property] = $value;

        return $this;
    }

    /**
     * Add a new child.
     *
     * @param  string         $instance
     * @param  \Closure|null  $callback
     *
     * @return $this
     * @throws \Exception
     */
    public function add($instance, $callback = null)
    {
        if (is_string($instance)) {
            $class = $instance;

            if (! class_exists($instance)) {
                $instance = app('build.bauhaus.container')->get($instance);
            }

            // Try again.
            if (! class_exists($instance)) {
                throw new \Exception("Mapper cannot create an instance of `{$class}`. Make sure it exists in the config");
            }

            $instance = new $instance;
        }

        $instance->setParent($this);

        $this->addChild($instance);

        if (is_array($callback)) {
            foreach ($callback as $key => $value) {
                $instance->set($key, $value);
            }
        }

        if (is_callable($callback)) {
            $callback($instance);
        }

        return $this;
    }

    /**
     * Get the current query type.
{'fraction_non_alphanumeric': 0.12856362643364283, 'fraction_numerical': 0.0004369197160021846, 'mean_word_length': 1.5468706536856744, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 51, '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': '1059654', 'n_tokens_mistral': 2684, 'n_tokens_neox': 2604, 'n_words': 640}