<commit_before><?php

namespace photon\utils\mongodb;
use photon\db\Connection;

abstract class Counter
{
    const database = 'default';
    const collection = 'counters';

    public static function resetAll()
    {
        $db = Connection::get(static::database);
        $counters = $db->{static::collection};
        $counters->drop();
    }

    public static function reset($id)
    {
        $db = Connection::get(static::database);
        $counters = $db->{static::collection};
        $counters->deleteOne(array('_id' => $id));
    }

    public static function get($id)
    {
        $db = Connection::get(static::database);
        $counters = $db->{static::collection};

        $obj = $counters->findOne(array('_id' => $id));
        if ($obj === null) {
            return 0;
        }
        
        return $obj['c'];
    }    

    public static function inc($id)
    {
        $db = Connection::get(static::database);
        $obj = $db->command(array(
            'findandmodify' => static::collection,
            'query' => array('_id' => $id),
            'update' => array('$inc' => array('c' => 1)),
            'upsert' => 1,
            'new' => 1,
        ));
        
        return $obj['value']['c'];
    } 
}<commit_msg>Fix for ext-mongodb<commit_after><?php

namespace photon\utils\mongodb;
use photon\db\Connection;

abstract class Counter
{
    const database = 'default';
    const collection = 'counters';

    public static function resetAll()
    {
        $db = Connection::get(static::database);
        $counters = $db->{static::collection};
        $counters->drop();
    }

    public static function reset($id)
    {
        $db = Connection::get(static::database);
        $counters = $db->{static::collection};
        $counters->deleteOne(array('_id' => $id));
    }

    public static function get($id)
    {
        $db = Connection::get(static::database);
        $counters = $db->{static::collection};

        $obj = $counters->findOne(array('_id' => $id));
        if ($obj === null) {
            return 0;
        }
        
        return $obj['c'];
    }    

    public static function inc($id)
    {
        $db = Connection::get(static::database);
        $obj = $db->command(array(
            'findandmodify' => static::collection,
            'query' => array('_id' => $id),
            'update' => array('$inc' => array('c' => 1)),
            'upsert' => 1,
            'new' => 1,
        ));

        $objs = $obj->toArray();
        $obj = $objs[0];

        return $obj['value']['c'];
    } 
}
{'fraction_non_alphanumeric': 0.17894736842105263, 'fraction_numerical': 0.0035087719298245615, 'mean_word_length': 2.091566265060241, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 38, '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': '3573763', 'n_tokens_mistral': 802, 'n_tokens_neox': 773, 'n_words': 154}