<commit_before><?php

namespace Monki\Endpoint\Item;

use PDO;
use PDOException;
use Dabble\Query\Where;

class Controller
{
    protected $adapter;
    protected $table;
    protected $item;

    public function __construct(PDO $adapter, $table, $item = null)
    {
        $this->adapter = $adapter;
        $this->table = $table;
        $this->item = $item;
    }

    private function normalize($value)
    {
        if (is_array($value)) {
            return array_map([$this, 'normalize'], $value);
        }
        if (!is_scalar($value)) {
            return $value;
        }
        if (is_numeric($value)) {
            return $value;
        }
        if (false !== ($time = strtotime($value))) {
            return date('Y-m-d H:i:s', $time);
        }
        return $value;
    }

    public function create(array $data)
    {
        $data = array_map([$this, 'normalize'], $data);
        unset($data['id']); // never when creating...
        foreach ($data as $key => &$item) {
            if (is_array($item)) {
                if (isset($item['id'])) {
                    $item = $item['id'];
                } else {
                    unset($data[$key]);
                }
            }
        }
        try {
            $stmt = $this->adapter->prepare(sprintf(<commit_msg>null is of course null<commit_after><?php

namespace Monki\Endpoint\Item;

use PDO;
use PDOException;
use Dabble\Query\Where;

class Controller
{
    protected $adapter;
    protected $table;
    protected $item;

    public function __construct(PDO $adapter, $table, $item = null)
    {
        $this->adapter = $adapter;
        $this->table = $table;
        $this->item = $item;
    }

    private function normalize($value)
    {
        if (is_array($value)) {
            return array_map([$this, 'normalize'], $value);
        }
        if (!is_scalar($value)) {
            return $value;
        }
        if (is_numeric($value)) {
            return $value;
        }
        if (is_null($value) || !strlen($value)) {
            return null;
        }
        if (false !== ($time = strtotime($value))) {
            return date('Y-m-d H:i:s', $time);
        }
        return $value;
    }

    public function create(array $data)
    {
        $data = array_map([$this, 'normalize'], $data);
        unset($data['id']); // never when creating...
        foreach ($data as $key => &$item) {
            if (is_array($item)) {
                if (isset($item['id'])) {
                    $item = $item['id'];
                } else {
                    unset($data[$key]);
                }
            }
        }
        try {
            $stmt = $this->adapter->prepare(sprintf(
{'fraction_non_alphanumeric': 0.15504451038575667, 'fraction_numerical': 0.0, 'mean_word_length': 1.6312195121951218, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '3846167', 'n_tokens_mistral': 810, 'n_tokens_neox': 797, 'n_words': 178}