<commit_before><?php
namespace App\Database;

use PDO;
use PDOStatement;
use RecursiveArrayIterator;
use RecursiveIteratorIterator;
use App\Database;

/**
 * @inheritDoc
 */
abstract class Base extends PDO implements Database
{
    /**
     * @inheritDoc
     */
    final public function execute(string $statement, array $parameters): PDOStatement
    {
        $placeholders = [];

        /*
        Generate the right amount of placeholders
        for a multidimensional array of paramaters.
        */
        foreach ($parameters as $index => $parameter) {
            if (!is_array($parameter)) {
                $placeholders[] = '?';
                continue;
            }
            $placeholders[] = implode(',', array_fill(0, count($parameter), '?'));
        }

        // Flatten parameters.
        $parameters = iterator_to_array(
            new RecursiveIteratorIterator(
                new RecursiveArrayIterator($parameters)
            ),
            false
        );

        // Prepare and execute statement.
        $statement = $this->prepare(
            // Insert placeholders.
            vsprintf($statement, $placeholders)
        );
        $statement->execute($parameters);

        return $statement;
    }
}<commit_msg>Refactored database component<commit_after><?php
namespace App\Database;

use App\Database;
use PDO;
use PDOStatement;
use RecursiveArrayIterator;
use RecursiveIteratorIterator;

/**
 * @inheritDoc
 */
final class Base implements Database
{
    /**
     * @var PDO
     */
    private $pdo;

    /**
     * Constructor.
     *
     * @param PDO $pdo
     */
    public function __construct(PDO $pdo)
    {
        $this->pdo = $pdo;
    }

    /**
     * @inheritDoc
     */
    public function execute(string $statement, array $parameters): PDOStatement
    {
        $placeholders = [];
        /*
        Generate the right amount of placeholders
        for a multidimensional array of paramaters.
        */
        foreach ($parameters as $index => $parameter) {
            if (!is_array($parameter)) {
                $placeholders[] = '?';
                continue;
            }
            $placeholders[] = implode(',', array_fill(0, count($parameter), '?'));
        }
        /*
        Flatten parameters.
        */
        $parameters = iterator_to_array(
            new RecursiveIteratorIterator(
                new RecursiveArrayIterator($parameters)
            ),
            false
        );
        /*
        Prepare and execute statement.
        */
        $statement = $this->pdo->prepare(
            /*
            Insert placeholders.
            */
            vsprintf($statement, $placeholders)
        );
        $statement->execute($parameters);

        return $statement;
    }
}
{'fraction_non_alphanumeric': 0.11207207207207207, 'fraction_numerical': 0.0007207207207207207, 'mean_word_length': 1.7649402390438247, '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': '1423770', 'n_tokens_mistral': 736, 'n_tokens_neox': 721, 'n_words': 169}