<commit_before><?php

namespace SimpleORM;

use SimpleORM\Exceptions\InvalidORMArgument;
use SimpleORM\Exceptions\NoCursorInitializedORMException;
use SimpleORM\Interfaces\ResultSetInterface;

require 'Interfaces/ResultSet.php';

class ResultSet implements ResultSetInterface
{
    private $resultSet;
    private $firstCall;

    public function __construct(\mysqli_result $queryResult)
    {
        while ($row = $queryResult->fetch_assoc()) {
            $this->resultSet[] = $row;
        }

        $this->firstCall = true;
    }

    public function count()
    {
        if($this->resultSet == null)
            return false;

        return count($this->resultSet);
    }

    public function fieldExists($field)
    {
        for ($i = 0; $i < count($this->resultSet); $i++) {
            if (array_key_exists($field, $this->resultSet[$i]))
                return true;
        }

        return false;
    }

    public function find($field, $value)
    {
        if (!array_key_exists($field, $this->resultSet[0]))
            return false;

        for ($i = 0; $i < count($this->resultSet); $i++) {
            if ($this->resultSet[$i][$field] == $value)
                return $this->resultSet[$i];
        }

        return false;
    }
    
    public function findValue($value)
    {
        if ($this->count()) {
            for ($i = 0; $i < count($this->resultSet); $i++) {
                if (array_search($value, $this->resultSet[$i]))
                    return $this->resultSet[$i];
            }
        }

        return false;
    }

    public function first()
    {
        if($this->firstCall)
            $this->firstCall = false;

        reset($this->resultSet);

        return $this;
    }

    public function get($field)
    {
        if($this->firstCall)
            throw new NoCursorInitializedORMException('You must call first(), last() or next() method before getting some info');

        if(!array_key_exists($field, $this->resultSet[0]))
            throw new InvalidORMArgument('Field ' . $field . ' does not exist in result');

        return $this->resultSet[key($this->resultSet)][$field];
    }

    public function getAll()
    {
        return current($this->resultSet);
    }

    /*public function getFields(...$fieldName)
    {
        $colRegisters = array();

        foreach ($fieldName as $col) {
            if (!array_key_exists($col, $this->resultSet[0]))
                throw new \OutOfRangeException('The column ' . $col . ' does not exists');
        }

        if (count($fieldName) > 1) {
            for ($i = 0; $i < count($fieldName); $i++) {
                for ($j = 0; $j < count($this->resultSet); $j++) {
                    $colRegisters[$fieldName[$i]][] = $this->resultSet[$j][$fieldName[$i]];
                }
            }
        } else {
            for ($i = 0; $i < count($this->resultSet); $i++) {
                $colRegisters[] = $this->resultSet[$i][$fieldName[0]];
            }
        }

        return $colRegisters;
    }*/

    public function goToRegister($register)
    {
        if ($register < 0 || $register >= count($this->resultSet))
            throw new \OutOfRangeException('Index does not exists in the result');

        reset($this->resultSet);

        while (key($this->resultSet) != $register)
            next($this->resultSet);

        return $this;
    }

    public function isFirst()
    {
        if($this->firstCall)
            throw new NoCursorInitializedORMException('You must call first(), last() or next() method before');

        if (!prev($this->resultSet))
            return true;

        next($this->resultSet);

        return false;
    }

    public function isLast()
    {
        if($this->firstCall)
            throw new NoCursorInitializedORMException('You must call first(), last() or next() method before');

        if (!next($this->resultSet))
            return true;

        prev($this->resultSet);

        return false;
    }

    public function last()
    {
        if($this->firstCall)
            $this->firstCall = false;

        end($this->resultSet);

        return $this;
    }

    public function next()
    {
        if($this->firstCall) {
            $this->firstCall = false;
            return $this;
        }

        if (!next($this->resultSet))
            return false;

        return $this;
    }

    public function prev()
    {
        if($this->firstCall)
            throw new NoCursorInitializedORMException('You must call first(), last() or next() method before');

        if (!prev($this->resultSet))
            return false;

        return $this;
    }

    public function valueExists($value)
    {
        for ($i = 0; $i < count($this->resultSet); $i++) {
            if (array_search($value, $this->resultSet[$i]))
                return true;
        }

        return false;
    }
}<commit_msg>Setted strict mode for "valueExists" method.<commit_after><?php

namespace SimpleORM;

use SimpleORM\Exceptions\InvalidORMArgument;
use SimpleORM\Exceptions\NoCursorInitializedORMException;
use SimpleORM\Interfaces\ResultSetInterface;

require 'Interfaces/ResultSet.php';

class ResultSet implements ResultSetInterface
{
    private $resultSet;
    private $firstCall;

    public function __construct(\mysqli_result $queryResult)
    {
        while ($row = $queryResult->fetch_assoc()) {
            $this->resultSet[] = $row;
        }

        $this->firstCall = true;
    }

    public function count()
    {
        if($this->resultSet == null)
            return false;

        return count($this->resultSet);
    }

    public function fieldExists($field)
    {
        for ($i = 0; $i < count($this->resultSet); $i++) {
            if (array_key_exists($field, $this->resultSet[$i]))
                return true;
        }

        return false;
    }

    public function find($field, $value)
    {
        if (!array_key_exists($field, $this->resultSet[0]))
            return false;

        for ($i = 0; $i < count($this->resultSet); $i++) {
            if ($this->resultSet[$i][$field] == $value)
                return $this->resultSet[$i];
        }

        return false;
    }
    
    public function findValue($value)
    {
        if ($this->count()) {
            for ($i = 0; $i < count($this->resultSet); $i++) {
                if (array_search($value, $this->resultSet[$i]))
                    return $this->resultSet[$i];
            }
        }

        return false;
    }

    public function first()
    {
        if($this->firstCall)
            $this->firstCall = false;

        reset($this->resultSet);

        return $this;
    }

    public function get($field)
    {
        if($this->firstCall)
            throw new NoCursorInitializedORMException('You must call first(), last() or next() method before getting some info');

        if(!array_key_exists($field, $this->resultSet[0]))
            throw new InvalidORMArgument('Field ' . $field . ' does not exist in result');

        return $this->resultSet[key($this->resultSet)][$field];
    }

    public function getAll()
    {
        return current($this->resultSet);
    }

    /*public function getFields(...$fieldName)
    {
        $colRegisters = array();

        foreach ($fieldName as $col) {
            if (!array_key_exists($col, $this->resultSet[0]))
                throw new \OutOfRangeException('The column ' . $col . ' does not exists');
        }

        if (count($fieldName) > 1) {
            for ($i = 0; $i < count($fieldName); $i++) {
                for ($j = 0; $j < count($this->resultSet); $j++) {
                    $colRegisters[$fieldName[$i]][] = $this->resultSet[$j][$fieldName[$i]];
                }
            }
        } else {
            for ($i = 0; $i < count($this->resultSet); $i++) {
                $colRegisters[] = $this->resultSet[$i][$fieldName[0]];
            }
        }

        return $colRegisters;
    }*/

    public function goToRegister($register)
    {
        if ($register < 0 || $register >= count($this->resultSet))
            throw new \OutOfRangeException('Index does not exists in the result');

        reset($this->resultSet);

        while (key($this->resultSet) != $register)
            next($this->resultSet);

        return $this;
    }

    public function isFirst()
    {
        if($this->firstCall)
            throw new NoCursorInitializedORMException('You must call first(), last() or next() method before');

        if (!prev($this->resultSet))
            return true;

        next($this->resultSet);

        return false;
    }

    public function isLast()
    {
        if($this->firstCall)
            throw new NoCursorInitializedORMException('You must call first(), last() or next() method before');

        if (!next($this->resultSet))
            return true;

        prev($this->resultSet);

        return false;
    }

    public function last()
    {
        if($this->firstCall)
            $this->firstCall = false;

        end($this->resultSet);

        return $this;
    }

    public function next()
    {
        if($this->firstCall) {
            $this->firstCall = false;
            return $this;
        }

        if (!next($this->resultSet))
            return false;

        return $this;
    }

    public function prev()
    {
        if($this->firstCall)
            throw new NoCursorInitializedORMException('You must call first(), last() or next() method before');

        if (!prev($this->resultSet))
            return false;

        return $this;
    }

    public function valueExists($value)
    {
        for ($i = 0; $i < count($this->resultSet); $i++) {
            if (array_search($value, $this->resultSet[$i], true))
                return true;
        }

        return false;
    }
}
{'fraction_non_alphanumeric': 0.14415332857579774, 'fraction_numerical': 0.0026506269752268326, 'mean_word_length': 1.9301075268817205, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 103, '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': '3072086', 'n_tokens_mistral': 2848, 'n_tokens_neox': 2728, 'n_words': 638}