<commit_before><?php

namespace Cocur\Vale;

/**
 * Accessor
 *
 * @package   Cocur\Vale
 * @author    <NAME> <<EMAIL>>
 * @copyright 2015 <NAME>
 */
class Accessor
{
    /**
     * @var mixed
     */
    protected $data;

    /**
     * @var mixed
     */
    protected $current;

    /**
     * @param mixed $data
     */
    public function __construct($data)
    {
        if (is_array($data)) {
            $this->data    = &$data;
            $this->current = &$data;
        } else {
            $this->data    = $data;
            $this->current = $data;
        }
    }

    /**
     * @return mixed
     */
    public function getData()
    {
        return $this->data;
    }

    /**
     * @return mixed
     */
    public function getCurrent()
    {
        return $this->current;
    }

    /**
     * Navigates to `$key`.
     *
     * @param string|int $key
     *
     * @return bool `true` if it is possible to navigate to `$key`, `false` if not
     */
    public function to($key)
    {
        $getter = 'get'.ucfirst($key);
        $hasser = 'has'.ucfirst($key);
        $isser  = 'is'.ucfirst($key);

        if (is_array($this->current) && array_key_exists($key, $this->current)) {
            $this->current = &$this->current[$key];

            return true;
        } else if ($this->isObjectWithMethod($this->current, $key)) {
            $this->current = $this->current->$key();

            return true;
        } else if ($this->isObjectWithMethod($this->current, $getter)) {
            $this->current = $this->current->$getter();

            return true;
        } else if ($this->isObjectWithMethod($this->current, $hasser)) {
            $this->current = $this->current->$hasser();

            return true;
        } else if ($this->isObjectWithMethod($this->current, $isser)) {
            $this->current = $this->current->$isser();

            return true;
        } else if (is_object($this->current) && isset($this->current->$key)) {
            $this->current = $this->current->$key;

            return true;
        }

        return false;
    }

    /**
     * @param string|int $key
     * @param mixed      $value
     *
     * @return bool
     */
    public function set($key, $value)
    {
        $setter = 'set'.ucfirst($key);

        if (is_array($this->current)) {
            $this->current[$key] = $value;

            return true;
        } else if ($this->isObjectWithMethod($this->current, $key)) {
            $this->current->$key($value);

            return true;
        } else if ($this->isObjectWithMethod($this->current, $setter)) {
            $this->current->$setter($value);

            return true;
        } else if (is_object($this->current)) {
            $this->current->$key = $value;

            return true;
        }

        return false;
    }

    /**
     * @param string|int $key
     *
     * @return bool
     */
    public function has($key)
    {
        $setter = 'set'.ucfirst($key);
        $getter = 'get'.ucfirst($key);
        $hasser = 'has'.ucfirst($key);
        $isser  = 'is'.ucfirst($key);

        return (is_array($this->current) && array_key_exists($key, $this->current))
            || is_object($this->current) && isset($this->current->$key)
            || $this->isObjectWithMethod($this->current, $key)
            || $this->isObjectWithMethod($this->current, $setter)
            || $this->isObjectWithMethod($this->current, $getter)
            || $this->isObjectWithMethod($this->current, $hasser)
            || $this->isObjectWithMethod($this->current, $isser);
    }

    /**
     * @param string|int $key
     *
     * @return bool
     */
    public function remove($key)
    {
        $unsetter = 'unset'.ucfirst($key);
        $remover  = 'remove'.ucfirst($key);

        if (is_array($this->current) && array_key_exists($key, $this->current)) {
            unset($this->current[$key]);

            return true;
        } else if (is_object($this->current) && isset($this->current->$key)) {
            unset($this->current->$key);

            return true;
        } else if ($this->isObjectWithMethod($this->current, $unsetter)) {
            $this->current->$unsetter();

            return true;
        } else if ($this->isObjectWithMethod($this->current, $remover)) {
            $this->current->$remover();

            return true;
        }

        return false;
    }

    /**
     * @param mixed      $data
     * @param string|int $key
     *<commit_msg>Improve handling of return values in Accessor<commit_after><?php

namespace Cocur\Vale;

/**
 * Accessor
 *
 * @package   Cocur\Vale
 * @author    <NAME> <<EMAIL>>
 * @copyright 2015 <NAME>
 */
class Accessor
{
    /**
     * @var mixed
     */
    protected $data;

    /**
     * @var mixed
     */
    protected $current;

    /**
     * @param mixed $data
     */
    public function __construct($data)
    {
        if (is_array($data)) {
            $this->data    = &$data;
            $this->current = &$data;
        } else {
            $this->data    = $data;
            $this->current = $data;
        }
    }

    /**
     * @return mixed
     */
    public function getData()
    {
        return $this->data;
    }

    /**
     * @return mixed
     */
    public function getCurrent()
    {
        return $this->current;
    }

    /**
     * Navigates to `$key`.
     *
     * @param string|int $key
     *
     * @return bool `true` if it is possible to navigate to `$key`, `false` if not
     */
    public function to($key)
    {
        $getter = 'get'.ucfirst($key);
        $hasser = 'has'.ucfirst($key);
        $isser  = 'is'.ucfirst($key);

        if (is_array($this->current) && array_key_exists($key, $this->current)) {
            $this->current = &$this->current[$key];
        } else if ($this->isObjectWithMethod($this->current, $key)) {
            $this->current = $this->current->$key();
        } else if ($this->isObjectWithMethod($this->current, $getter)) {
            $this->current = $this->current->$getter();
        } else if ($this->isObjectWithMethod($this->current, $hasser)) {
            $this->current = $this->current->$hasser();
        } else if ($this->isObjectWithMethod($this->current, $isser)) {
            $this->current = $this->current->$isser();
        } else if (is_object($this->current) && isset($this->current->$key)) {
            $this->current = $this->current->$key;
        } else {
            return false;
        }

        return true;
    }

    /**
     * @param string|int $key
     * @param mixed      $value
     *
     * @return bool
     */
    public function set($key, $value)
    {
        $setter = 'set'.ucfirst($key);

        if (is_array($this->current)) {
            $this->current[$key] = $value;
        } else if ($this->isObjectWithMethod($this->current, $key)) {
            $this->current->$key($value);
        } else if ($this->isObjectWithMethod($this->current, $setter)) {
            $this->current->$setter($value);
        } else if (is_object($this->current)) {
            $this->current->$key = $value;
        } else {
            return false;
        }

        return true;
    }

    /**
     * @param string|int $key
     *
     * @return bool
     */
    public function has($key)
    {
        $setter = 'set'.ucfirst($key);
        $getter = 'get'.ucfirst($key);
        $hasser = 'has'.ucfirst($key);
        $isser  = 'is'.ucfirst($key);

        return (is_array($this->current) && array_key_exists($key, $this->current))
            || is_object($this->current) && isset($this->current->$key)
            || $this->isObjectWithMethod($this->current, $key)
            || $this->isObjectWithMethod($this->current, $setter)
            || $this->isObjectWithMethod($this->current, $getter)
            || $this->isObjectWithMethod($this->current, $hasser)
            || $this->isObjectWithMethod($this->current, $isser);
    }

    /**
     * @param string|int $key
     *
     * @return bool
     */
    public function remove($key)
    {
        $unsetter = 'unset'.ucfirst($key);
        $remover  = 'remove'.ucfirst($key);

        if (is_array($this->current) && array_key_exists($key, $this->current)) {
            unset($this->current[$key]);
        } else if (is_object($this->current) && isset($this->current->$key)) {
            unset($this->current->$key);
        } else if ($this->isObjectWithMethod($this->current, $unsetter)) {
            $this->current->$unsetter();
        } else if ($this->isObjectWithMethod($this->current, $remover)) {
            $this->current->$remover();
        } else {
            return false;
        }

        return true;
    }

    /**
     * @param mixed      $data
     * @param string|int $key
     *
{'fraction_non_alphanumeric': 0.176812585499316, 'fraction_numerical': 0.0009119927040583675, 'mean_word_length': 1.8632506527415145, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 171, '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': '5279028', 'n_tokens_mistral': 2744, 'n_tokens_neox': 2684, 'n_words': 497}