<commit_before><?php
/**
 * This file is part of library-template
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author <NAME> <<EMAIL>>
 */

namespace StringTemplate;


use Traversable;

class NestedKeyArray implements \ArrayAccess, \IteratorAggregate
{
    private $array;
    private $keySeparator;

    /**
     * @param array $array
     * @param string $keySeparator
     */
    public function __construct(array &$array, $keySeparator = '.')
    {
        $this->array = $array;
        $this->keySeparator = '.';
    }

    /**
     * {@inheritdoc}
     */
    public function getIterator()
    {
        return new NestedKeyIterator(new RecursiveArrayOnlyIterator($this->array));
    }

    /**
     * {@inheritdoc}
     */
    public function offsetExists($offset)
    {
        $keys = explode($this->keySeparator, $offset);
        $ary = &$this->array;

        foreach ($keys as $key) {
            if (!isset($ary[$key]))
                return false;
            $ary = &$ary[$key];
        }

        return true;
    }

    /**
     * {@inheritdoc}
     */
    public function offsetGet($offset)
    {
        $keys = explode($this->keySeparator, $offset);
        $result = &$this->array;

        foreach ($keys as $key) {
            $result = &$result[$key];
        }

        return $result;
    }

    /**
     * {@inheritdoc}
     */
    public function offsetSet($offset, $value)
    {
        $this->setNestedOffset($this->array, explode($this->keySeparator, $offset), $value);
    }

    /**
     * {@inheritdoc}
     */
    public function offsetUnset($offset)
    {
        $this->unsetNestedOffset($this->array, explode($this->keySeparator, $offset));
    }


    /**
     * @return array
     */
    public function toArray()
    {
        return $this->array;
    }

    /**
     * @param array $target
     * @param array $offsets
     * @param $value
     * @return $this
     */
    private function setNestedOffset(array &$target, array $offsets, $value)
    {
        $currKey = array_shift($offsets);

        if (!$offsets) {
            $target[$currKey] = $value;
        }  else {
            if (!isset($target[$currKey]))
                $target[$currKey] = array();
            $this->setNestedOffset($target[$currKey], $offsets, $value);
        }

        return $this;
    }

    /**
     * @param array $target
     * @param array $offsets
     * @return $this
     */
    private function unsetNestedOffset(array &$target, array $offsets)
    {
        $currKey = array_shift($offsets);

        if (!$offsets) {
            unset($target[$currKey]);
        }  elseif (isset($target[$currKey])) {
            $this->unsetNestedOffset($target[$currKey], $offsets);
        }

        return $this;
    }
} <commit_msg>At NestedKeyArray fix code that is not using the keySeparator<commit_after><?php
/**
 * This file is part of library-template
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author <NAME> <<EMAIL>>
 */

namespace StringTemplate;

class NestedKeyArray implements \ArrayAccess, \IteratorAggregate
{
    private $array;
    private $keySeparator;

    /**
     * @param array $array
     * @param string $keySeparator
     */
    public function __construct(array &$array, $keySeparator = '.')
    {
        $this->array = $array;
        $this->keySeparator = $keySeparator;
    }

    /**
     * {@inheritdoc}
     */
    public function getIterator()
    {
        return new NestedKeyIterator(new RecursiveArrayOnlyIterator($this->array));
    }

    /**
     * {@inheritdoc}
     */
    public function offsetExists($offset)
    {
        $keys = explode($this->keySeparator, $offset);
        $ary = &$this->array;

        foreach ($keys as $key) {
            if (!isset($ary[$key]))
                return false;
            $ary = &$ary[$key];
        }

        return true;
    }

    /**
     * {@inheritdoc}
     */
    public function offsetGet($offset)
    {
        $keys = explode($this->keySeparator, $offset);
        $result = &$this->array;

        foreach ($keys as $key) {
            $result = &$result[$key];
        }

        return $result;
    }

    /**
     * {@inheritdoc}
     */
    public function offsetSet($offset, $value)
    {
        $this->setNestedOffset($this->array, explode($this->keySeparator, $offset), $value);
    }

    /**
     * {@inheritdoc}
     */
    public function offsetUnset($offset)
    {
        $this->unsetNestedOffset($this->array, explode($this->keySeparator, $offset));
    }


    /**
     * @return array
     */
    public function toArray()
    {
        return $this->array;
    }

    /**
     * @param array $target
     * @param array $offsets
     * @param $value
     * @return $this
     */
    private function setNestedOffset(array &$target, array $offsets, $value)
    {
        $currKey = array_shift($offsets);

        if (!$offsets) {
            $target[$currKey] = $value;
        }  else {
            if (!isset($target[$currKey]))
                $target[$currKey] = array();
            $this->setNestedOffset($target[$currKey], $offsets, $value);
        }

        return $this;
    }

    /**
     * @param array $target
     * @param array $offsets
     * @return $this
     */
    private function unsetNestedOffset(array &$target, array $offsets)
    {
        $currKey = array_shift($offsets);

        if (!$offsets) {
            unset($target[$currKey]);
        } elseif (isset($target[$currKey])) {
            $this->unsetNestedOffset($target[$currKey], $offsets);
        }

        return $this;
    }
}
{'fraction_non_alphanumeric': 0.14712523883967343, 'fraction_numerical': 0.0, 'mean_word_length': 2.0194022024121656, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, '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': '655956', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1698, 'n_words': 374}