<commit_before><?php

namespace Stratedge\Wye;

use Stratedge\Wye\PDO\PDO;
use Stratedge\Wye\PDO\PDOStatement;
use Stratedge\Wye\Result;
use Stratedge\Wye\Row;

class Wye
{
    /**
     * @var boolean
     */
    protected static $booted = false;

    /**
     * @var array
     */
    protected static $statements = [];

    /**
     * @var array
     */
    protected static $results = [];

    /**
     * @var int
     */
    protected static $num_queries = 0;


    public function __construct()
    {
        if ($this->isBooted()) {
            $this->boot();
        }
    }


    public static function boot()
    {
        static::reset();
    }


    public static function reset()
    {
        static::resetStatements();
        static::resetResults();
        static::resetNumQueries();
    }


    public static function makeStatement($statement, $options)
    {
        $statement = new PDOStatement(new static, $statement, $options);
        return $statement;
    }


    public static function makePDO()
    {
        $pdo = new PDO(new static);
        return $pdo;
    }


    public static function makeResult()
    {
        $result = new Result(new static);
        return $result;
    }


    public static function makeRow($data)
    {
        $row = new Row(new static, $data);
        return $row;
    }


    public static function executeStatement(
        PDOStatement $statement,
        array $params = []
    ) {
        //Add the statement to the list of those run
        static::addStatement($statement);

        //Add params to the statement
        $statement->params($params);

        $result = static::getResultAt(static::numQueries());

        //Add the result to the statement
        $statement->result($result);

        //Increment number of queries run
        static::incrementNumQueries();
    }



    //**************************************************************************
    // BOOTED
    //**************************************************************************

    public static function booted($booted = null)
    {
        if (is_null($is_booted)) {
            return static::getBooted();
        } else {
            return static::setBooted($booted);
        }
    }

    public static function getBooted()
    {
        return static::$booted;
    }

    public static function setBooted($booted)
    {
        static::$booted = (bool) $booted;
    }

    public static function isBooted()
    {
        return static::getBooted() === true;
    }



    //**************************************************************************
    // STATEMENTS
    //**************************************************************************

    public static function statements($statements = null)
    {
        if (is_null($statements)) {
            return static::getStatements();
        } else {
            return static::setStatements($statements);
        }
    }

    public static function getStatements()
    {
        return static::$statements;
    }

    public static function setStatements($statements)
    {
        static::$statements = $statements;
    }

    public static function resetStatements()
    {
        static::setStatements([]);
    }


    public static function addStatement(PDOStatement $statement)
    {
        //Add statement
        $statements = static::statements();
        $statements[] = $statement;

        //Store statements
        static::statements($statements);
    }



    //**************************************************************************
    // RESULTS
    //**************************************************************************

    public static function results($results = null)
    {
        if (is_null($results)) {
            return static::getResults();
        } else {
            return static::setResults($results);
        }
    }

    public static function getResults()
    {
        return static::$results;
    }

    public static function getResultAt($index = 0)
    {
        $results = static::results();

        return !empty($results[$index]) ? $results[$index] : null;
    }

    public static function setResults($results)<commit_msg>Add getStatementAtIndex method to Wye<commit_after><?php

namespace Stratedge\Wye;

use Stratedge\Wye\PDO\PDO;
use Stratedge\Wye\PDO\PDOStatement;
use Stratedge\Wye\Result;
use Stratedge\Wye\Row;

class Wye
{
    /**
     * @var boolean
     */
    protected static $booted = false;

    /**
     * @var array
     */
    protected static $statements = [];

    /**
     * @var array
     */
    protected static $results = [];

    /**
     * @var int
     */
    protected static $num_queries = 0;


    public function __construct()
    {
        if ($this->isBooted()) {
            $this->boot();
        }
    }


    public static function boot()
    {
        static::reset();
    }


    public static function reset()
    {
        static::resetStatements();
        static::resetResults();
        static::resetNumQueries();
    }


    public static function makeStatement($statement, $options)
    {
        $statement = new PDOStatement(new static, $statement, $options);
        return $statement;
    }


    public static function makePDO()
    {
        $pdo = new PDO(new static);
        return $pdo;
    }


    public static function makeResult()
    {
        $result = new Result(new static);
        return $result;
    }


    public static function makeRow($data)
    {
        $row = new Row(new static, $data);
        return $row;
    }


    public static function executeStatement(
        PDOStatement $statement,
        array $params = []
    ) {
        //Add the statement to the list of those run
        static::addStatement($statement);

        //Add params to the statement
        $statement->params($params);

        $result = static::getResultAt(static::numQueries());

        //Add the result to the statement
        $statement->result($result);

        //Increment number of queries run
        static::incrementNumQueries();
    }



    //**************************************************************************
    // BOOTED
    //**************************************************************************

    public static function booted($booted = null)
    {
        if (is_null($is_booted)) {
            return static::getBooted();
        } else {
            return static::setBooted($booted);
        }
    }

    public static function getBooted()
    {
        return static::$booted;
    }

    public static function setBooted($booted)
    {
        static::$booted = (bool) $booted;
    }

    public static function isBooted()
    {
        return static::getBooted() === true;
    }



    //**************************************************************************
    // STATEMENTS
    //**************************************************************************

    public static function statements($statements = null)
    {
        if (is_null($statements)) {
            return static::getStatements();
        } else {
            return static::setStatements($statements);
        }
    }

    public static function getStatements()
    {
        return static::$statements;
    }

    public static function setStatements($statements)
    {
        static::$statements = $statements;
    }

    public static function resetStatements()
    {
        static::setStatements([]);
    }

    public static function addStatement(PDOStatement $statement)
    {
        //Add statement
        $statements = static::statements();
        $statements[] = $statement;

        //Store statements
        static::statements($statements);
    }

    public static function getStatementAtIndex($index = 0)
    {
        $statements = static::statements();

        return isset($statements[$index]) ? $statements[$index] : null;
    }



    //**************************************************************************
    // RESULTS
    //**************************************************************************

    public static function results($results = null)
    {
        if (is_null($results)) {
            return static::getResults();
        } else {
            return static::setResults($results);
        }
    }

    public static function getResults()
    {
        return static::$results;
    }

    public static function getResultAt($index = 0)
    {
        $results = static::results();

        return !empty($results[$index]) ? $results[$index] : null;
    }

    public static function setResults($results)
{'fraction_non_alphanumeric': 0.21004884856943476, 'fraction_numerical': 0.0005815305885089556, 'mean_word_length': 2.313680154142582, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '593606', 'n_tokens_mistral': 2302, 'n_tokens_neox': 2127, 'n_words': 508}