<commit_before><?php

namespace Repository;

use Doctrine\DBAL\Connection;
use Entity\AbstractEntity;

/**
 * Provides basic CRUD functionality.
 */
abstract class AbstractRepository
{

    /**
     * @var Connection
     */
    protected $dbConnection;

    /**
     * @var string
     */
    protected $tableName;

    /**
     * The constructor.
     *
     * @param Connection $dbConnection PDO wrapper with extra functions
     * @param string $tableName The table to query
     */
    public function __construct(Connection $dbConnection, $tableName)
    {
        $this->dbConnection = $dbConnection;
        $this->tableName = $tableName;
    }

    /**
     * Stores entity data in the database.
     *
     * @param AbstractEntity $entity The entity
     * @return int Number of affected rows
     */
    public function save(AbstractEntity $entity)
    {
        // ! concrete repos should decide when/if not to allow updates/inserts. by default, if it has an id, we update, otherwise insert.
        if (!is_null($entity->getId())) {
            return $this->update($entity);
        }      

        return $this->insert($entity);
    }

    /**
     * Inserts an entity's data in the database.
     *
     * @param AbstractEntity $entity The entity
     * @return int Number of affected rows
     */
    protected function insert(AbstractEntity $entity)
    {
        $entityAsArray = $this->loadArrayFromEntity($entity);
        // temp fix: check DateTime format
        foreach($entityAsArray as $field => $value) {
            if ($field === 'date' && is_object($value)) {
               $entityAsArray[$field] = $value->format('Y-m-d');                
            }
        }
        return $this->dbConnection->insert($this->tableName, $entityAsArray);
    }

    /**
     * Updates an entity's data in the database.
     *
     * @param AbstractEntity $entity The entity
     * @return int Number of affected rows
     */
    protected function update(AbstractEntity $entity)
    {
        $id = $entity->getId();
        $entityAsArray = $this->loadArrayFromEntity($entity);
        return $this->dbConnection->update($this->tableName, $entityAsArray, array('id' => $id));<commit_msg>[develop] temporary fix for time format when adding to db<commit_after><?php

namespace Repository;

use Doctrine\DBAL\Connection;
use Entity\AbstractEntity;

/**
 * Provides basic CRUD functionality.
 */
abstract class AbstractRepository
{

    /**
     * @var Connection
     */
    protected $dbConnection;

    /**
     * @var string
     */
    protected $tableName;

    /**
     * The constructor.
     *
     * @param Connection $dbConnection PDO wrapper with extra functions
     * @param string $tableName The table to query
     */
    public function __construct(Connection $dbConnection, $tableName)
    {
        $this->dbConnection = $dbConnection;
        $this->tableName = $tableName;
    }

    /**
     * Stores entity data in the database.
     *
     * @param AbstractEntity $entity The entity
     * @return int Number of affected rows
     */
    public function save(AbstractEntity $entity)
    {
        // ! concrete repos should decide when/if not to allow updates/inserts. by default, if it has an id, we update, otherwise insert.
        if (!is_null($entity->getId())) {
            return $this->update($entity);
        }      

        return $this->insert($entity);
    }

    /**
     * Inserts an entity's data in the database.
     *
     * @param AbstractEntity $entity The entity
     * @return int Number of affected rows
     */
    protected function insert(AbstractEntity $entity)
    {
        $entityAsArray = $this->loadArrayFromEntity($entity);
        // temp fix: check DateTime format
        foreach($entityAsArray as $field => $value) {
            if ($field === 'date' && is_object($value)) {
               $entityAsArray[$field] = $value->format('Y-m-d');                
            }
            if ($field === 'time' && !empty($value)) {
                $value .= ':00:00';
               $entityAsArray[$field] = $value;                
            }
        }
        return $this->dbConnection->insert($this->tableName, $entityAsArray);
    }

    /**
     * Updates an entity's data in the database.
     *
     * @param AbstractEntity $entity The entity
     * @return int Number of affected rows
     */
    protected function update(AbstractEntity $entity)
    {
        $id = $entity->getId();
        $entityAsArray = $this->loadArrayFromEntity($entity);
        return $this->dbConnection->update($this->tableName, $entityAsArray, array('id' => $id));
{'fraction_non_alphanumeric': 0.12076042341758479, 'fraction_numerical': 0.0008641175199827177, 'mean_word_length': 2.237762237762238, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, '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': '1351249', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1237, 'n_words': 352}