<commit_before><?php
namespace Metagist;

use \Doctrine\DBAL\Driver\Connection;
use \Doctrine\Common\Collections\ArrayCollection;

/**
 * Repository for package meta information.
 * 
 * @author <NAME> <<EMAIL>>
 */
class MetaInfoRepository
{
    /**
     * db connection
     * @var \Doctrine\DBAL\Driver\Connection 
     */
    private $connection;
    
    /**
     * Constructor.
     * 
     * @param \Doctrine\DBAL\Driver\Connection $connection
     */
    public function __construct(Connection $connection)
    {
        $this->connection = $connection;
    }
    
    /**
     * Retrieves all stored meta info for the given package.
     * 
     * @param \Metagist\Package $package
     * @return \Doctrine\Common\Collections\Collection
     */
    public function byPackage(Package $package)
    {
        $collection = new ArrayCollection();
        $stmt = $this->connection->executeQuery(
            'SELECT * FROM metainfo WHERE package_id = ?', array($package->getId())
        );
        while ($row = $stmt->fetch()) {
            $collection->add(MetaInfo::fromArray($row));
        }
        
        return $collection;
    }
    
    /**
     * Saves a package.
     * 
     * @param \Metagist\Package $package
     * @throws \RuntimeException
     */
    public function savePackage(Package $package)
    {
        if ($package->getId() == null) {
            throw new \RuntimeException('Save the package first.');
        }
        
        //delete old entries
        $this->connection->executeQuery(
            'DELETE FROM metainfo WHERE package_id = ?',
            array($package->getId())
        );
            
        $metaInfos = $package->getMetaInfos();
        foreach ($metaInfos as $info) {
            $this->save($info);
        }
    }
    
    /**
     * Saves (inserts) a single info.
     * 
     * @param \Metagist\MetaInfo $info
     * @return int
     */
    public function save(MetaInfo $info)
    {
        $stmt = $this->connection->executeQuery(
            'INSERT INTO metainfo (package_id, user_id, time_updated, version, category, group, value) 
             VALUES (?, ?, ?, ?, ?, ?, ?)',
            array(
                $info->getPackage()->getId(),
                $info->getUserId(),
                date('Y-m-d H:i:s', time()),
                $info->getVersion(),
                $info->getCategory(),
                $info->getGroup(),
                $info->getValue()
            )
        );
        
        return $stmt->rowCount();
    }
}<commit_msg>escaped column nam with backticks<commit_after><?php
namespace Metagist;

use \Doctrine\DBAL\Driver\Connection;
use \Doctrine\Common\Collections\ArrayCollection;

/**
 * Repository for package meta information.
 * 
 * @author <NAME> <<EMAIL>>
 */
class MetaInfoRepository
{
    /**
     * db connection
     * @var \Doctrine\DBAL\Driver\Connection 
     */
    private $connection;
    
    /**
     * Constructor.
     * 
     * @param \Doctrine\DBAL\Driver\Connection $connection
     */
    public function __construct(Connection $connection)
    {
        $this->connection = $connection;
    }
    
    /**
     * Retrieves all stored meta info for the given package.
     * 
     * @param \Metagist\Package $package
     * @return \Doctrine\Common\Collections\Collection
     */
    public function byPackage(Package $package)
    {
        $collection = new ArrayCollection();
        $stmt = $this->connection->executeQuery(
            'SELECT * FROM metainfo WHERE package_id = ?', array($package->getId())
        );
        while ($row = $stmt->fetch()) {
            $collection->add(MetaInfo::fromArray($row));
        }
        
        return $collection;
    }
    
    /**
     * Saves a package.
     * 
     * @param \Metagist\Package $package
     * @throws \RuntimeException
     */
    public function savePackage(Package $package)
    {
        if ($package->getId() == null) {
            throw new \RuntimeException('Save the package first.');
        }
        
        //delete old entries
        $this->connection->executeQuery(
            'DELETE FROM metainfo WHERE package_id = ?',
            array($package->getId())
        );
            
        $metaInfos = $package->getMetaInfos();
        foreach ($metaInfos as $info) {
            $this->save($info);
        }
    }
    
    /**
     * Saves (inserts) a single info.
     * 
     * @param \Metagist\MetaInfo $info
     * @return int
     */
    public function save(MetaInfo $info)
    {
        $stmt = $this->connection->executeQuery(
            'INSERT INTO metainfo (package_id, user_id, time_updated, version, category, `group`, value) 
             VALUES (?, ?, ?, ?, ?, ?, ?)',
            array(
                $info->getPackage()->getId(),
                $info->getUserId(),
                date('Y-m-d H:i:s', time()),
                $info->getVersion(),
                $info->getCategory(),
                $info->getGroup(),
                $info->getValue()
            )
        );
        
        return $stmt->rowCount();
    }
}
{'fraction_non_alphanumeric': 0.13795821836815136, 'fraction_numerical': 0.0, 'mean_word_length': 1.7536625067824199, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 53, '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': '4422470', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1429, 'n_words': 294}