<commit_before><?php

namespace Del\Collection;

use ArrayIterator;
use Del\Entity\Person as PersonEntity;
use LogicException;

class Person extends ArrayIterator
{
    /**
     * @return PersonEntity
     */
    public function getFirstItem()
    {
        if ($this->count() === 0) {
            throw new LogicException('No people in the collection');
        }
        $this->rewind();
        return $this->current();
    }

    /**
     * @return PersonEntity
     */
    public function getLastItem()
    {
        if ($this->count() === 0) {
            throw new LogicException('No people in the collection');
        }
        $count = $this->count() - 1;
        return $this->offsetGet($count);
    }


    /**
     * @param PersonEntity $person
     * @return $this
     */
    public function update(PersonEntity $person)
    {
        $key = $this->findKey($person);
        if($key) {

            $this->offsetSet($key,$person);
            return $this;

        }
        throw new LogicException('Person was not in the collection.');
    }

    /**
     * @param PersonEntity $person
     */
    public function append(PersonEntity $person)
    {
        parent::append($person);
    }

    /**
     * @return PersonEntity|null
     */
    public function current()
    {
        return parent::current();
    }

    /**
     * @param PersonEntity $person
     * @return bool|int
     */
    public function findKey(PersonEntity $person)
    {
        $this->rewind();
        while($this->valid()) {
            if($this->current()->getId() == $person->getId()) {
                return $this->key();
            }
            $this->next();
        }
        return false;
    }

    /**
     * @return PersonEntity|null
     */
    public function prev()
    {
        if ($this->key() == 0) {
            return null;
        }
        $this->seek($this->key() - 1);
        return $this->current();
    }

}<commit_msg>find by id in collection<commit_after><?php

namespace Del\Collection;

use ArrayIterator;
use Del\Entity\Person as PersonEntity;
use LogicException;

class Person extends ArrayIterator
{
    /**
     * @return PersonEntity
     */
    public function getFirstItem()
    {
        if ($this->count() === 0) {
            throw new LogicException('No people in the collection');
        }
        $this->rewind();
        return $this->current();
    }

    /**
     * @return PersonEntity
     */
    public function getLastItem()
    {
        if ($this->count() === 0) {
            throw new LogicException('No people in the collection');
        }
        $count = $this->count() - 1;
        return $this->offsetGet($count);
    }


    /**
     * @param PersonEntity $person
     * @return $this
     */
    public function update(PersonEntity $person)
    {
        $key = $this->findKey($person);
        if($key) {

            $this->offsetSet($key,$person);
            return $this;

        }
        throw new LogicException('Person was not in the collection.');
    }

    /**
     * @param PersonEntity $person
     */
    public function append(PersonEntity $person)
    {
        parent::append($person);
    }

    /**
     * @return PersonEntity|null
     */
    public function current()
    {
        return parent::current();
    }

    /**
     * @param PersonEntity $person
     * @return bool|int
     */
    public function findKey(PersonEntity $person)
    {
        $this->rewind();
        while($this->valid()) {
            if($this->current()->getId() == $person->getId()) {
                return $this->key();
            }
            $this->next();
        }
        return false;
    }

    /**
     * @return PersonEntity|null
     */
    public function prev()
    {
        if ($this->key() == 0) {
            return null;
        }
        $this->seek($this->key() - 1);
        return $this->current();
    }

    public function findById($id)
    {
        $this->rewind();
        
        while ($this->valid()) {
            if($this->current()->getId() == $id) {
                return $this->current();
            }
            $this->next();
        }

        return false;
    }

}
{'fraction_non_alphanumeric': 0.1490787269681742, 'fraction_numerical': 0.0023929169657812875, 'mean_word_length': 1.6726342710997442, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '3796721', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1163, 'n_words': 263}